飞机大战之所以叫飞机大战,肯定要飞机才行。这一篇我们就为游戏添加一架飞机——也就是我们的主角。
先创建一个图层(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))
本文介绍如何在《飞机大战》游戏中创建主角飞机,并通过动画效果增强其出场表现。首先,通过Lua脚本创建了一个名为PlaneLayer的新图层来显示主角飞机。接着使用CCSprite创建了主角飞机,并设置其初始位置。为了使主角的出现更加吸引人,还添加了闪烁和动画效果。
3216

被折叠的 条评论
为什么被折叠?



