
Getting Started
Say that you have a game that would be really cool if you could move the characters or images or whatever like in real games. This will show you what you can do the SGC way to make your characters or whatever move.
The Code
The code to make things move is very, very simple. Choose which speed you want the sprite to move (usually 20), and use this simple line of code in a KeyPress event or timer:
Image1.Left = Image1.Left - 20
You can modify this code to do what you want, and here's a little table explaining what will happen depending on which modifications you make to it (20 is an optional speed, you can change that on your own depending on how fast you want the sprite/image to move).
|
Property |
Modification |
Effect |
|
Left |
+20 |
Move 20 Left |
|
-20 |
Move 20 Right |
|
| Top | +20 | Move 20 Down |
| -20 | Move 20 Up |
Okay, animation is a "tad" harder to do than the actual moving (in SGC way). Simply import the images (say we have 3) and name them (how bout "walking1", "walking2" and "walking3" ((don't forget one of the sprite standing still, name this one "still"). Create a timer (switch the Enabled property to False, and choose an interval (usually 500). In the timer's event, include this code ("standing" will be the picture of the sprite standing still):
If standing.Picture = walking1.Picture then
standing.picture = walking2.Picture
Exit sub
end if
And so on, all the way until "If standing.Picture = walking3.picture then"... Then add this code (after the code I juss wrote):
standing.Picture = walking1.picture
And you're done. So, in conclusion, this is our code:
Form_KeyDown(Keyascii as integer)
if keyascii = 13 then
standing.picture = walking1.picture
image1.left = image1.left - 20
timer1.enabled = true
end if
End Sub
Form_KeyUp(Keyascii as integer)
if keyascii = 13 then
standing.picture = still.picture
timer1.enabled = false
end if
End Sub
Timer1_timer()
If standing.Picture = walking1.Picture then
standing.picture = walking2.Picture
Exit sub
end if
If standing.picture = walking2.picture then
standing.picture = walking3.picture
exit sub
end if
if standing.picture = walking3.picture then
standing.picture = walking1.picture
exit sub
end if
End Sub
And you're done! If you have any questions, just contact us and I'll help you. Soon an example project will be attached to this, showing all the code and blah blah blah. Enjoy!