Here is the backstory.
I was using the old method of sprite sheets in StoryBoard.
And in order to dispose of a sprite sheet, it was simple as:
myspriteSheet:dispose()
This released the sprite sheet from textured memory and everything was fine: (thanks to Peach Pellen) here:
Now that I have converted to the (new api), I am getting the following message when trying to dispose of my sheets.
In new API this:
myspriteSheet:dispose()
Results this error:
attempt to index up value ‘babyduckSheet’ <a userdata value>
Below is a “basic” block flow of what I am doing now, and in the “exit scene” is where I have the dispose.
Now…I did find this in the forums:
The post suggests to do this now:
babyduck:removeSelf()
babyduck = nil
babyduckSheet = nil
Which seems to resolve my sprite sheets being removed now from textured memory but I thought I would ask if I am doing something wrong with the new API or if there is a better way than using Garbage Collector to clean up spritesheets in the new API?
Thank you for your time.
[lua]local babyduckData,babyduckSheet,babyduckSeqData,babyduck,babyduckTouch
– Called when the scene’s view does not exist:
function scene:createScene( event )
local screenGroup = self.view
–setup SpriteSheet new API method
babyduckData = { width=220, height=197, numFrames=3, sheetContentWidth=660, sheetContentHeight=197 }
babyduckSheet = graphics.newImageSheet( “assets/page07/page07-babyduck-sprite.png”, babyduckData )
babyduckSeqData = {{ name = “babyduckPlay”, frames = {1,2,3,1}, time=2000, loopCount = 1 }}
babyduck = display.newSprite( babyduckSheet, babyduckSeqData )
babyduck.x = display.contentWidth/2+130
babyduck.y = display.contentHeight/2+150
babyduck:setSequence( “babyduckPlay” )
babyduck.touch = babyduckTouch
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
–stop animations
babyduck:pause()
–remove sprite sheets
babyduckSheet:dispose()
end
[/lua]