Jump to content
  • Advertisement
Sign in to follow this  
p997

[.net] Performance issue

This topic is 4485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!