Glad it worked out okay. =)
Actually, there is a bug and I don’t know why it’s in here. It looks like this :
You certainly don’t know why it’s there, this is why it’s a bug. When there is a bug, you need to trace it, to what it’s caused by. You can do the tracing using debugger, or by adding a debug code in your program. The latter is what i mostly do, because debugger is like too separated from the code, but debug code isn’t. Debugging is a kind of misleading word, most of it is not about removing bugs, but tracing them.
Yeah, I do not know how to use a debugger. I tried to find a tutorial that was good enough but unfortunately did not succeed. I know how to set breakpoints and watch through them, but I don’t know how to fix some problems. Thanks debugger I fixed the problem that map was showing in only 1 color. I don’t know how to use it to debug this, though.
Yes setting breakpoints is what you mostly do with the debugger, the other thing is finding out where it crashes or another exception happens. You can add functions to breakpoints and everything, but the code and all there is a kind of too separated from your code. I used to put debug code between #ifdef DEBUG and #endif. Now when i define DEBUG, the debug code becomes active. And this can include all kind of code, printing, conditional statements, and even functions that analyze all your data. Debugging is a kind of advanced, and when you finally find the bug, this is mostly some simple mistake, taking only a minute to fix. But this advanced debugging is a necessary work and often most of the work, as when the code is complex, finding simple mistakes is a time consuming task.
I agree with actsl. You really need to start debugging your code and find the cause of the bug(s) you’re having in your code. I found your latest bug (where the map wasn’t even rendered) by debugging your code, used breakpoints, checked values of variables and so on.
You need to follow the code flow from the start of your code through the mainloop and check for something that doesn’t make sense and fix it. The reason why your map is rendered in the same color, and sometimes rendered by only head sprites, is probably caused by some error in your rendering function(s) and/or the generation of the level, where you’re setting the texture coordinates and so on.
You also mentioned that you had some problem swithing from gamestate into titlescreen state so there might also be some error in your state machine, which you should also check.
There’s a problem with map render when I change currentScreen from GameplayScreen to TitleScreen. If currentScreen is equal to GameplayScreen everything loads correctly. The bug starts when I change currentScreen to title(my menu) and choose New Game. Then currentScreen sets to GameplayScreen, the player loads correctly, but the map is going crazy. I went through the whole tile class, layer class, map class, player class, GameplayScreen class, ScreenManager class and Texture class by doing breakpoints. Should I change my hobby?
i recommended debug code instead of using debugger, also because it remains always a part of your code, which you always can use.
What “debug code instead of using debugger” means?
Write debug code permanently in your code. Between #ifdef DEBUG and #endif everywhere it appears. Then do #define DEBUG , and it becomes active. Like there are some things that you want to see all the time, printing out of what happens. If you use debugger, this will be once, it will be lost, and next time you start all over again. But in that way you always get some good picture of what happens without any additional effort.
Ok. How does it help me with this problem? What should I look for?
I have not even looked at your code, but from what i read. Make it to print out all data about the map, you can make it to do that only in certain conditions, you can add a flag that it does it only once, all is possible. When you run it from terminal, it can print to terminal (usually printed to the standard error stream).
The questions you’re asking are extremely novice and have nothing to do with
SDL. I suggest reading up a little more on programming and especially
Ok, so first, what make me say your code isn’t working? The map doesn’t render as I wish.
Second, what did I expect my code to do and why? To render the map, because I’d like to have a ground.
Third, What did me code do instead? It renders good when currentScreen = GameplayScreen, if currentScreen = TitleSreen the map loads crazy. So I should change the Draw method. What should I write there? I don’t know. Why? Because when I set breakpoint there, it says everything loads good.
So you maybe don’t check all the conditions at your breakpoint, at which your map doesn’t load good. When you say your map doesn’t load in certain conditions, then you should see what happens during loading the map in these conditions, and what is wrong then in loading the map. This is called tracing, up to the initial cause of why things go wrong.
If you meant that I should compare the code which work vs which doesn’t work, I thought about it before. I compered Draw and Update methods of GameplayScreen class, layer, class and map class. They are exactly the same.
No, you should see what happens when the code doesn’t work, and what goes wrong. What happens you can see by seeing the values of the variables, or printing them out.
Ok. Everything going ok when in ScreenManager currentScreen = GameplayScreen. I compered all values when currentScreen is equal GameplayScreen and when currentScreen is equal TitleScreen(menu) and the values are exactly the same. So why the first option works if the values are the same? Maybe I do not understand what you are talking about.
All i wanted to say, it looks like to me that you need a more advanced debugging, like you need conditional statements in the debug code. You can do that with debugger, but this is an advanced use of debugger. So i recommended to use debug code instead, for which you don’t have to know more than you already know. The additional benefit is that the debug code will be a part of your code, that you can switch on and off with conditional inclusion directives.
You seem to ask a wrong question, nothing can work differently when everything is the same. It is about finding out what is different in certain conditions, so you need conditional statements in the debug code, to see the values of the variables when certain conditions are true. Also don’t make assumptions about what is wrong, this is a waste of your time, instead find out what really happens.
Debugging can be very interesting, you can use the power of the computer against its own power, to find out what is wrong. It can be done very creatively. But it is just a very different task from what you maybe have been taught that programming is about. You may have been taught that programming is writing a code, which also all people seem to think who know really nothing about programming. Now you may find that often most of the programming is tracing. It is like, no one wonders that one who does electronics, most of the time does measurements with oscilloscope or other measuring equipment. Programmer does debugging, both have the same aim, finding out what really happens.
Ok. I just fixed it. The problem was that I used Texture class and LoadFromFile method instead do the same in SetContent in Tile class, I mean, I just copied and pased almost everything from Texture class to Tile and that works. Thanks y’all for eveyrthing. I’ll try to find tuts or articles about debugging. Thanks by now for everything