Thanks Ron and Brent for the replies.
I checked that line Rob posted after each chunk that I load images and I can see that problem lies with those big images, each of those calls takes about 53MB of Texture Memory ™.
I do use ImageRect and specify multiple resolution with @ identifier. ( I just do @2x for now but will do the @4x for Retina devices as well).
Each of those big objects are in fact 3 image sheets that I load and turn them visible and invisible with “isVisible” flag, due to different gameplay circumstances.
Here is the section I load them:
function M.new(monsterType, xPos, yPos) -- Creating monsters local newMonster = display.newGroup() local sheetData = { width = 105, height = 430, numFrames = 9, -- The params below are optional; used for dynamic resolution support sheetContentWidth = 945, -- width of original 1x size of entire sheet sheetContentHeight = 430 -- height of original 1x size of entire sheet } local animationSequenceData = { { name = "idle", frames = { 1, 2, 3, 3 }, time = 1000, loopCount = 0 }, -- { name = "chew", frames = { 4, 5, 6, 7, 8, 8 }, time = 400, loopCount = 1 }, -- { name = "chew", frames = { 4, 7, 8, 8 }, time = 200, loopCount = 1 }, -- { name = "chew", frames = { 4, 6, 8, 8 }, time = 200, loopCount = 1 }, { name = "chew", frames = { 8, 9, 8, 9, 8, 8 }, time = 500, loopCount = 1 }, -- { name = "chew", frames = { 8, 8 }, time = 200, loopCount = 1 }, } if "Purple" == monsterType then local mySheet --============================== Phase 1 ============================== -- -- phase1:Sprite mySheet = graphics.newImageSheet("monster\_purple\_phase\_1.png", sheetData ); newMonster.phase1 = display.newSprite(mySheet, animationSequenceData) newMonster:insert(newMonster.phase1) -- Adding body part to the display group. -- phase1:Offset newMonster.phase1:setReferencePoint(display.TopLeftReferencePoint) newMonster.phase1.x = newMonster.x newMonster.phase1.y = newMonster.y -- phase1:Animation newMonster.phase1:setSequence( "idle" ) newMonster.phase1:play() --============================== Phase 2 ============================== -- -- phase2:Sprite mySheet = graphics.newImageSheet("monster\_purple\_phase\_2.png", sheetData ); newMonster.phase2 = display.newSprite(mySheet, animationSequenceData) newMonster:insert(newMonster.phase2) -- Adding body part to the display group. -- phase2:Offset newMonster.phase2:setReferencePoint(display.TopLeftReferencePoint) newMonster.phase2.x = newMonster.x newMonster.phase2.y = newMonster.y -- Making it invisible since we play phase 1 by default newMonster.phase2:setSequence( "idle" ) newMonster.phase2:play() -- newMonster.phase2.isVisible = false --============================== Phase 3 ============================== -- -- phase3:Sprite mySheet = graphics.newImageSheet("monster\_purple\_phase\_3.png", sheetData ); newMonster.phase3 = display.newSprite(mySheet, animationSequenceData) newMonster:insert(newMonster.phase3) -- Adding body part to the display group. -- phase1:Offset newMonster.phase3:setReferencePoint(display.TopLeftReferencePoint) newMonster.phase3.x = newMonster.x newMonster.phase3.y = newMonster.y -- Making it invisible since we play phase 1 by default newMonster.phase3:setSequence( "idle" ) newMonster.phase3:play() -- newMonster.phase3.isVisible = false
Please note that I’m showing 1x version here but that 53MB memory I mentioned earlier was from Corona simulator running the game for iPhone 4.
So my imagesheet is 945x430 in 1x and 1850x860 in 2x which I believe will take the 2048x2048 texture. (I’m not sure if it’s the case for iPod touch 4G as well, please correct me if I’m wrong.)
I can’t calculate precisely how much memory it will take but I think 2048*2048*4 which is about 16MB and since I load three of them for each monster, that is about that 53MB I reported.
So that’s the problem?
On the side note, I have another question as well, if this code is this bad, why iOS 6 won’t close my game and iOS 5 does?