Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Switches, lag, and animations oh my!

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 WJM   Members   

103
Like
0Likes
Like

Posted 03 April 2012 - 04:13 PM

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.

#2 Slavik81   Members   

360
Like
0Likes
Like

Posted 03 April 2012 - 04:33 PM

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.

#3 WJM   Members   

103
Like
0Likes
Like

Posted 03 April 2012 - 04:41 PM

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. :)

#4 Narf the Mouse   Members   

322
Like
0Likes
Like

Posted 03 April 2012 - 04:43 PM

At this point, you want a code profiler, not a forum.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.