我写了这个代码来移动我的角色并且它可以工作,但它只是前进...我希望它在它击中屏幕边缘时复出(我的是1280px)。请帮忙!
let charPosition = parseInt(character.css('left'));
for (let i = 0; i < 400; i++) {
setTimeout(function(){
if(i<100){
character.css('left',currentX+=20);
}else if(i>=100){
character.css('left',currentX+=20);
character.css({'background-image':'url(https://gameartpartners.com/wp-content/uploads/edd/2015/03/Golden_Knight_featured.png)'});
if(charPosition >= 1200){
character.css('left',currentX-=200);
}
}
}, timer()[i]);
}
function timer () {
let number = 0;
let array = [];
for (i =0; i< 400; i++) {
number = number + 400 - 1 * i;
array.push(number);
} return array; }