Jump to content
  • Advertisement
Sign in to follow this  
monkey7461

Moving Content on a Surface that isn't the SDL_SetVideoMode() Surface

This topic is 2155 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've been trying to get an understanding of how to create a platformer with SDL.  The problem is, I don't know how properly clear my background's buffer with an image.  How I've done it before is by using SDL_FillRect() to cover last frame's content.  But how could I achieve this with an image?  I'm using SDL_BlitSurface(), and on the surface called in that function, I'm attempting to load moving objects (such as animations and moving characters).  Sorry if this doesn't make sense, I'm learningtongue.png

Edited by monkey7461

Share this post


Link to post
Share on other sites
Advertisement

You shouldn't need to draw the moving sprites onto the background's surface. Each frame simply clear the screen, draw the background to the screen surface, then draw the moving objects to the screen surface. The images are always drawn on top of one another, so draw them in order of furthest to nearest.

Share this post


Link to post
Share on other sites

draw the moving objects to the screen surface.

What if I have objects that are past the size of the screen? for example: if I had a rectangle at the x position of 650, but my screen width was only 640

Share this post


Link to post
Share on other sites


What if I have objects that are past the size of the screen? for example: if I had a rectangle at the x position of 650, but my screen width was only 640

 

It will not draw it to the screen surface. Bounds checking when drawing to a surface is built into the API. The same goes for an image that is partially off screen - it will automatically clip what doesn't fit.

Share this post


Link to post
Share on other sites

 

It will not draw it to the screen surface. Bounds checking when drawing to a surface is built into the API. The same goes for an image that is partially off screen - it will automatically clip what doesn't fit.

 

then how could I set a sprite that has not yet appeared on the screen? I couldn't set it to the background surface because it won't animate correctly, and I can't set it to the screen surface because it will cut off.

Share this post


Link to post
Share on other sites

then how could I set a sprite that has not yet appeared on the screen? I couldn't set it to the background surface because it won't animate correctly, and I can't set it to the screen surface because it will cut off.

 

Your sprite should exist as an object that keeps track of its position in the game space (create a "sprite" class with X and Y values as members). This object will render itself each frame in relation to the current camera position.

Share this post


Link to post
Share on other sites


Your sprite should exist as an object that keeps track of its position in the game space (create a "sprite" class with X and Y values as members). This object will render itself each frame in relation to the current camera position.

Thank yousmile.png

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!