Jump to content
  • Advertisement
Sign in to follow this  
destiny_breaker86

How to make an array of SDL_Suface pointers

This topic is 4865 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

I want to have an array of SDL_Sufaces to store different frames of an animation. Here's what the code looks like: SDL_Suface **img; *img = new SDL_Surface[frames]; ... SDL_BlitSurface(img, &srcRect, screen, &destRect); I'm using Visual C++ 6. I just need a way to dynamically allocate an array of pointers (not a multidimensional array).

Share this post


Link to post
Share on other sites
Advertisement
Instead of "*img = new SDL_Surface[frames];", you need to use "img = new SDL_Surface*[frames];". This creates the array of pointers, instead of setting the location that img is pointing to (null/uninitialized) to a set of entire new SDL_Surfaces. Once you've made this change, you can then do things such as "img = SDL_LoadBMP(...)", "SDL_BlitSurface(img, ...)", and so forth.

Share this post


Link to post
Share on other sites
Well, SDL just started borking out on my compiler so I can't run a test compile right now, but I see only one reason why that code wouldn't compile -- if frames was 0 or a negative number, for some reason.

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!