Moving images under user control - Please help! - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Moving images under user control - Please help! (/thread-1405.html)
Moving images under user control - Please help! - pseudobot - Apr 23, 2009 07:13 PM
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!
Moving images under user control - Please help! - TythosEternal - Apr 24, 2009 08:24 AM
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.
Moving images under user control - Please help! - pseudobot - Apr 24, 2009 05:14 PM
Thanks a lot. I just found a good entry-level tutorial that handles keyboard input & blitting &so on in SDL. Thanks again!
Moving images under user control - Please help! - pseudobot - Apr 24, 2009 05:15 PM
Thanks, just figured it out thanks to a tutorial.
Moving images under user control - Please help! - joecoolman - May 9, 2009 02:45 PM
Please pseudobot (great nick), could you tell me the address of that tutorial ? I need too.