| problem with keys |
|
Glocke
|
Can you post the code of the event-loop interpreting the keydown- and keyup-events?
|
|||||||||||
|
|
||||||||||||
|
spiff88
|
main loop
CPaddle.h :
CPaddle.cpp :
|
|||||||||||||||||
|
|
||||||||||||||||||
|
spiff88
|
the above code is a little off its this
main loop:
CPaddle.h :
CPaddle.cpp :
|
|||||||||||||||||
|
|
||||||||||||||||||
|
Glocke
|
Well, your main loop handling keydown and keyup seems correct to me (but I didn't tested it at all). But I would prefer another approch for moving your CPaddle:
Your CPaddle uses a speed variable. That's good! But in my opinion it doesn't make sense to implement "mMove(int speed)" in that way and change the speed all the time. A better solution might be "mMove(int dx, int dy)" for moving in direction <delta x, delta y> relative to your current position (mX and mY seem to the current position). You might store dx and dy in seperate values, such as mdX, mdY or so. Try to use mMove only to set the direction (which is a vector with x and y). Then you can use nLogic to calculate your new position by mX = mX + mdX * mSpeed; and the same way for y. So you just need to set the direction after getting your keydown/keyup. Actual you are only using y-direction (arrow keys up and down). So you can use mMove(0, 1) for moving down and mMove(0, -1) for moving up. If you need moving in x-direction you can simple extend it by using the first parameter of mMove. I hope this is helpful. Don't hesitate to ask furthermore. Kind regards Glocke[/code] |
|||||||||||
|
|
||||||||||||

