Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 austinsheep   Members   -  Reputation: 180

Like
0Likes
Like

Posted 26 November 2013 - 11:43 PM

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, 27 November 2013 - 12:11 AM.


Sponsor:

#2 Ludus   Members   -  Reputation: 970

Like
1Likes
Like

Posted 27 November 2013 - 12:37 AM

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.



#3 austinsheep   Members   -  Reputation: 180

Like
0Likes
Like

Posted 27 November 2013 - 12:41 AM

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



#4 Ludus   Members   -  Reputation: 970

Like
1Likes
Like

Posted 27 November 2013 - 12:51 AM


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.



#5 austinsheep   Members   -  Reputation: 180

Like
0Likes
Like

Posted 27 November 2013 - 12:56 AM

 

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.



#6 Ludus   Members   -  Reputation: 970

Like
0Likes
Like

Posted 27 November 2013 - 01:07 AM


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.



#7 austinsheep   Members   -  Reputation: 180

Like
0Likes
Like

Posted 27 November 2013 - 01:16 AM


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



#8 Ludus   Members   -  Reputation: 970

Like
0Likes
Like

Posted 27 November 2013 - 01:28 AM

No problem. If you haven't already done so, I recommend checking out the tutorials at sdltutorials.com and Lazy Foo's tutorials. The former will guide you through the creation of a framework for a 2D platformer game.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS