Switches, lag, and animations oh my!

Started by
2 comments, last by Narf the Mouse 12 years ago
Hey guys, all Oz references aside, I got a question. Basically, I have a game (using Allegro), and its coming along very nicely, I have a map, tiles, enemies, textures and the lot, but I notice that the lag tends to spike at what (seems like) random. I'll get to why I think its lagging later, but I should probably go over the whole things for the sake of completeness. Every cycle (tick, whatever you want to call it), the game draws all the tiles (including water and lava, which are animated with 2 frames), runs the enemy through its AI once, then draws the player and the enemy (both use the same animation technique). All the tiles store a pointer to their image (and a second one in case they're animated), and are in turn stored in a room object. Now,I think the player object is particularly ugly and lag prone because of its animation function. it uses an if statement to check if there is an animation started, then another if statement for each direction the player could be facing (NESW), then a switch for what frame to draw. The switch uses an integer that gets advanced with each tick, and reset to 0 when a new animation is started. There's also some other switches for standing still etc. Is it the amount of if/switch statements slowing it down? or is it something else I'm not aware of.

I hope that makes sense.
Advertisement
There's almost no way that the ifs/switches determining what to draw would be significant. That sort of code is trivial in execution cost and relatively rarely executed.

Your problem is far more likely to be due to whatever you're doing once you determine what to draw/animate.

There's almost no way that the ifs/switches determining what to draw would be significant. That sort of code is trivial in execution cost and relatively rarely executed.

Your problem is far more likely to be due to whatever you're doing once you determine what to draw/animate.

thanks, I think I'll try to make it draw 2 large bitmaps instead of each tile. :)
At this point, you want a code profiler, not a forum.

This topic is closed to new replies.

Advertisement