Advertisement Jump to content
Sign in to follow this  

Starting out in SDL

This topic is 5000 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, I'm having a go at SDL. I've got as far as being able to blit images onto the screen, and being able to move one image at a time using the keyboard. I have a good grasp of how pointers and classes work. I'm trying to make Pong as my first game, but I've hit some trouble. Firstly, how do I move more than one sprite at a time using the keyboard? Currently, when I move one sprite and press the button to operate the other, the original one stops and I have to press the button for the second sprite again to make it move. And how do I make the ball move continuously whilst updating the screen with the new paddle positions? I've trawled the net for tutorials, I'm surprised at the fact that there are hardly any. I've tried Rob Loach's Pong download, and didn't understand his sprite class properly. Any help would be greatly appreciated, ukdeveloper.

Share this post

Link to post
Share on other sites
The problem you're having is a very common one. You're changing the flow of the program in response to "things moving". This isn't unfortunately the right thing to do.

Games that move more than one thing at once (i.e. most of them) are really turn-based (also known as tick-based) - each object moves a small amount in between frames, like making a flick-book movie.

Essentially your main loop might look like:

for each thing in the game
process input or AI as necessary
move a small amount in the direction you need to go
check for collisions
draw each thing
wait for next frame

The principle is that each object is considered in turn, and moved independently.

In the case of something like Pong, there are only a few objects, but the principle still applies.

The way each "thing" is represented will depend on the game and the structure. Some of them might be in arrays, or STL lists (vectors etc). Or they might be in one big list with polymorphism - or a mixture.

It doesn't really matter. For "pong", if there is only one ball, I'd just have a global or something to store its position. For the bats (there are two of them which share some behaviour) I'd use something like an array.

Then each frame, move the ball a little bit, and move each bat a little bit.


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!