View source code: https://github.com/a-mean-blogger/text-game-maker-js/blob/master/src/base-objects/interval.js
Class (extends TM.IObject)
A class that creates instances repeats a function with interval. The object that loops the function in TM.ILoopObject is also the instance of this class.
new TM.Interval(speed, func)
true
after calling init function, false
after calling inactivate. The Object status(active/inactive) can be checked by this property.**View example source code: interval-tutorial.js
We will make MyWatch class that prints current time using TM.Interval class.
First, create an instance of TM.ScreenManager and assign to var TMS(Text Game Maker Screen).
var TMS = new TM.ScreenManager();
Create an instance of TM.Interval that creates current time and print on the screen with 1000 milliseconds interval.
var myWatch = new TM.Interval(1000,function(){ var date = new Date(); TMS.insertTextAt(1,1,date.toLocaleTimeString()); }) myWatch.init()
Type these commands into the browser console on this page to test.
//inactivate myWatch
myWatch.inactivate(); //reactivate(initialize) myWatch
myWatch.init(); //reset loop interval speed of myWatch myWatch.setSpeed(2000);
Comments
Login with SNS account to write comments. see details