您的位置:首页 > 其它

纹理及其异步加载

2015-06-22 21:01 281 查看
<1>

--单例
winSize = cc.Director:getInstance():getWinSize()
frameCacheInstance = cc.SpriteFrameCache:getInstance()
textureCacheInstance = cc.Director:getInstance():getTextureCache()
defaultInstance = cc.UserDefault:getInstance()
schedulerInstance = cc.Director:getInstance():getScheduler()
function LoadingScene:createLayer()
local layer = cc.Layer:create()
frameCacheInstance:addSpriteFrames("texture/loading_texture.plist", "texture/loading_texture.png")

--背景
local bg = cc.TMXTiledMap:create("map/red_bg.tmx")
layer:addChild(bg)

--logo
local logo = cc.Sprite:createWithSpriteFrameName("logo.png")
logo:setPosition(cc.p(winSize.width/2, winSize.height/2))
layer:addChild(logo)

--
local sp = cc.Sprite:createWithSpriteFrameName("loding4.png")
local x, y = logo:getPosition()
sp:setPosition(cc.p(x, y - 130))
layer:addChild(sp)
--
local animation = cc.Animation:create()
for i = 1, 4 do
local framename = string.format("loding%d.png", i)
local spFrame = frameCacheInstance:getSpriteFrame(framename)
animation:addSpriteFrame(spFrame)
end

animation:setDelayPerUnit(0.5)
animation:setRestoreOriginalFrame(true)

local animate = cc.Animate:create(animation)
sp:runAction(cc.RepeatForever:create(animate))

local function loadingTextureCallBack(texture)
frameCacheInstance:addSpriteFrames("hd/texture/LostRoutes_Texture.plist", "hd/texture/LostRoutes_Texture.png")

local homeScene = require("HomeScene").create()
cc.Director:getInstance():replaceScene(cc.TransitionFade:create(2.0, homeScene))

end

textureCacheInstance:addImageAsync(texture_res, loadingTextureCallBack)

return layer
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: