cocos2dx:精靈幀動畫的使用

local sprite = cc.Sprite:create()
local animation = cc.Animation:create()  -- 創建動畫
for i = 1, 10 do
    local frameName = string.format("plist_texture_name_%02d.png", i)
    animation:addSpriteFrame(cc.SpriteFrameCache:getInstance():getSpriteFrame(frameName))  -- 添加精靈幀
end
animation:setDelayPerUnit(1 / 10.0)  -- 設置每一幀持續時間,以秒爲單位
animation:setRestoreOriginalFrame(false)  -- 設置是否在動畫播放結束後恢復到第一幀
-- animation:setLoops(-1)  -- 循環的次數,-1代表一直循環
local action = cc.Animate:create(animation)  -- 由動畫創建Animate動作
sprite:runAction(cc.RepeatForever:create(action))
sprite:setAnchorPoint(0.5, 0.5)
local size = parent:getContentSize()
sprite:setPosition(cc.p(size.width/2, size.height/2 + 2))
sprite:setScaleX(0.9)
sprite:setScaleY(1.1)
parent:addChild(sprite)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章