I'm wondering if there's any difference in CPU usage when we manually detect situations where something has changed and then call methods in the _draw individually only in those cases.
I'm working on a game with many static elements and I'm considering whether it makes sense to constantly redraw everything or only the elements that have changed, for example in picross game.
if you are calling cls() you are already drawing everything each frame.. if you don't call cls() you will persist the last frame and have to clear what you need redrawn manually.. the drawing operations themselves, unless you run a lot of them or loop many times, are not generally going to use too much CPU
I didn't use cls() at all. Let's discuss an example. Half of the screen is the player's interface with information, and it doesn't change very often. The other half is the game, where the action happens. Each frame, I draw a black rectangle only in the area where the action takes place, leaving the interface untouched. The interface will only be redrawn if I set a specific flag. When I decide that the interface needs to change, I redraw only the interface once, with the new values.
editI missed the question of the first post....
I don't know much if this really save CPU usage, but could clip() be helpful?
Something like clip(0,64,128,64) to freeze the half of the screen, but you couldn't show user interactions like moving indicators of the menue in this half. (without some program logic inside your code, that "unfreeze" the screen.
@Porkite this might indeed save some CPU but really, unless you're doing some really complex drawing were taking about 1 or 2 % so it's up to you if it's worth that for your game.
[Please log in to post a comment]