这是我的 jsfiddle:http: //jsfiddle.net/yKvuK/6/
if (keydown.right) {
characterImg.src = 'http://pixenate.com/pixenate//cache/photo_e2094a30725ccd74a6d889648d34343b.jpg';
character.CurentPos++;
character.x += character.speed;
if (character.x > CanvasWidth - character.width) { // make the character keep walking even if he step outside the canvas
character.x = 0;
}
}
if (keydown.up) {
characterImg.src = "http://pixenate.com/pixenate//cache/photo_1_5ef90294cd2afeb4486dedd663cfd872.jpg";
character.y -= character.speed;
if (character.y < 0) {
character.y = 0;
}
character.CurentPos++;
}
if (keydown.down) { //going down
characterImg.src = "http://pixenate.com/pixenate//cache/photo_1_ff6712ddd80b138f1865eb4937622d1b.jpg";
character.CurentPos++;
character.y += character.speed;
if (character.y > CanvasHeight - character.height) {
character.y = CanvasHeight - character.height;
}
}
你可以在尝试上下移动角色时看到问题有人可以帮助我吗?