Skip to main content
gamedev.net
🔒 Locked

[.net] Performance issue

Started by p997 Apr 4, 2006 at 10:48 PM 5 replies 950+ views
Original Post
p997
p997
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?
janoside
janoside
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]
joelmartinez
joelmartinez
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]
jonahrowley
jonahrowley
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.
TMP72
TMP72
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!
Rob Loach
Rob Loach
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] [
p997
p997
Thanks for the info!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.