初始化一个飞机类的时候,先读取对应的清单 plist文件,然后再读取飞机的图片~ cocos2d-x 3.0 C++写法
bool PlaneLayer::initInstance()
{
// return Layer::init();
bool bRet = false;
do{
CC_BREAK_IF(!Layer::init());
Size winSize = Director::getInstance()->getWinSize();
// 先读取 plist 文件 然后再读入对应的图片名字形成动画效果。
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("shoot.plist");
auto plane = Sprite::createWithSpriteFrameName("hero1.png");
this->addChild(plane,0,AIRPLANE); //AIRPLANE 是Tag
auto blink = Blink::create(1,3);
auto animation = Animation::create();
animation->setDelayPerUnit(0.1f);
animation->addSpriteFrameWithFile("hero1.png");
animation->addSpriteFrameWithFile("hero2.png");
auto animate = Animate::create(animation);
plane->runAction(blink);
plane->runAction(RepeatForever::create(animate));
bRet = true;
}while(0);
return bRet;
}
附加Javascripte 的闪烁。不过没有读取plist
var PlaneLayer = cc.Layer.extend({
ctor:function(){this._super();
cc.associateWithNative(this,cc.Layer);},
init:function(){
//var animation = cc.Animation.create();
cc.log(s_planeh1);
var size = cc.Director.getInstance().getWinSize();
var layer = cc.LayerColor.create(cc.c4b(255, 255, 0, 100));
this.addChild(layer,-1);
var plane = cc.Sprite.create(s_planeh1);
var blink = cc.Blink.create(1,3);
var animation = cc.Animation.create();
animation.addSpriteFrameWithFile(s_planeh1);
animation.addSpriteFrameWithFile(s_planeh2);
var animate = cc.Animate.create(animation);
plane.runAction(blink);
plane.runAction(cc.RepeatForever.create(cc.Sequence.create(animate,blink)));
plane.setPosition(size.width/2,size.height/3);
this.addChild(plane,1);
}
});