「HTML5開発」playerを作成、キーボードをコントロールする

処理コード:
1.playerを作成
var player = {
color: “#00A",
x: 220,
y: 270,
width: 32,
height: 32,
draw: function() {
canvas.fillStyle = this.color;
canvas.fillRect(this.x, this.y, this.width, this.height);
}
};
2.keyboardをコントロールする

function update() {
if (keydown.left) {
player.x -= 5;
}
if (keydown.right) {

player.x += 5;

}

player.x = player.x.clamp(0, CANVAS_WIDTH – player.width);

}

jQuery

Posted by arkgame