Moving images under user control - Please help!

Nibbie
Posts: 3
Joined: 2009.04
Post: #1
Hello!
I just recently started to program in C++. I started to learn SDL (Simple Direct Media Layer) too. However, I have one problem that I can't figure out:
How to make something move from keyboard input.

I know how to poll events, check for keyboard presses and so on, however, I am completely stumped how to load an image that can be moved in the end. If possible, please show me the code needed to make a image move.

Nothing fancy, just something that:
-Blits the image on some kind of surface so it is moveable
-Allow the press of a cursor key to move that image

Sorry if this is a stupid question, Im still very new to this.
Thanks in advance!
Quote this message in a reply
Member
Posts: 46
Joined: 2008.10
Post: #2
I'm going to assume you're using the popular SDL / OpenGL combination for graphics, in which case I suggest breaking down your problem into three smaller steps:
- Figure out how to bind event triggers (checking for a specific key-down or key-press event) to event execution (changing a state variable, in this case image location)
- Figure out how to load an image as a texture (make sure the dimensions are ^2!) that can be used to draw a textured quad
- Translating that quad when rendered using a game state that tracks x and y variables (adjusted by events as noted above)

The nice thing is, each one of these steps has been very well documented here on the site and in other places (see Google, a coder's best friend). If there's some specific step that you're stuck on, though, feel free to reply here and we'll help as best we can.

"Who's John Galt?"
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.04
Post: #3
Thanks a lot. I just found a good entry-level tutorial that handles keyboard input & blitting &so on in SDL. Thanks again!
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.04
Post: #4
Thanks, just figured it out thanks to a tutorial. Smile
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2009.05
Post: #5
Please pseudobot (great nick), could you tell me the address of that tutorial ? I need too.
Quote this message in a reply
Post Reply