Cocos2d-x-lua实现简单的动画帧、读取CocoStudio文件

-- create a zombies<创建精灵帧动画>

local z_caches = CCSpriteFrameCache:sharedSpriteFrameCache()--加入缓存帧中

local z_path = CCFileUtils:sharedFileUtils():fullPathForFilename("zombies/BucketheadZombie_default.plist")

z_caches:addSpriteFramesWithFile(z_path)--添加plist文件

local z_sprite = CCSprite:createWithSpriteFrameName("BucketheadZombie1.png")--初始化一下精灵

z_sprite:setPosition(ccp(win_w/2-190, win_h/2-90))--设置精灵位置

local z_ccarray = CCArray:create();--创建数组存放精灵帧

z_ccarray:retain()

for i=1,15 do

local temp = string.format("BucketheadZombie%d.png",i)--读取拼接每帧动画名

local z_spriteFrame = z_caches:spriteFrameByName(temp)--从缓存中读取每帧

z_ccarray:addObject(z_spriteFrame)--加入到数组中

end

local z_animation = CCAnimation:createWithSpriteFrames(z_ccarray, 0.1)--将帧序列加入动画中

z_animation:setLoops(-1)--永久循环动作

local z_animate = CCAnimate:create(z_animation)--创建动画

z_sprite:runAction(z_animate)--运行动画

self:addChild(z_sprite)--加入层中

--创建一个 辣椒植物 

local p_path = CCFileUtils:sharedFileUtils():fullPathForFilename("zombies/Squash_default.plist")

z_caches:addSpriteFramesWithFile(p_path)

local p_sprite = CCSprite:createWithSpriteFrameName("Squash1(被拖移).tiff")

local p_animation = CCAnimation:create()

p_animation:setDelayPerUnit(0.2)

for k=1,17 do

local p_temp = string.format("Squash%d(被拖移).tiff",k)

local p_frame = z_caches:spriteFrameByName(p_temp)

p_animation:addSpriteFrame(p_frame)

end

p_sprite:runAction(CCRepeatForever:create(CCAnimate:create(p_animation)))

p_sprite:setPosition(ccp(win_w/2+200, win_h/2+90))

self:addChild(p_sprite)


-- 创建植物

local pea_path = CCFileUtils:sharedFileUtils():fullPathForFilename("zombies/Threepeater_default.plist")

z_caches:addSpriteFramesWithFile(pea_path)

local pea_sprite = CCSprite:createWithSpriteFrameName("Threepeater1(被拖移).tiff")

local pea_animation = CCAnimation:create()

pea_animation:setDelayPerUnit(0.2)

for i=1,16 do

local pea_temp = string.format("Threepeater%d(被拖移).tiff",i)

local pea_frame = z_caches:spriteFrameByName(pea_temp)

pea_animation:addSpriteFrame(pea_frame)

end

        pea_animation:setLoops(-1)

        local pea_animate = CCAnimate:create(pea_animation)

        pea_sprite:setPosition(ccp(win_w/2, win_h/2-100))

        pea_sprite:runAction(pea_animate)

        self:addChild(pea_sprite)


        -- 创建一个 Ball

        local  m_ball= Ball.new("dog.png")

        m_ball:setPosition(ccp(100, 100))

        m_ball.move()

        m_ball.setOriginal(ccp(90, 90))

        local moves = CCMoveTo:create(0.2, ccp(300, 100))

    local rotate = CCRotateBy:create(0.2, 360)

    local array = CCArray:create()

    array:addObject(moves)

    array:addObject(rotate)

    local spawn = CCSpawn:create(array) 

    m_ball:runAction(spawn)


        self:addChild(m_ball)


        -- 读取一个CocosStudio的文件Json

        local uiLayout = GUIReader:shareReader():widgetFromJsonFile("SampleUIAnimation.json")

        uiLayout:setPosition(ccp(win_w/2-90, win_h/2-100))

        self:addWidget(uiLayout)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GFanStudio-LeeSir

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值