我正在为一个画布游戏制作一个动画系统。每当我想移动一个播放器时,我使用entities[0].moveTo(...),entities[0]是一个对象,moveTo()是它的方法,执行更大的animate()函数。
var moveTo = function(x,y,d){
if(x!=0) animate(this,'x',this.coords.x+x*tilescale,d,animation_mode);
if(y!=0) animate(this,'y',this.coords.y+y*tilescale,d,animation_mode);
}
var animate = function(e, prop, val, duration, mode) {
if(mode){
var start = new Date().getTime();
var end = start + duration;
var current = e["offset"][prop];
var distance = val - current;
var step = function() {
var timestamp = new Date().getTime();
var progress = Math.min((duration - (end - timestamp)) / duration, 1);
e["offset"][prop] = current + (distance * progress);
render();
if (progress < 1) requestAnimationFrame(step);
else ## moveTo.onanimationfinished() ##
};
return step();
}
else{
return;
}
};基本上,我想要两个小变换的“颠簸”动画--前进,然后快速后退。当“前进”部分完成时,应显示“返回”部分。有办法做到这一点吗?
发布于 2016-06-23 07:53:21
您可以创建一个新函数bumb,然后在animate的末尾调用它,但您也可以在animate函数中给出另一个名为bumb的参数,如下所示:
var animate = function(e, prop, val, duration, mode, bump) {
if(bump){
// Bump animatio
}
else{
// Move animation
}
}https://stackoverflow.com/questions/37979159
复制相似问题