Hi everybody,
I try to use the great Ricardo class, but I must admit I don't understand the :insert() thing.
Assuming I have sample code (a former main.lua) that I want to put in a scene (exactly like the demo does with screen1 and screen2.lua) :
Mainly it's said that I have to put my code here :
1 2 3 4 5 6 7 8 9 10 11 | module(..., package.seeall) -- Main function - MUST return a display.newGroup() function new() local localGroup = display.newGroup() ------ Your code here ------ -- MUST return a display.newGroup() return localGroup end |
I realize I'm not that clear.
I see ricardo video saying insert should be done for all display objects.
But I'm still worried about eventlisteners : director class auto cleans every listeners when changing scenes ?
@Antheor
The localGroup is needed to clean display objects from the screen. After that, Director try to unload the file from execution.
Let's talk about the modules.
When you want to use an outside module to store functions and variables, you have to use this command:
1 | local myPackage = require("myPackage") |
Thx for your answer.
I mus admit the use of modules to store functions and variables is obscure to me (I'll dig into it later).
Concerning listeners, I suppose you're talking only about runtime listeners.
In your code example screen 2 :
1 2 3 4 5 6 7 | -- Touch to go back local function touched ( event ) if event.phase == "ended" then director:changeScene("screen1","fade") end end background:addEventListener("touch",touched) |
@Antheor
Yes, I was talking about the Runtime Listeners only. Director goes through every object inserted into the localGroup and calls the removeSelf function. This function removes the image and the listeners.
As the Runtime listeners aren't associated to a display object, Director can't find them to remove.
One more thing : if I add, at the beginning, a lib like :
1 2 3 4 5 6 7 8 | module(..., package.seeall) -- Main function - MUST return a display.newGroup() function new() local localGroup = display.newGroup() ------ Your code here ------ local Particles = require("lib_particle_candy") |
@Antheor
I always put my require functions at the beginning so I can use them wherever I want.
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Accelerometer Acceleration Speed? How do you change speed?
iFly is out now!
MysticGlyph a Monument of Mystery Wrapped in a Riddle
Why doesn't Dynamic Image Resolution work on the device.
I was featured in the First Developer Spotlight at AppUnderdogs (I talk about Corona too!)
Audio channel volume troubles - help!
Image Ninja - Promo Codes
Get Rid of Bouncing
how to input multiline text