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