Advertisement

[SDL] Guidance with the movment of Sprites

Started by July 27, 2011 10:54 AM
0 comments, last by evillive2 13 years, 4 months ago
I have been struggling with the process of making my Sprite objects to move at all in my game.

It works fine when I write all the SDL related code in the main but I'm trying to seperate the main from the SDL related code in another class.

I can blit the Sprite with no problem but when I try to move the sprite by pressing the UP, DOWN, LEFT, RIGHT keys it does not work.
Now I started another thread in the beguinners section, perhaps this belongs there as well but my issue is SDL related.

What I think I need is a example of how this can be achieved, moving sprites in SDL without having any SDL code in the main. Or some help figuring out what's wrong with my code. What ever suits you guys.
Just to clarify - this isn't really an SDL related question per say as the concept is the same regardless of the API or the language for that matter however since you are using SDL it doesn't hurt to look at SDL specific ways to handle key presses.

Now - for the actual issue. You mentioned that when you have all of your code in the main function this isn't an issue however when you move the code to a class it no longer works. The issue could be a number of things and we would really need to see the code you think isn't working properly along with an explanation of what you think should be happening.

Without seeing any code I would first recommend setting a break point where your key press handler or event is fired, run the program and then step through the code when it stops and make sure the program walks through it's paces as expected - I am assuming it isn't. Another method of this is to litter your code with cout or printf statements with meaningful messages at important decision points in your program. Both ways will give you an insight into what your program is actually doing compared to what you think it should be doing.
Evillive2

This topic is closed to new replies.

Advertisement