Dart Documentationgame_loopGameLoopDigitalInput

GameLoopDigitalInput class

A collection of digital input buttons

class GameLoopDigitalInput {
 /** Game loop this digital input belongs to. */
 final GameLoop gameLoop;
 /** Buttons this digital input knows about */
 final Map<int, GameLoopDigitalButton> buttons =
     new Map<int, GameLoopDigitalButton>();

 /** Create a digital input that supports all buttons in buttonIds. */
 GameLoopDigitalInput(this.gameLoop, List<int> buttonIds) {
   for (int buttonId in buttonIds) {
     buttons[buttonId] = new GameLoopDigitalButton(buttonId);
   }
 }

 /** 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;
   }
 }

 /** Is [buttonId] down this frame? */
 bool isDown(int buttonId) {
   GameLoopDigitalButton button = buttons[buttonId];
   if (button == null) {
     return false;
   }
   return button.down;
 }

 /** Was [buttonId] just pressed down? */
 bool pressed(int buttonId) {
   GameLoopDigitalButton button = buttons[buttonId];
   if (button == null) {
     return false;
   }
   return button.framePressed == gameLoop.frame;
 }

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

 /** Is [buttonId] up this frame? */
 bool isUp(int buttonId) {
   GameLoopDigitalButton button = buttons[buttonId];
   if (button == null) {
     return true;
   }
   return button.up;
 }

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

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

Subclasses

GameLoopKeyboard, GameLoopMouse

Constructors

new GameLoopDigitalInput(GameLoop gameLoop, List<int> buttonIds) #

Create a digital input that supports all buttons in buttonIds.

GameLoopDigitalInput(this.gameLoop, List<int> buttonIds) {
 for (int buttonId in buttonIds) {
   buttons[buttonId] = new GameLoopDigitalButton(buttonId);
 }
}

Properties

final Map<int, GameLoopDigitalButton> buttons #

buttons =
new Map<int, GameLoopDigitalButton>()

final GameLoop gameLoop #

gameLoop

Methods

void digitalButtonEvent(GameLoopDigitalButtonEvent event) #

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;
 }
}

bool isDown(int buttonId) #

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) #

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) #

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) #

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) #

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) #

Time buttonId was released.

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