【发布时间】:2014-09-17 22:30:12
【问题描述】:
我正在使用 EaselJS SpriteSheets,我想知道如何让我的英雄停止平稳运行,所以如果 SpriteSheet 正在播放“运行”动画并且它在第 5 帧上,我需要通过帧进行动画处理6, 7, 8, 8, 8, 7, 6, 5 然后停在 0 以使我的英雄静止。 我该怎么做?
这是我的 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");
这是最重要的部分,在ticker中运行的动画逻辑:
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");
}
【问题讨论】:
标签: javascript animation html5-canvas easeljs sprite-sheet