Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Show / Hide Overlay Bug (Duplicate Execution Demands)
Started by AngelaMcCall Nov 23 2019 04:28 AM

2 replies to this topic

Best Answer AngelaMcCall , 26 November 2019 - 01:59 AM

I solved it.

I litterally deconstructed my scene to find the cause.

I have two buttons that are visually different, a close backpack and then an open backpack.

They are sized identically, so when clicked on, it looks like the same button.

The closed btn lives in the parent scene,

the open btn in the overlay scene.

Although i "thought" i was hiding the closed back pack button on the parent scene, I was not properly doing so, it was still hitable.

So when the overlay open backpack was positioned, it layed ontop and the click to close was invoking BOTH actions.

As in clicking through to parent scene btn at same time.

 

Problem, was solved, by moving the parent button into a idfferent group, that I hide to prevent click through from the overlay on objects I don't want to be clickable when the overlay is present.

 

Thanks

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 33 posts
  • Corona SDK

Hi all,

 

Inside my normal game play scenes, and overlay scenes, I've a small line of code, that writes to the composer, when that scenes event code is executed, this is because I'm trying to debug a problem.

 

When the player clicks on their btnBackPack, my OL1 (Overlay 1 Inventory) lua file is displayed.

EVERYTHING is fine upto this point (coloured green)

12:05:56.132  GP1 SHOW EVENT DID
12:05:58.204  OL1 ============================
12:05:58.204  OL1 SCENE FILE LEVEL
12:05:58.204  OL1 CREATE EVENT
12:05:58.215  OL1 SHOW EVENT WILL
12:05:58.215  OL1 SHOW EVENT DID

But...

When the player closes clicks on the btnBackPackClose to close the OL1 (Overlay 1 Inventory) lua file, for some reason things go wrong. the close process is calling the overlays SHOW event again (coloured red)!

12:05:59.616  OL1 HIDE EVENT WILL
12:05:59.616  OL1 SHOW EVENT WILL
12:05:59.616  OL1 SHOW EVENT DID
12:06:00.124  OL1 HIDE EVENT DID
12:06:00.124  OL1 DESTROY EVENT
12:06:00.124  OL1 -------------------------

As you can see, the next scene event called is the OL1 HIDE EVENT WILL. 

This is correct and expected.

 

But then the overlay's SHOW WILL, and SHOW DID events are called AGAIN.

I've now commented out every single object created, function written leaving just the button to close the overlay remaining. There is nothing in my code, calling the SHOW WILL/DID events again.
If the entire overlay file was being called, then it's HIDE EVENTS would show twice, but they do not.

There are no events taking place from the parent scene.

 

I've read over and over all the scene management, composer notes/tutorials etc I can find on the subject.

This double/secondary SHOW event execution in my overlay is screwing my management of parent scene objects.

Thanks

Angela



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,393 posts
  • Enterprise

This frequently happens when you have a button with a touch listener (or using the onEvent handler for widget.newButton). Touch handlers or the onEvent handler has multiple phases to detect when the button was touched and when it was released. You have to check the event.phase value and only call composer.gotoScene in one of the phases. 

 

There could be other causes, but if you're doing something like this:

local function playGame(event)
    composer.gotoScene("somescene")
    return true
end

widget.newButton({
    ...
    onEvent=playGame,
    ...
})

will cause composer.gotoScene() to be called twice. Instead either:

local function playGame(event)
    composer.gotoScene("somescene")
    return true
end

widget.newButton({
    ...
    onPress=playGame,
    ...
})

or

local function playGame(event)
    if event.phase == "began" then
        composer.gotoScene("somescene")
    end
    return true
end

widget.newButton({
    ...
    onEvent=playGame,
    ...
})

Rob



[TOPIC: post.html]
#3

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 33 posts
  • Corona SDK

  Best Answer

I solved it.

I litterally deconstructed my scene to find the cause.

I have two buttons that are visually different, a close backpack and then an open backpack.

They are sized identically, so when clicked on, it looks like the same button.

The closed btn lives in the parent scene,

the open btn in the overlay scene.

Although i "thought" i was hiding the closed back pack button on the parent scene, I was not properly doing so, it was still hitable.

So when the overlay open backpack was positioned, it layed ontop and the click to close was invoking BOTH actions.

As in clicking through to parent scene btn at same time.

 

Problem, was solved, by moving the parent button into a idfferent group, that I hide to prevent click through from the overlay on objects I don't want to be clickable when the overlay is present.

 

Thanks




[topic_controls]
[/topic_controls]