cocos2d-x笔记(十)Lua开发飞机大战-4-创建主角

来源:互联网 发布:淘宝电器小家电 编辑:程序博客网 时间:2024/06/05 02:03

飞机大战之所以叫飞机大战,肯定要飞机才行。这一篇我们就为游戏添加一架飞机——也就是我们的主角。

先创建一个图层(PlaneLayer)用来显示飞机,然后在create方法中初始化飞机

module("PlaneLayer",package.seeall) local plane = nilisAlive = truefunction create()local planeLayer =  CCLayer:create()CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile("Images/shoot.plist")plane = CCSprite:createWithSpriteFrameName("hero1.png")plane:setPosition(ccp(visibleSize.width / 2,plane:getContentSize().height / 2))planeLayer:addChild(plane)isAlive = truereturn planeLayerend

主角这样登场显得有些草率和唐突,现在为主角的出场添加一点效果

local blink = CCBlink:create(1,3)local animation = CCAnimation:create()animation:setDelayPerUnit(0.1)animation:addSpriteFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName("hero1.png"))animation:addSpriteFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName("hero2.png"))local animate = CCAnimate:create(animation)plane:runAction(blink)plane:runAction(CCRepeatForever:create(animate))


 

0 0
原创粉丝点击