Monday 2 January 2012

Beginner game tutorial

i have been programming for a while now and people ask me, how do i make things move with the arrow keys? well here you go!
Private Sub fm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyData = Keys.Up Then
'if the up arrow key is pressed
'what you want to happen
end if
End Sub

as you can see, the code for the arrow key is in the form-keydown. this will not work any other way. e.keydata works with most keys on the keyboard. it is saying simply, if this key is pressed then...

Another thing that people ask me is, how do i write an if touching code?
and here it is!
If object1.Bounds.IntersectsWith(object2.Bounds) Then
'what you want to happen
end if
 this one does not have to be in a certain sub but i find that the best one to be in is a timer on a very small interval because it will check every to the timer goes round. this is also simply saying, if the bounds of object1 is touching object2s bounds then...

i have sent an attachment so you could see it examples of how these could be used.

hope this has been helpful

No comments:

Post a Comment