HTML and CSS Reference
In-Depth Information
Create an
update
function below the constructor that looks like this:
update():void{
console.log("update called");
}
Now, you should be able to save the file, make sure that it compiles, and refresh the page. In the console, you will
see that update being called in time with the browser's
requestAnimationFrame
, as demonstrated in Figure
19-10
.
Figure 19-10.
As you can see, update is being called a lot, as the loop is going to continue to run without interruption
Let's also add a
draw
method call to your
update
function and to the method itself. Replace “update called”
console.log
with this:
if (this.invalid) {
this.draw();
}
Next, create the new method:
draw():void{
console.log("draw called");
this.invalid = false;
}
Finally, you have to add a property to your class, right above the constructor called invalid, as follows:
invalid: boolean = true;