VirtualDPad

The VirtualDPad (virtual direction pad) is for systems which do not have normal dpad/buttons. The virtual dpad is displayed on the screen and can be controlled by touch or mouse controls.

How to use:

  • Create a new VirtualDPad.
  • Call mouse handlers (mouseDown(), mouseUp(), mouseMove()), when they are called in your Game-class.
  • Use the left, right, up, down variables of the VirtualDPad to determine which direction the user presses.
  • Override the render()-function to make a beautiful virtual dpad.
  • If your VirtualDPad has another shape than a simple rectangle, override the checkMouseCollision()-function. You might also want to override isMouseWithinMoveArea(), isMouseWithinDeadAreaX() and isMouseWithinDeadAreaY().
  • If the interaction should be canceled, for example if your game or a level in your game restarts, or if the virtual dpad loses focus, because a window has been opened, or in any similar case, call reset().

Caution: - Take care that nothing weird happens when the user presses on both real dpad/button or analog stick, and virtual dpad at the same time. Because this can happen on systems that have both. You can use user_is_interacting to handle this.

Look into the VirtualDPadDemo to see how the VirtualDPad can be used.

Constructor

new (x:Int, y:Int, size:Int, dead_area:Int, move_area:Int)

Constructor

Parameters:

x

: x position on screen in pixels

y

: y position on screen in pixels

size

: Size in pixels (used for both width and height)

dead_area:

Within this area in the center no direction is pressed

move_area:

Outside of this area no direction is pressed

Variables

down:Bool

left:Bool

right:Bool

size:Int

up:Bool

user_is_interacting:Bool

To check if the user is currently using the virtual dpad at all:

x:Int

y:Int

Methods

checkMouseCollision (mouse_x:Int, mouse_y:Int):Bool

isMouseWithinDeadAreaX (mouse_x:Int):Bool

isMouseWithinDeadAreaY (mouse_y:Int):Bool

isMouseWithinMoveArea (mouse_x:Int, mouse_y:Int):Bool

mouseDown (mouse_x:Int, mouse_y:Int):Void

Mouse handlers Call these when the mouse handlers in your Game-class are called

mouseMove (mouse_x:Int, mouse_y:Int):Void

Mouse handlers Call these when the mouse handlers in your Game-class are called

mouseUp (mouse_x:Int, mouse_y:Int):Void

render (painter:Graphics):Void

Please override this with your own function.

Parameters:

painter

: g2 Graphics object

reset ():Void

If the interaction should be canceled, for example if your game or a level in your game restarts, or if the dpad loses focus, because a window has been opened, or in any similar case, call reset().