Answers for "javascript gameloop"

0

javascript game loop

function loop() {
  //Game logic here
  
  requestAnimationFrame(loop);
}
loop();
Posted by: Guest on June-04-2020
0

javascript gameloop

<script>
    "use strict";
    let canvas;
    let context;

    window.onload = init;

    function init(){
        canvas = document.getElementById('canvas');
        context = canvas.getContext('2d');

        // Start the first frame request
        window.requestAnimationFrame(gameLoop);
    }

    function gameLoop(timeStamp){
        draw();

        // Keep requesting new frames
        window.requestAnimationFrame(gameLoop);
    }

    function draw(){
        let randomColor = Math.random() > 0.5? '#ff8080' : '#0099b0';
        context.fillStyle = randomColor;
        context.fillRect(100, 50, 200, 175);
    }
</script>
Posted by: Guest on August-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language