Bug: UI Buttons + Director's Class

Hi,

so I just stumbled upon a problem when using director’s class along with the UI-class. Here it is:
I’ve got an object that the user controls with the accelerometer. This object collides with other objects. Some of them make the game change scene to gameover.lua, some don’t.

In the same scene I’ve got a pause button. Now, when I click and hold the pause button, and at the same time collide with a gameover object, director’s class will change the scene, but everything will freeze afterwards. The pause button is gone, but the new buttons I’ve got in this new scene don’t work?

Can someone confirm that this is a bug? Or is there a chance I’m doing something wrong?

Thanks in advance, [import]uid: 14018 topic_id: 7454 reply_id: 307454[/import]

Are you managing your listeners correctly ? [import]uid: 6981 topic_id: 7454 reply_id: 26427[/import]

I guess so… They are working perfectly when not switching scenes [import]uid: 14018 topic_id: 7454 reply_id: 26462[/import]

I’m thinking removing the listener for the pause button before switching scenes should solve this? But using the UI-class, how do you go about doing this? Since I’m assuming the listener is within the ui.lua file that I include at the top of my code?

Thanks, [import]uid: 14018 topic_id: 7454 reply_id: 26501[/import]

what about stopping the object from moving when you press pause? or removing the accelerometer event while your game is paused… [import]uid: 7849 topic_id: 7454 reply_id: 26627[/import]

UI.lua does not include the ability to remove listeners so if you switch screens and remove the buttons, the listeners are still there. This may be the reason the new buttons don’t work. [import]uid: 7559 topic_id: 7454 reply_id: 26640[/import]

Yeah I’m guessing that’s what’s causing this issue but I can’t find a solution to this anywhere. Is it even possible to fix it? [import]uid: 14018 topic_id: 7454 reply_id: 26656[/import]

Yup, use a different button library.

I made one because of this issue.

My site is down at the moment but i can upload it to a filesharing site if you want to try it [import]uid: 6981 topic_id: 7454 reply_id: 26722[/import]

Sure! But does it work the same way or do I have to modify my code? Because I’ve got aaaaa lot of buttons… [import]uid: 14018 topic_id: 7454 reply_id: 26755[/import]

@NahirC, I believe you can remove the Listeners yourself before switching screens. You need to do the following for each active button that was created with the UI library.

youButton:removeEventListener( "touch", yourButton )  

Just substitute your button name for “yourButton” in both places. [import]uid: 7559 topic_id: 7454 reply_id: 26757[/import]

It’s still not working… I get the same issue…

Edit: Can there be a problem with holding down the button then removing the eventlistener also? [import]uid: 14018 topic_id: 7454 reply_id: 26759[/import]

You should only remove the button listeners on the button “release” event.

Holding down the button sets the focus (setFocus) on the button which needs to be released before the focus can go to any other object (e.g. other buttons). The focus is removed when the button is released. [import]uid: 7559 topic_id: 7454 reply_id: 26772[/import]

If I can’t remove the listener while holding down the button, it wont help my situation? :confused: So I guess I’ve got to add a line of code making the button reach the release.event without the user actually letting go of the button before I switch scenes? I thought about this before but have no clue how to do it [import]uid: 14018 topic_id: 7454 reply_id: 26828[/import]

I hope it’s not too late to help you. I had the same problem and that worked out for me:

display.getCurrentStage():setFocus(nil)

I hope it works out for you too! [import]uid: 5330 topic_id: 7454 reply_id: 39347[/import]