My game has a lot of sprite sheets that I need to use all in one level and because of the memory requirements I can’t load them all at once. My thought process was maybe I could load a sprite sheet right when it was needed (on the fly). So if I have a walking sprite sheet and someone presses the jump button I could load the jump sprite sheet and unload the walking sprite sheet at that exact moment so that no new memory is used.
This idea seems to work but when I run it on an iOS 4 or an Andriod 2.2 device I can see about a 1 second delay from the sprite sheet being loaded to being displayed. Is this because of the time it takes to load the sprite sheet image from the devices file system? Is this because I am loading the sprite sheet while the game is running? Perhaps I am doing something wrong in code? Am I just S.O.L.?
Please help! Here is the code.
require "sprite"
display.setStatusBar(display.HiddenStatusBar)
local idleSheet = sprite.newSpriteSheetFromData( "Idle@2x.png", require("Idle@2x").getSpriteSheetData() )
local spriteSet = sprite.newSpriteSet(idleSheet, 1, 15)
sprite.add(spriteSet,"Idle",1,15,500,0)
local spriteInstance = sprite.newSprite(spriteSet)
spriteInstance:setReferencePoint(display.BottomCenterReferencePoint)
spriteInstance.x = 175
spriteInstance.y = 350
spriteInstance:prepare("Idle")
spriteInstance:play()
local function onTap( event )
idleSheet:dispose()
idleSheet = nil
local walkSheet = sprite.newSpriteSheetFromData( "Walk@2x.png", require("Walk@2x").getSpriteSheetData() )
local spriteSet2 = sprite.newSpriteSet(walkSheet, 1, 13)
sprite.add(spriteSet2,"Walk",1,13,300,0)
spriteInstance = sprite.newSprite(spriteSet2)
spriteInstance:setReferencePoint(display.BottomCenterReferencePoint)
spriteInstance.x = 175
spriteInstance.y = 350
spriteInstance:prepare("Walk")
spriteInstance:play()
end
spriteInstance:addEventListener ( "tap", onTap )
Thanks
ML [import]uid: 63352 topic_id: 14337 reply_id: 314337[/import]