showing results for - "javascript gameloop"
Irene
15 Sep 2018
1function loop() {
2  //Game logic here
3  
4  requestAnimationFrame(loop);
5}
6loop();
Jessica
09 Apr 2018
1<script>
2    "use strict";
3    let canvas;
4    let context;
5
6    window.onload = init;
7
8    function init(){
9        canvas = document.getElementById('canvas');
10        context = canvas.getContext('2d');
11
12        // Start the first frame request
13        window.requestAnimationFrame(gameLoop);
14    }
15
16    function gameLoop(timeStamp){
17        draw();
18
19        // Keep requesting new frames
20        window.requestAnimationFrame(gameLoop);
21    }
22
23    function draw(){
24        let randomColor = Math.random() > 0.5? '#ff8080' : '#0099b0';
25        context.fillStyle = randomColor;
26        context.fillRect(100, 50, 200, 175);
27    }
28</script>