Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Etarus  
#1 Posted : Sunday, February 24, 2013 9:02:26 PM(UTC)
Etarus

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

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Sunday, February 24, 2013 9:08:53 PM(UTC)
Benjamin

Medals: Admin

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 Go to Quoted Post

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

Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
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.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.321 seconds.