Accessing a display object in original scene from an overlay and changing fill of that object?

Greetings,

Without going into too much detail, I have a scene with an overlay.  I know how to pass variables as parameters from scene to the overlay.

But say if I have a display object in the scene, and when I’m in the overlay, I want to change the fill of the display object in the scene FROM the overlay…

This possible?

Thanks,

Seth

pass a reference to the object to the overlay via params

https://docs.coronalabs.com/daily/api/library/composer/showOverlay.html#params-optional

Download this file:

http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

Look at example 11, which does this:

https://www.youtube.com/watch?v=7dn9_CjoGbM&feature=youtu.be

hey @roaminggamer

Thanks for helping…

I am using that method for passing variables (scores) through the parameters to be accessed in the overlay… but how do I change a display.object that is in the parent scene from the Overlay.

In the original scene, I have lets say - a display object called ‘ball’.  Then another variable called ‘myScore’ which is self explanatory.

I can access myScore in the Overlay by passing the sampleVar parameter:

local options = { isModal = true, effect = "fade", time = 400, params = { sampleVar = myScore } } composer.showOverlay( "pause", options )

In overlay, something like this to access the ‘myScore’ variable in the overlay:

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent --reference to the parent scene object local score = parent.params.sampleVar end

So in this example, score would be the same as ‘myScore’ in the original scene (there maybe some code discrepencies I’m not at my code-computer.

Anyways - so my question is , while in the Overlay - how do I change fill color of the ball object?  I’m probably missing something very obvious :wink:

Appreciate your input!

EDIT - Just saw your more recent post video , I’ll see if that answers it, thanks again

provided answer while you were typing, please look above.

That’s exactly what I wanted in video, it’s even a ball  :lol:  I’ll download that project later and dissect it.

Thanks @roaminggamer!

In addition to what @roaminggamer said, there are two other ways you might want to consider:

composer.setVariable( key, value )

value = composer.getVariable( key )

These will store data in the composer object itself. This is one way to share values in between scenes.

The other method involves the overlay scene’s ability to access it’s parent. In the four scene events functions, they receive a table that we call event. One of the members of that able is event.parent. This is the parent scene’s scene object.

In your parent scene you can do:

local myObjectToFill = -- whatever you need to do setup your display object function scene.fillObject( red, green, blue, alpha )       myObjectToFill:setFillColor( red, green, blue, alpha ) end

Then in your overlay scene:

local parentScene = nil ... -- somewhere later in your code parentScene.setFillColor( 0.5, 0.2, 0.9 ) ... function scene:create( event )       local sceneGroup = self.view       parentScene = event.parent ... end

You have a lot of flexibility in this area.

Rob

Thanks @Rob Miracle

All this helps a lot.

pass a reference to the object to the overlay via params

https://docs.coronalabs.com/daily/api/library/composer/showOverlay.html#params-optional

Download this file:

http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

Look at example 11, which does this:

https://www.youtube.com/watch?v=7dn9_CjoGbM&feature=youtu.be

hey @roaminggamer

Thanks for helping…

I am using that method for passing variables (scores) through the parameters to be accessed in the overlay… but how do I change a display.object that is in the parent scene from the Overlay.

In the original scene, I have lets say - a display object called ‘ball’.  Then another variable called ‘myScore’ which is self explanatory.

I can access myScore in the Overlay by passing the sampleVar parameter:

local options = { isModal = true, effect = "fade", time = 400, params = { sampleVar = myScore } } composer.showOverlay( "pause", options )

In overlay, something like this to access the ‘myScore’ variable in the overlay:

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent --reference to the parent scene object local score = parent.params.sampleVar end

So in this example, score would be the same as ‘myScore’ in the original scene (there maybe some code discrepencies I’m not at my code-computer.

Anyways - so my question is , while in the Overlay - how do I change fill color of the ball object?  I’m probably missing something very obvious :wink:

Appreciate your input!

EDIT - Just saw your more recent post video , I’ll see if that answers it, thanks again

provided answer while you were typing, please look above.

That’s exactly what I wanted in video, it’s even a ball  :lol:  I’ll download that project later and dissect it.

Thanks @roaminggamer!

In addition to what @roaminggamer said, there are two other ways you might want to consider:

composer.setVariable( key, value )

value = composer.getVariable( key )

These will store data in the composer object itself. This is one way to share values in between scenes.

The other method involves the overlay scene’s ability to access it’s parent. In the four scene events functions, they receive a table that we call event. One of the members of that able is event.parent. This is the parent scene’s scene object.

In your parent scene you can do:

local myObjectToFill = -- whatever you need to do setup your display object function scene.fillObject( red, green, blue, alpha )       myObjectToFill:setFillColor( red, green, blue, alpha ) end

Then in your overlay scene:

local parentScene = nil ... -- somewhere later in your code parentScene.setFillColor( 0.5, 0.2, 0.9 ) ... function scene:create( event )       local sceneGroup = self.view       parentScene = event.parent ... end

You have a lot of flexibility in this area.

Rob

Thanks @Rob Miracle

All this helps a lot.