2014-07-26 31 views
0

我正在使用EaselJS SpriteSheets,我想知道如何讓我的英雄停止平穩運行,所以如果SpriteSheet正在播放「運行」動畫並且它在第5幀,我需要爲第6,7,8,8,8,7,6,5等動畫製作動畫,然後在0上停下來讓我的英雄靜止不動。 我該怎麼做?EaselJS雖然基於當前幀的框架生成動畫

這裏是我的SpriteSheet:

my SpriteSheet

注意,框架是不連續的:他們去從0到4,4到0,則5〜8幀9未被使用。

這裏是我的SpriteSheet代碼:

user.hero.bmp = new createjs.Bitmap("Graphics/Fox.png"); 
user.hero.bmp.cache(0, 0, user.hero.bmp.image.width, user.hero.bmp.image.height); 
var data = new createjs.SpriteSheet({ 
    images: [user.hero.bmp.cacheCanvas], 
    frames: { 
     width: 30, 
     height: 40 
    }, 
    animations: { 
     stand: 0, 
     run: { 
      frames: [0,1,2,3,4,4,4,3,2,1,0,5,6,7,8,8,8,7,6,5], 
      next: true, 
      speed: .75 
     } 
    } 
}); 
user.hero = new createjs.Sprite(data, "stand"); 
// Removed lots of non-relevant things here 
movableObjContainer.addChild(user.hero); 
movableObj.push(user.hero); 

下面是我用動畫之間切換的功能:

function changeAnimation(obj, frameOrAnimation) { 
    if (obj.animation != frameOrAnimation) { 
     obj.animation = frameOrAnimation; 
     obj.gotoAndPlay(frameOrAnimation); 
    } 
} 

函數用法:changeAnimation(user.hero, "stand");

和這裏的日Ë最重要的部分,那裏面股票運行動畫邏輯:

if ((user.input.left || user.input.right) && !user.hero.jumping) { 
    changeAnimation(user.hero, "run"); 
} else if (!user.hero.jumping && user.hero.animation != "stopFalling" && user.hero.animation != "almostFalling") { 
    changeAnimation(user.hero, "stand"); 
} 

回答

1

當重新制定我的問題,我明白我的問題更好,解決了這個問題。 謝謝,StackOverflow。

所以,我想我需要得到實際的幀編號,然後每增加一個減號1減去它,直到它到達幀0爲止。不幸的是,這種方法過於複雜,它顯然會妥協可維護性。

我已經通過檢查currentFrame屬性是否等於零來解決我的問題。如果不是則動畫繼續,否則動畫停止。

下面是生成的代碼:

if ((user.input.left || user.input.right) && !user.hero.jumping) { 
    changeAnimation(user.hero, "run"); 
} else if (!user.hero.jumping && user.hero.animation != "stopFalling" && user.hero.animation != "almostFalling") { 
    if (!(user.hero.animation == "run" && user.hero.currentFrame != 0)) { 
     changeAnimation(user.hero, "stand"); 
    } 
}