Mouse Input

1.Overview #

Mouse input is a core input device for gamers on desktop/laptop devices. Often time the mouse input are used in the browser alone and/or combined with keyboard and/input. Although the mice only has a few buttons its usage(as a mouse or even touchpad) can create some of the most ergonomic motions for smooth gameplay interactions. 

 

2.Mouse Functions #

gpe.check_mouse_button_down(int mouseButtonId )

Returns true or false if the mouse button is being pressed now.

Scope: GPE

Return type : bool

Parameters:

  • int mouseButtonId – The constant assigned to the button. Also procecessed the nobutton and anybutton cases.

 

gpe.check_mouse_button_pressed(int mouseButtonId )

Returns true or false if the mouse buttonwas just pressed in frame.

Scope: GPE

Return type : bool

Parameters:

  • int mouseButtonId – The constant assigned to the button. Also procecessed the nobutton and anybutton cases.

 

gpe.check_mouse_button_released(int mouseButtonId )

Returns true or false if the mouse button was just released in frame.
Scope: GPE

Return type : bool

Parameters:

  • int mouseButtonId – The constant assigned to the button. Also procecessed the nobutton and anybutton cases.

 

3.Mouse constants #

In GPE we utilize constants with the “mb_” prefix for handling mouse button input. It is important to know their importance when referencing buttons and their states throughout your games

Here is a complete list of the mb_ constants:

ConstantDescription
mb_anybuttonUsing this constant will cause mouse_checks to see if any button satisfies the called function.
mb_nobuttonUsing this constant will cause mouse_checks to see if all buttons do not satisfy the called function.
mb_leftThe left mouse button.
mb_rightThe right mouse button
mb_middleThe middle mouse button(often time the same as the mouse-wheel)
mb_centerThe middle mouse button(often time the same as the mouse-wheel)

4.Mouse Properties #

GamePencil handles not just the button states of the mouse, but also its global (X, Y )  coordinates in the game as well as camera based mouse coordinates.

5.Examples #

Take a peak of a basic point and click shooter example for using the mouse in GPE:

//Gets the mouse coordinates of camera[0].
this.mouseDirection = this.get_my_direction( gpe.get_camera_mouse_x(0), gpe.get_camera_mouse_y(0) );
if( gpe.check_mouse_released( mb_left ) )
{
    this.targetX = gpe.get_camera_mouse_x(0);
    this.targetY = gpe.get_camera_mouse_y(0);
    //moves towards the mouse coordinates with a speed of 4
    this.move_towards(this.targetX, this.targetY, 4 );
}
else if( gpe.check_mouse_released( mb_right ) && this.canFire  )
{
   //on right click fires a bullet towards the mouse
    var newBullet = gpe.add_new_object( obj_bullet, this.getx(), this.gety() );
    newBullet.direction = this.mouseDirection;
    newBullet.speed = 7;
    //cooldown effect
    this.canFire = false;
    this.start_countdown( 0, 30 );
}

 

Help Guide Powered by Documentor
Suggest Edit