0
这是代码:jQuery的游戏人物动作系统
$(document).ready(function(){
var mUp=false;
var mLeft=false;
var mRight=false;
function movement(){
$(function(){
if(mUp){
$('.user').animate({
bottom: '+=120'
},{
duration: 50,
easing: 'linear',
complete: function() {
$('.user').animate({
bottom: '-=120'
},{
duration: 150,
easing: 'linear',
complete: function() {
mUp=false;
if(!mRight&&!mLeft){
$('.user').stop();
}
}
}).dequeue();
}
}).dequeue();
}
if(mRight){
$('.user').animate({
left: '+=1000'
},{
duration: 1000,
easing: 'linear',
}).dequeue();
}
if(mLeft){
$('.user').animate({
left: '-=1000'
},{
duration: 1000,
easing: 'linear',
}).dequeue();
}
});
}
$(document).keydown(function(e){
var curKey=e.keyCode;
if(curKey==39){
console.log('right+');
if(!mRight){
mRight=true;
movement();
}
}
if(curKey==37){
if(!mLeft){
mLeft=true;
movement();
}
}
if(curKey==38){
console.log('up+');
if(!mUp){
mUp=true;
movement();
}
}
});
$(document).keyup(function(e){
var curKey=e.keyCode;
if(curKey==39){
console.log('right-');
if(!mUp){
$('.user').stop();
}
mRight=false;
}
if(curKey==37){
console.log('left-');
if(!mUp){
$('.user').stop();
}
mLeft=false;
}
if(curKey==38){
console.log('up-');
}
});
});
我正在为一个基于jQuery的游戏简单的运动系统。我可以左右移动角色并跳转。在跳转动画仍在进行的过程中,尝试向左或向右移动角色时,我的问题就开始了。如果我在已经向左或向右移动的情况下跳转,但是当我第一次跳转时,当跳转动画仍然有效时,尝试向左或向右移动它有点疯狂。
的jsfiddle:CLICK
我知道你不希望这种行为,但我喜欢它(就像攀登),我会说http://geekwhisperin.files.wordpress.com/2009/09/ bug-vs-feature.jpg – 2014-10-09 16:19:59
在发布之前,我想到你说的是什么,但是..行为有它自己的想法。从外观上看,我坚持不懈。 :) – user1885099 2014-10-09 16:39:18