Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

EO (1.3) Mouse Movement Tutorial


Rob Janes
 Share

Recommended Posts

Something a lot of people have been asking for is a Tutorial on Mouse Movement for walking.

Here is a very QUICK tutorial on how to add Mouse Movement.  It uses Right Click to Move, and Left click for targetting.

ALL the changes are done on the CLIENT, requiring no modifications to the server.

Step 1\. Open modGlobals on the Client, and Add the Following
```
'Players Current Position
'These will store the players Current X/Y (values from GetPlayerX()/GetPlayerY())
'February 1st, 2011 - Robert Janes (Samu Games)
Public MyX As Integer
Public MyY As Integer
Public MouseMove As Boolean

```
Step 2\. Add this to the Beginning of Sub Main in modGeneral
```
' Set Default MouseMove Boolean to False
' This will become True with Right Clicking and False with Mouse Up
' February 1st, 2011 - Robert Janes (Samu Games)
MouseMove = False
```
Step 3\. In Sub CheckInputKeys, in modInput, Just before it starts doing the checks for Moving Up/Down/Left/Right add
```
'Quickly Check to See if we are using MouseMovement, if so, exit sub and don't check Keyboard Movement
    If MouseMove = True Then
        Exit Sub
    End If
```
Step 4\. in frmMain, on picScreen MouseDown, Just after it checks vbKeyRightClick, just BEFORE the If ShiftDown, we add the following.
```
MouseMove = True

            'Right Click Mouse Movement Here, Give MyX and MyY values for current Pos then compare

            MyX = GetPlayerX(MyIndex)
            MyY = GetPlayerY(MyIndex)

            'Move Right
            If CurX > MyX Then
                DirUp = False
                DirDown = False
                DirLeft = False
                DirRight = True
          End If

            'Move Left
            If CurX < MyX Then
                DirUp = False
                DirDown = False
                DirLeft = True
                DirRight = False
            End If

            'Move Down
            If CurY > MyY Then
                DirUp = False
                DirDown = True
                DirLeft = False
                DirRight = False
            End If
            'Move Up
            If CurY < MyY Then
                DirUp = True
                DirDown = False
                DirLeft = False
                DirRight = False
            End If

```
Step 5\. in frmMain on picScreen MOUSEUP, add
```
MouseMove = False
```
Step 6\. in modGameLogic, in the Sub GameLoop, comment out CheckKeys like so
```
' Call CheckKeys
```We comment this out because the GameLoop calls this function to ensure they aren't doing anything like Auto Walking so if the Keyboard keys aren't pressed down, it stops the movent, this screws up mouse movement.  It will not really affect your game in any way, as in CheckInputKeys, we already do a check to see if the key is pressed.  So it's moot for movement. You could go into CheckKeys and just comment out the checks for the KeyUp, KeyRight, KeyLeft, KeyDown if you wanted.

Viola!!!

Mouse Movement! Enjoy!
Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

1 thing I noticed was it doesnt stop the movement on mouse up, even with MouseMove = False in picScreen Mouse Up.  I've retried this a few times and it happens both times.  Any clue as to why, or perhaps what I did wrong in testing it?  Everything seems to work fine.
Link to comment
Share on other sites

It still looks like its missing a check somewhere, here is my inputkeys
```
  If GetKeyState(vbKeyControl) < 0 Then
        ControlDown = True
    Else
        ControlDown = False
    End If

    'Quickly Check to See if we are using MouseMovement, if so, exit sub and don't check Keyboard Movement
    If MouseMove = True Then
        Exit Sub
    End If

    'Move Up
    If GetKeyState(vbKeyUp) < 0 Then
        DirUp = True
        DirDown = False
        DirLeft = False
        DirRight = False
        Exit Sub
    Else
        DirUp = False
    End If
```
Link to comment
Share on other sites

@SamuGames:

> Something a lot of people have been asking for is a Tutorial on Mouse Movement for walking.
>
> Here is a very QUICK tutorial on how to add Mouse Movement.  It uses Right Click to Move, and Left click for targetting.
>
> ALL the changes are done on the CLIENT, requiring no modifications to the server.
>
> Step 1\. Open modGlobals on the Client, and Add the Following
> ```
> 'Players Current Position
> 'These will store the players Current X/Y (values from GetPlayerX()/GetPlayerY())
> 'February 1st, 2011 - Robert Janes (Samu Games)
> Public MyX As Integer
> Public MyY As Integer
> Public MouseMove As Boolean
>
> ```
> Step 2\. Add this to the Beginning of Sub Main in modGeneral
> ```
> ' Set Default MouseMove Boolean to False
> ' This will become True with Right Clicking and False with Mouse Up
> ' February 1st, 2011 - Robert Janes (Samu Games)
> MouseMove = False
> ```
> Step 3\. In Sub CheckInputKeys, in modInput, Just before it starts doing the checks for Moving Up/Down/Left/Right add
> ```
> 'Quickly Check to See if we are using MouseMovement, if so, exit sub and don't check Keyboard Movement
>     If MouseMove = True Then
>         Exit Sub
>     End If
> ```
> Step 4\. in frmMain, on picScreen MouseDown, Just after it checks vbKeyRightClick, just BEFORE the If ShiftDown, we add the following.
> ```
> MouseMove = True
>            
>             'Right Click Mouse Movement Here, Give MyX and MyY values for current Pos then compare
>
>             MyX = GetPlayerX(MyIndex)
>             MyY = GetPlayerY(MyIndex)
>
>             'Move Right
>             If CurX > MyX Then
>                 DirUp = False
>                 DirDown = False
>                 DirLeft = False
>                 DirRight = True
>           End If
>
>             'Move Left
>             If CurX < MyX Then
>                 DirUp = False
>                 DirDown = False
>                 DirLeft = True
>                 DirRight = False
>             End If
>            
>             'Move Down
>             If CurY > MyY Then
>                 DirUp = False
>                 DirDown = True
>                 DirLeft = False
>                 DirRight = False
>             End If
>             'Move Up
>             If CurY < MyY Then
>                 DirUp = True
>                 DirDown = False
>                 DirLeft = False
>                 DirRight = False
>             End If
>  
> ```
> Step 5\. in frmMain on picScreen MOUSEUP, add
> ```
> MouseMove = False
> DirUp = False
> DirDown = False
> DirLeft = False
> DirRight = False
> ```
> Step 6\. in modGameLogic, in the Sub GameLoop, comment out CheckKeys like so
> ```
> ' Call CheckKeys
> ```We comment this out because the GameLoop calls this function to ensure they aren't doing anything like Auto Walking so if the Keyboard keys aren't pressed down, it stops the movent, this screws up mouse movement.  It will not really affect your game in any way, as in CheckInputKeys, we already do a check to see if the key is pressed.  So it's moot for movement. You could go into CheckKeys and just comment out the checks for the KeyUp, KeyRight, KeyLeft, KeyDown if you wanted.
>
> Viola!!!
>
> Mouse Movement! Enjoy!
Link to comment
Share on other sites

yes, the main post is the proper tutorial, MouseUp is something you select in VB.  Double click on the picScreen so it opens up the source code. At the top right hand side of what white Syntax Editor, you'll see a DropDown that will say
picScreen_Click
Click that drop down and select "MouseUp"
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...