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:runAction(cc.Sequence:create(
action,
cc.CallFunc:create(function()
sprite:removeFromParent()
end)
))
]]
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)