您的位置:首页 > 移动开发 > Cocos引擎

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

2014-04-18 19:52 441 查看
飞机大战之所以叫飞机大战,肯定要飞机才行。这一篇我们就为游戏添加一架飞机——也就是我们的主角。

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

module("PlaneLayer",package.seeall)
local plane = nil
isAlive = true
function 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 = true
return planeLayer
end

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

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))


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2d-x Lua blink
相关文章推荐