New answers tagged

3

context.clearRect() has a method signature of: context.clearRect(x, y, width, height) In your code, however, you are passing the height and width in the incorrect positions. Changing your call to context.clearRect(0, 0, canvas.width, canvas.height) fixes the issue. MDN clearRect() documentation.


0

Similar to RDeving's answer, here's my usual code: var keys = {}; window.onkeydown = function(evt) { keys[evt.keyCode] = true; } window.onkeyup = function(evt) { delete keys[evt.keyCode]; } Then, in your update loop: if (37 in keys) { //keycode 39 is down } if (38 in keys) { //keycode 38 is down } // ... etc


0

Is simple, you have to use a simple "camara" system and make the cube or item or player be the center of it, so...done Here's an example of a camera in pure javascript Use arrows to move the camera var map = []; for(var t = 0; t < 100; t++){ var r = []; for(var tt = 0; tt < 100; tt++) r.push(Math.floor(Math.random()*4)); ...



Top 50 recent answers are included