Archived

This topic is now archived and is closed to further replies.

Tai-Pan

handling control in a 2d game

Recommended Posts

Ok..I already have my character classes and everything needed to display sprites on screen. Now im working on the control side of things, Im using SDL. Im not sure how I should handle the control system of my game engine (its a 2D game), the following is what I have thought about thisproblem: I have a “control” class which methods that receive key presses and pointers to the sprite that I need to move..then the method of the controls class changes the sprite´s X and Y position. Is this a good approach to the problem? If you know different methods for handling sprite control please tell me. Thanks in advance. "Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Share this post


Link to post
Share on other sites
Humm..hey Hazelnuss, your method sounds good..I will try to work on it.
BTW: should I check for key presses every in every iteration of the game´s loop?

"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Share this post


Link to post
Share on other sites
That's what i am doing... you could also define 3 messages: one that makes the object move right, one for left, and one to make it stop running. If the right arrow key is pressed you would send "run to the right", if the key is released again you would send "stand still".

[edited by - Hazelnuss on May 5, 2003 2:01:04 PM]

Share this post


Link to post
Share on other sites
I had a function named "CheckInput" which updated all input data for the player class. The class had an array of bools which controled which player button what down or up.

This function was called every game loop iteration.

The message system? Hmmmm..... I suppose that would be good for custom GUIs but I don''t know if it would be that good for the game loop. I haven''t done event-based programming yet.



- Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

Share this post


Link to post
Share on other sites
Thank you guys...do you know where I could take a look at some example code?

"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Share this post


Link to post
Share on other sites
Look in the SDL documentation (I use the compiled html version) and in the section concerning keyboard input there is a piece about game input. Although this keeps the functions in the main class it shows how you can take the input and set player velocities with it. This is called every loop and it is very common.

So, if you aint got it. head over to libsdl.org and download the docs.

Share this post


Link to post
Share on other sites
Thanks dude..I already have those SDL document..I took a quick look at the input section but I didnt find what you are talking about..Ill take a deeper look at it..thanks again-

"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Share this post


Link to post
Share on other sites
quote:
Original post by Tai-Pan
Thank you guys...do you know where I could take a look at some example code?


You won't actually learn-learn it if you don't do it yourself though .

[EDIT] Oops, I forgot this: http://plantsourcecode.com that's a good site for just looking at code directly.



- Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda


[edited by - Rob Loach on May 6, 2003 12:59:18 PM]

Share this post


Link to post
Share on other sites
Dont worry..Ive been trying to figure it out..but I just want to lear some kind of standard to handle input in games..thanks for the link


"Those who follow the path of the warrior must be ready to die, to stand for their convictions, live for one´s convictions, die for one´s convictions"

Share this post


Link to post
Share on other sites