--方法1
local spriteFrameCache=
cc.SpriteFrameCache:getInstance();
local animationCache=
cc.AnimationCache:getInstance();
spriteFrameCache:addSpriteFrames("Effect/loading.plist");
animationCache :addAnimations
("Effect/loading_effect.plist");
local animation_loading=
cc.AnimationCache:getInstance():getAnimation("animation_loading")
self.animationLoading
= cc.Sprite:create();
self.animationLoading:setPosition( cc.p(viewSize.width/2,
viewSize.height/2));
self.Layer :addChild
( self.animationLoading);
self.animationLoading:runAction( cc.RepeatForever:create(cc.Animate:create(animation_loading) ) );
--方法2
--[[
local spriteFrameCache=
cc.SpriteFrameCache:getInstance();
spriteFrameCache:addSpriteFrames("Effect/loading.plist","Effect/loading.png");
self.animationLoading = cc.Sprite:create();
self.animationLoading:setPosition( cc.p(viewSize.width/2,
viewSize.height/2));
self.Layer :addChild
( self.animationLoading);
local animFrames = {};
for i=1,59 do
if i<10 then
local frame = spriteFrameCache:getSpriteFrame( string.format("loading_00%02d.png", i) );
animFrames[i] = frame;
end
local frame = spriteFrameCache:getSpriteFrame( string.format("loading_0%02d.png", i) );
animFrames[i] = frame;
end
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.03);
self.animationLoading:runAction( cc.RepeatForever:create(cc.Animate:create(animation) ) );
]]
------------------------------
loading_effect.plist文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>animations</key>
<dict>
<!-- Loading特效 -->
<key>animation_loading</key>
<dict>
<key>delay</key>
<real>0.03</real>
<key>frames</key>
<array>
<string>loading_000.png</string>
<string>loading_001.png</string>
....
<string>loading_059.png</string>
</array>
</dict>
</dict>
</dict>
</plist>
------------------------------
loading_.plist文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>frames</key>
<dict>
<key>loading_000.png</key>
<dict>
<key>frame</key>
<string>{{508,84},{1,1}}</string>
<key>offset</key>
<string>{-99.5,99.5}</string>
<key>rotated</key>
<false/>
<key>sourceColorRect</key>
<string>{{0,0},{1,1}}</string>
<key>sourceSize</key>
<string>{200,200}</string>
</dict>
......................
<key>loading_059.png</key>
<dict>
<key>frame</key>
<string>{{508,84},{1,1}}</string>
<key>offset</key>
<string>{-99.5,99.5}</string>
<key>rotated</key>
<false/>
<key>sourceColorRect</key>
<string>{{0,0},{1,1}}</string>
<key>sourceSize</key>
<string>{200,200}</string>
</dict>
</dict>
<key>metadata</key>
<dict>
<key>format</key>
<integer>2</integer>
<key>realTextureFileName</key>
<string>loading.png</string>
<key>size</key>
<string>{512,512}</string>
<key>smartupdate</key>
<string>$TexturePacker:SmartUpdate:0e9839b17b099fb41aef47a1984b0b09$</string>
<key>textureFileName</key>
<string>loading.png</string>
</dict>
</dict>
</plist>
loading.plist
loading.png
用TexturePackerGUI工具生成的