Hello there!
I'm new to programming in C# (And pretty much every other language) and have been fiddling around with a lot of basic stuff such as "Click this button and do this" and textbased games with leaderboards for a time.
Since I'm new I don't know every rule there is for where certain characters and commands go, and that causes some problems.
Recently I've been trying to make a small game with keyboard input.
Hence my plea for help:
I can't get the darn playingobject to move. It's the first step I've been trying to master, but all I get is torn pieces of hair.
I don't know how to make something on the screen to move by pressing a key.
f.e.x I can make a label increase it's width or height by clicking a button, but not move up or down with either button or keypressing.
I don't have any lines of code to show, I end up starting over and not saving the last project when I try again, it's not like it's a lot of code down the drain.
I do this in VS10 with the Windows form application preset.
Is there a kind soul out there who could point me (and the playingobject) in any direction?
PS: Treat me like a complete newbie, since that's what I am.
//Simon
Replace <name of object> with the name of your object and <Move Length> with how far you want it to moveCode:// Left <name of object>.Left += <Move Length>; // Right <name of object>.Left -= <Move Length>; // Up <name of object>.Top -= <Move Length>; // Down <name of object>.Top += <Move Length>;![]()
Thankyou! That was invaluable to me!
There's only one problem left, I am completly lost when it comes to keyinput.
I've been searching for tutorials and looking at others problems, but so far I can't get the code to work at all, even though it's compilable.
f.e.x:
does nothing.Code:private void keycontrol (Object sender, System.Windows.Forms.KeyEventArgs e) { switch (e.KeyCode) { case Keys.Left: ovalShape1.Left += 100; break; case Keys.Right: ovalShape1.Left -= 100; break; case Keys.Up: ovalShape1.Top -= 100; break; case Keys.Down: ovalShape1.Top += 100; break; } }
(That's code I took off a post somewhere else)
Check this out from MSDN. Maybe this will help you. How to: Modify Keyboard Input to a Standard Control
-CDG10620
Software Developer
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks