Joined: 1/29/2013(UTC) Posts: 3
|
Hello,
i want to control a sprite over the screen with the arrow keys or with other ones. How do i implement an event for moving the sprite if the special key was pressed?
Regards
|
|
|
|
Medals:  Joined: 8/20/2011(UTC) Posts: 1,421 Location: Hannover
Thanks: 18 times Was thanked: 97 time(s) in 92 post(s)
|
Originally Posted by: Etarus  i want to control a sprite over the screen with the arrow keys or with other ones. How do i implement an event for moving the sprite if the special key was pressed?
Hi Etarus. That should be quite simple to accomplish. In fact if you do a search for Key.CursorLeft in the current v0.9.7.2 source code release you can find some examples like this one from the Breakout game, where you control the paddle with the cursor keys: Code:
// Only needs to be setup once in the constructor:
inputCommands.Add(Key.CursorLeft, State.Pressed,
() => xPosition -= PaddleMovementSpeed * time.CurrentDelta);
inputCommands.Add(Key.CursorRight, State.Pressed,
() => xPosition += PaddleMovementSpeed * time.CurrentDelta);
// And then at drawing time just draw whatever xPosition is:
protected override void Render(Renderer renderer, Time time)
{
//...
DrawArea = Rectangle.FromCenter(xPosition, yPosition, Width, Height);
base.Render(renderer, time);
}
Edited by user Sunday, February 24, 2013 9:10:30 PM(UTC)
| Reason: code blocks fix
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.