[.net] Performance issue

Started by
5 comments, last by p997 18 years ago
Hi, im coding a simple 2D game and need to use 4 separate sprites to represent the main character's movements(facing up, donw, left, and right). should i create 4 different Sprite variables to hold them and load them all at once in an initialization function, or just do i just need to create 1 variable and load the corresponding sprite each time as the character moves? which way is better, performance-wise?
Advertisement
Since the sprites are (I'm assuming) small and will probably be used often, I would recommend loading them all during initialization. Due to the (assumed) small size, it shouldn't make too great a difference in performance.
-janoside [Firestorm Engine]
Depending on what you're using to draw to the screen, one option might be to have all four images in one texture. That way, you could load the whole texture pack at once, and simply change the offsets to show each different image.
Joel Martinez
http://codecube.net
[twitter]joelmartinez[/twitter]
You definately won't want to be loading the sprite every time you change direction. Even though this is a simple 2d game, and that sprite will probably remain in the disk cache, and you might never actually see a difference in the performance, it's not a good idea, and it's definately not a good habit to get into.
Usually the best way is to have all animation frames of a particular sprite saved as a single image (ie. texture) Load the texture and display only the portion of the texture that is needed. Using this method will help you when moving into more complex sprite animation.

Just my two cents
T!
With game programming, you want to have as little loading as possible during the game loop. Try to have as much loading done in the initialization of the game state. The only time you'll want to have loading done during the game loop is when you're streaming content in for dynamic loading of content (like endless map data generation).

This means you'll want to load all textures when the game starts and cache them somewhere. Then just switch off the graphics when required without loading anything during the game loop.
Rob Loach [Website] [Projects] [Contact]
Thanks for the info!

This topic is closed to new replies.

Advertisement