我正在用javascript编写一个RPG游戏,我希望我的主角在你按下箭头键或wasd键时移动。我有生成他的代码,但是我应该如何定义他的位置,以便在按下上述键时他移动?
function mainchar(){
var mainchar = new Image();
mainchar.src = /*I'll add this soon*/;
mainchar.style.top = /*What should I put here?*/;
mainchar.style.left = /*What should I put here?*/;
mainchar.style.position = "absolute";
document.body.appendChild( mainchar );
}