SHARE
TWEET

Untitled

a guest Jun 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function parent(){
  2.     mainCanvas.load();
  3. }
  4.  
  5.   var mainCanvas = {
  6.  
  7.         canvas : document.getElementById("myCanvas"),
  8.  
  9.         load: function(){
  10.             //ctx1.beginPath();
  11.             ctx1 = canvas.getContext("2d");
  12.             ctx1.canvas.width = (window.innerWidth)/2;
  13.             ctx1.canvas.height = window.innerHeight;
  14.             ctx1.fillStyle = "black";
  15.             ctx1.fillRect(0, 0, ctx1.canvas.width, ctx1.canvas.width);
  16.             //ctx1.fillStyle = "blue";
  17.             //if (diffColor == true)
  18.                 //ctx1.fillStyle = "yellow";
  19.             //ctx1.fillRect(30, 30, 100, 150);
  20.  
  21.             document.body.insertBefore(canvas, document.body.childNodes[0]);
  22.             interval = setInterval(moveTracker, 20);
  23.  
  24.             window.addEventListener ("keydown", function(e){
  25.                 console.log(e.keyCode);
  26.                 mainCanvas.key = e.keyCode; //execute movement when key pressed
  27.                 if (e.keyCode == 38)
  28.                     diffColor = true;
  29.                 else
  30.                     diffColor = false;
  31.             });
  32.             window.addEventListener ("keyup", function(e){
  33.                     mainCanvas.key = false; //stop movement once key is released
  34.                     })
  35.         },
  36.  
  37.         clear: function(){
  38.             ctx1.clearRect(0,0, canvas.width, canvas.height);
  39.         }
  40.         //ctx1.fill();
  41.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top