基于 helloworld-example 和 cocos-2d-x 文档(http://www.cocos2d-x.org/wiki/Sprite_Sheet_Animation),我尝试制作一个简单的精灵表动画。这是代码:
this.mostafa = cc.Sprite.create(res.Mostafa_png);
this.mostafa.attr({
x: size.width / 3,
y: size.height / 3,
scale: 0.2,
rotation: 180
});
this.addChild(this.mostafa, 0);
var rotate = cc.RotateTo.create(2, 0);
cc.spriteFrameCache.addSpriteFrames(res.Mostafa_plist);
var animFrames = [];
var str = "";
for (var i = 1; i < 9; i++) {
str = "mosquito_fly" + (i < 10 ? ("0" + i) : i) + ".png";
var frame = cc.spriteFrameCache.getSpriteFrame(str);
animFrames.push(frame);
}
var animation = cc.Animation.create(animFrames, 0.04);
var animate = cc.Animate.create(animation);
this.mostafa.runAction(animate); // shows nothing
//this.mostafa.runAction(rotate); // shows turning sprite
它没有显示任何东西。但是,如果我放入最后一行并放出第二行,那么它会显示一个旋转的精灵。(精灵帧缓存加载正确)
什么不见了?