im试图用箭头键移动我的图像luvmush。但即时通讯无法弄清楚如何正确地链接和填充。谢谢!我只是想用JS做游戏。
var gsc = document.getElementById("gsc");
var context = gsc.getContext("2d");
//gsc= game screen
this is the image that im trying to make move.
var luvmush = document.getElementById("luvmush")
var luvmush = new Image();
luvmush.src = "./images/Pinky.png"
context.drawImage(luvmush, 100, 400, 30, 30);
//array for key states
let keys = new Array (0xff).fill(0);
//listeners
document.addEventListener('keydown', e=> keys[e.keyCode] = 1);
document.addEventListener('keyup', e=> keys[e.keyCode] = 0);
//key codes
const LEFT = 37;
const UP = 38;
const RIGHT = 39;
const DOWN = 40;
let dx = keys[RIGHT] - keys[LEFT];
let dy = keys[DOWN] - keys[UP];
//moving
x += dx * t * SPEED;
y += dy * t * SPEED;
What should i change? or add?