TIMER-ENGINE
Timer make loop with "update" and "draw" states function
Live example
Install
npm i timer-engine --save
or
yarn add timer-engine
Importing
; const timer = ;timer { /*make something*/};timer { /*make something*/};timerstart;
Sample SNAKE GAME
simple game to test Timer-engine plugin
index.html file
script.js file
var canvas = documentbodychildren0;var context = canvas;context;snake = 16 1; action = ArrowUp: 0 -1 ArrowDown: 0 1 ArrowLeft: -1 0 ArrowRight: 1 0; direction = 0 1;apple = 5 5; // intance and choose frequencetimer = Timer; // use keyboard to move snakewindow { direction = actionkey || direction;}; // set Update functiontimer { head = snake0; snake; if apple0 === head0 && apple1 === head1 apple = Math * 32 | 0 Math * 24 | 0; else snake; }; // set Draw functiontimer { context; contextfillStyle = "red"; context; contextfillStyle = "black"; snake;}; //first drawtimer; //click to start gamedocument;
Options
Methods
.start()
Type | Description |
---|---|
function |
Start the loop, if it wasn't already start |
.stop()
Type | Description |
---|---|
function |
Stop the loop, if it wasn't already stop |
.setFrequence(num)
Type | Description |
---|---|
function |
set new frequence loop |
argument | type | Description |
---|---|---|
num |
number |
new value of frequence |