Dart Documentationgame_loopGameLoopMouse

GameLoopMouse class

A mouse input. Has digital buttons corresponding to mouse buttons: LEFT, MIDDLE, RIGHT. Also implements the GameLoopPositionInput interface.

class GameLoopMouse extends GameLoopDigitalInput
   implements GameLoopPositionInput {
 /** Left mouse button */
 static const LEFT = 0;
 /** Middle mouse button */
 static const MIDDLE = 1;
 /** Right mouse button */
 static const RIGHT = 2;
 static final List<int> _buttonIds = [LEFT, MIDDLE, RIGHT];


 int _dx = 0;
 /** Mouse movement in x direction since previous frame. */
 int get dx => _dx;

 int _dy = 0;
 /** Mouse movement in y direction since previous frame. */
 int get dy => _dy;


 int _x = 0;
 /** Mouse position in x direction within element. */
 int get x => _x;

 int _y = 0;
 /** Mouse position in y direction within element. */
 int get y => _y;


 double _time = 0.0;
 /** Time at which mouse position was last updated. */
 double get time => _time;


 int _frame  = 0;
 /** Frame at which mouse position was last updated. */
 int get frame => _frame;

 GameLoopMouse(gameLoop) : super(gameLoop, _buttonIds);

 /** Process one [GameLoopMouseEvent]. */
 void gameLoopMouseEvent(GameLoopMouseEvent event) {
   _x = event.x;
   _y = event.y;
   _time = event.time;
   _frame = event.frame;
   _dx += event.dx;
   _dy += event.dy;
 }

 void _resetAccumulators() {
   _dx = 0;
   _dy = 0;
 }
}

Extends

GameLoopDigitalInput > GameLoopMouse

Implements

GameLoopPositionInput

Static Properties

const LEFT #

LEFT = 0

const MIDDLE #

MIDDLE = 1
RIGHT = 2

Constructors

new GameLoopMouse(gameLoop) #

GameLoopMouse(gameLoop) : super(gameLoop, _buttonIds);

Properties

final Map<int, GameLoopDigitalButton> buttons #

inherited from GameLoopDigitalInput
buttons =
new Map<int, GameLoopDigitalButton>()

final int dx #

Mouse movement in x direction since previous frame.

int get dx => _dx;

final int dy #

Mouse movement in y direction since previous frame.

int get dy => _dy;

final int frame #

Frame at which mouse position was last updated.

int get frame => _frame;

final GameLoop gameLoop #

inherited from GameLoopDigitalInput
gameLoop

final double time #

Time at which mouse position was last updated.

double get time => _time;

final int x #

Mouse position in x direction within element.

int get x => _x;

final int y #

Mouse position in y direction within element.

int get y => _y;

Methods

void digitalButtonEvent(GameLoopDigitalButtonEvent event) #

inherited from GameLoopDigitalInput

Deliver an input event

void digitalButtonEvent(GameLoopDigitalButtonEvent event) {
 GameLoopDigitalButton button = buttons[event.buttonId];
 if (button == null) {
   return;
 }
 if (event.down) {
   if (button.down == false) {
     // Ignore repeated downs.
     button.framePressed = event.frame;
     button.timePressed = event.time;
   }
 } else {
   button.frameReleased = event.frame;
   button.timeReleased = event.time;
 }
}

void gameLoopMouseEvent(GameLoopMouseEvent event) #

Process one GameLoopMouseEvent.

void gameLoopMouseEvent(GameLoopMouseEvent event) {
 _x = event.x;
 _y = event.y;
 _time = event.time;
 _frame = event.frame;
 _dx += event.dx;
 _dy += event.dy;
}

bool isDown(int buttonId) #

inherited from GameLoopDigitalInput

Is buttonId down this frame?

bool isDown(int buttonId) {
 GameLoopDigitalButton button = buttons[buttonId];
 if (button == null) {
   return false;
 }
 return button.down;
}

bool isUp(int buttonId) #

inherited from GameLoopDigitalInput

Is buttonId up this frame?

bool isUp(int buttonId) {
 GameLoopDigitalButton button = buttons[buttonId];
 if (button == null) {
   return true;
 }
 return button.up;
}

bool pressed(int buttonId) #

inherited from GameLoopDigitalInput

Was buttonId just pressed down?

bool pressed(int buttonId) {
 GameLoopDigitalButton button = buttons[buttonId];
 if (button == null) {
   return false;
 }
 return button.framePressed == gameLoop.frame;
}

bool released(int buttonId) #

inherited from GameLoopDigitalInput

Was buttonId just released?

bool released(int buttonId) {
 GameLoopDigitalButton button = buttons[buttonId];
 if (button == null) {
   return false;
 }
 return button.frameReleased == gameLoop.frame;
}

double timePressed(int buttonId) #

inherited from GameLoopDigitalInput

Time buttonId was pressed.

double timePressed(int buttonId) {
 GameLoopDigitalButton button = buttons[buttonId];
 if (button == null) {
   return 0.0;
 }
 return button.timePressed;
}

double timeReleased(int buttonId) #

inherited from GameLoopDigitalInput

Time buttonId was released.

double timeReleased(int buttonId) {
 GameLoopDigitalButton button = buttons[buttonId];
 if (button == null) {
   return 0.0;
 }
 return button.timeReleased;
}