0
我在學校爲Game Jam做準備,遇到了問題。在這段代碼中,我試圖做到這一點,當你按下右箭頭鍵時,它會將字符向右移動。但是這個功能正在使它從右而不是右移。我在使用JavaScript和jQuery的遊戲角色代碼時遇到問題
這裏是我的代碼---
var main = function() {
var moveRight = function() {}
var wall = function() {
wall = $('.header')
}
$(document).keypress(function(event) {
if(event.which === 32) {
$('.header').animate({
bottom: "-31px"
},1000)
}
});
$(document).keydown(function(event) {
if(event.which === 39) {
$('.character').animate({
right: "400px"
},1000)
}
});
}
$(document).ready(main);
的問題是在這裏的某個地方---
$(document).keydown(function(event) {
if(event.which === 39) {
$('.character').animate({
right: "400px"
},1000)
}
});
謝謝您的幫助。
爲什麼這兩段代碼不同?第一個看起來錯了。 「right:400px」將從右側邊緣將右邊緣設置爲400px,而不是將其移動到右邊的400px。 –
你應該朝相反的方向移動你的角色。 –