Button hiding while using composer API

Hello,

​I have problems in hiding buttons.

I am using composer API (composer.gotoScene( ​"scene_name")) for transitioning from one scene to another.

​I am finding difficulties in hiding the buttons of one scene when moving to another scene.

Plot: Suppose there are two scenes, scene1 and scene2. The scene1 has button1 at coordinates A(150,100) and scene2 has  button2 at coordinates B(150,200).

​Problem: When I am going to scene2( by pressing button1 on scene1), and if I press on scene2 at the position same as the coordinates of button1 on scene1 (i.e., A(150,100)), it executes the functionalities of button1 automatically.

I am using the widget.newButton for creating the buttons and have separate defaultFile and overFile for displaying the buttons…

It will be very kind if anyone can help me with this problem.

Thank you in advance.

Shivani 

Try to remove the scene1 in scene2:create(event) as

composer.removeScene(scene1)

Are you adding your display objects to the scene’s group?

Hi shivaniparikh13,

playBtn = widget.newButton{ label="Play Now", defaultFile="button.png", overFile="button-over.png", onRelease = onPlayBtnRelease -- event listener function } sceneGroup:insert( playBtn )

After inserting your button in the sceneGroup this problem will be gone.

Edit: defaultFile and overFile

Thank you for all your responses.

Hello heavy_machine,

The code seems to work fine but with the help of it, the button is not displayed on the screen. The button becomes invisible.

I want the button to be displayed and after we go to the next scree based on event handler, then I want the functionality of

sceneGroup : insert(object) for buttons available on any other screens, so that when I press anywhere in the screen, it doesn’t create any problems as stated above.  

Hi I uploaded a solution to your problem. If I understood everything right then this should work out for you.

main -> scene1 -> scene2 -> scene1 …

https://www.dropbox.com/s/3lihgz4vno7sh4q/ButtonDemo.zip?dl=0

Feel free to conctact me if you have any questions

Hello heavy_machine.

Thank you for the snippet. It helped a lot.

But encountered a new problem.

We even have a textfield in one of our scenes. 

​Plot: For example , I have a button1 in scene1 and a text_field  and also a back_button in scene2.

button1 leads to scene2 and back_button leads back to scane1.

​Problem 1: W​hen button1 is pressed, I come to scene2. Here I have the text_field for some input to be given. Now when I press back_button and go back to scene1 and again press button1(on scene1), it leads to scene2 but the text_field disappears.

Any solution will be of great help

​Problem 2:  ​Can we put functions to sceneGroup: insert()? If not, what can be its equivalent?

Thank you in advance.

For that you have to save your data somehow.

  1. If you just want to keep the text for this session you can persist it in composer like this

In scene2 event scene:hide you have to put the current text into.

composer.setVariable( "text\_key", yourtextfield.text )

Then when you come back to the scene you have to prefill you text again.

yourtextfield.text = composer.getVariable( "text\_key" )
  1. If you want to keep it after the app gets killed and restarted you have to persist it (sqlite, json, file, …) there are like a ton of ways you can do that.

Best Regards

Thanks a lot heavy_machine for all the help. The snippets were of great help. Thank you

shivani

Try to remove the scene1 in scene2:create(event) as

composer.removeScene(scene1)

Are you adding your display objects to the scene’s group?

Hi shivaniparikh13,

playBtn = widget.newButton{ label="Play Now", defaultFile="button.png", overFile="button-over.png", onRelease = onPlayBtnRelease -- event listener function } sceneGroup:insert( playBtn )

After inserting your button in the sceneGroup this problem will be gone.

Edit: defaultFile and overFile

Thank you for all your responses.

Hello heavy_machine,

The code seems to work fine but with the help of it, the button is not displayed on the screen. The button becomes invisible.

I want the button to be displayed and after we go to the next scree based on event handler, then I want the functionality of

sceneGroup : insert(object) for buttons available on any other screens, so that when I press anywhere in the screen, it doesn’t create any problems as stated above.  

Hi I uploaded a solution to your problem. If I understood everything right then this should work out for you.

main -> scene1 -> scene2 -> scene1 …

https://www.dropbox.com/s/3lihgz4vno7sh4q/ButtonDemo.zip?dl=0

Feel free to conctact me if you have any questions

Hello heavy_machine.

Thank you for the snippet. It helped a lot.

But encountered a new problem.

We even have a textfield in one of our scenes. 

​Plot: For example , I have a button1 in scene1 and a text_field  and also a back_button in scene2.

button1 leads to scene2 and back_button leads back to scane1.

​Problem 1: W​hen button1 is pressed, I come to scene2. Here I have the text_field for some input to be given. Now when I press back_button and go back to scene1 and again press button1(on scene1), it leads to scene2 but the text_field disappears.

Any solution will be of great help

​Problem 2:  ​Can we put functions to sceneGroup: insert()? If not, what can be its equivalent?

Thank you in advance.

For that you have to save your data somehow.

  1. If you just want to keep the text for this session you can persist it in composer like this

In scene2 event scene:hide you have to put the current text into.

composer.setVariable( "text\_key", yourtextfield.text )

Then when you come back to the scene you have to prefill you text again.

yourtextfield.text = composer.getVariable( "text\_key" )
  1. If you want to keep it after the app gets killed and restarted you have to persist it (sqlite, json, file, …) there are like a ton of ways you can do that.

Best Regards

Thanks a lot heavy_machine for all the help. The snippets were of great help. Thank you

shivani