It looks like you're new here. If you want to get involved, click one of these buttons!
local ghosts = {} plusButton:addEventListener( "click", function() for i = #ghosts + 1, #ghosts + 100 do local ghost = AnimSprite.new( "Images/blowfish.png", screenW, screenH ) ghost:setAlpha( 0.0 ) -- invisible sprite -> a ghost stage:addChild( ghost ) ghosts[i] = ghost end print( "*** Ghosts: " .. #ghosts ) end ) minusButton:addEventListener( "click", function() if #ghosts > 0 then for i = #ghosts - 99, #ghosts do stage:removeChild( ghosts[i] ) ghosts[i] = nil end print( "*** Ghosts: " .. #ghosts ) end end ) |
Comments
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Am waiting for a solution. Sigh...
Do you see two events being triggered? I think what's happening is that when you tap, both of the functions get triggered and there is a strong possibility that the remove gets called and then creates the 100 ghosts.
sigh...
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
in gideros mouse and touch event actuate 1 function
I check the Code and the fps decrease by adding ghosts and increase by removing them.
I am unaware that Gideros does not allow automatic garbage collector to do the job. But, it is a good news for game development.
In my case, i do collectgarbage("count"), and check if it more than a certain amount (20000 for me), and then do collect garbage only on an event when the user won't be bothered by it.
You would also need to do it on every scene change, for better result.
http://lua-users.org/wiki/GarbageCollectionTutorial
Because well, collecting it on each frame or loop, maybe too inefficient