function g_createAnimation(amName, frameFmtName, firstPos, lastPos, x, y, isForever)
local frames = display.newFrames(frameFmtName, firstPos, lastPos)
local animation = display.newAnimation(frames, 0.5 / 10) --0.5秒播放10帧
display.setAnimationCache(amName, animation)
local sprite = display.newSprite()
sprite:show()
sprite:setPosition(x, y)
if isForever then
sprite:playAnimationForever(display.getAnimationCache(amName)) -- 永久播放
else
sprite:playAnimationOnce(display.getAnimationCache(amName)) -- 播放一次动画
end
return sprite
end
function g_removeAnimation(amName)
display.removeAnimationCache(amName)
end
function CreateMapScene:createAmtest()
cc.SpriteFrameCache:getInstance():addSpriteFrames("amTest/am.plist", "amTest/am.png")
local sprite = g_createAnimation("Drone1", "Drone1_%03d.png", 0, 9, 150, 150, true)
self:addChild(sprite)
-- local frames = display.newFrames("Drone1_%03d.png", 0, 9)
-- local animation = display.newAnimation(frames, 0.5 / 10) --0.5秒播放10帧
-- display.setAnimationCache("Drone1", animation)
-- local sprite = display.newSprite()
-- self:addChild(sprite)
-- sprite:show()
-- sprite:setPosition(150, 150)
-- --sprite:playAnimationOnce(display.getAnimationCache("Drone1")) -- 永久播放
-- sprite:playAnimationForever(display.getAnimationCache("Drone1")) -- 播放一次动画
--display.removeAnimationCache("Drone1") --用完记得删
-- 方法 1
--local moveTo = cc.MoveTo:create(4, cc.p(150, 500))
--sprite:runAction( moveTo )
-- 方法 2
cca.builder()
:begin("spawn")
:moveTo(4, 150, 500)
:done()
--:removeSelf()
:addTo(sprite)
end

Paste_Image.png

Paste_Image.png