Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Why does game chaeck all buttons when last button is clicked? — Gideros Forum

Why does game chaeck all buttons when last button is clicked?

I am basically following ar2rsawseen's book, "Gideros Mobile Game Development".

I have attached two screenshots with the code I'm having a problem with. The first is the file for my button class. The seconde is a part of the code from my "play" scene. This screenshot shows the code for 2 "choice" buttons, buttons the player clicks on for what he thinks is the correct answer. There are actually 4 buttons, but I could onlt fit 2 in the screeshot. The other two are identical except for the numbers in the names.

A note: In this iteration, I just have the function called by each button change the scene of the game to a different secene. Each button goes to a different scene. I'm only doing this to test the buttons and the functionality will eventually be quite different.

At first glance, it seems to work fine. Each time I run it, when I click one of the buttons, the game changes to the correct new scene.

If I didn't have the print statment in line 13 of the button class file, I wouldn't know there's a problem. In the 2ns screenshot, if you look at the output in the console, you'll see that it returen false 3 times for the self:hitTestPoint(event.x, event.y) variable before it returns true. Actually, this is the result if the 4th button is clicked. What actually happens, is that when you click a button, it seems to check the self:hitTestPoint(event.x, event.y) for all of the buttons above it, it returns false for those buttons and then returns true for the button clicked.

Why does it do this and is it a problem I need to fix?imageimage
buttonClass.PNG
864 x 341 - 21K
choiceButtons.PNG
1165 x 607 - 58K

Comments

  • olegoleg Member
    edited January 2018
    if self:hitTestPoint(event.touch.x, event.touch.y) then
     
                   print(self:hitTestPoint())
     
    		event:stopPropagation()
    	end
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • rpallenrpallen Member
    edited January 2018
    Thanks, Oleg, but I still don't understand why the code I used appears to be checking the buttons before the button I actually clicked.
  • hgy29hgy29 Maintainer
    Accepted Answer
    @rpallen,
    When you listen to Mouse events, those events are dispatched to your listener no matter they occurred in the sprite you attached the listener to. You could as well have attached to them to the stage. It only matters if you ever stopPropagation(), because inner sprites receive events first.

    That’s why you need to hitTestPoint() to be sure that the event occurred on the sprite you are checking.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    Accepted Answer
    So basically every object you add an event listener to.. receives that event when it occurs :)
  • Thanks for the explanations, hgy29 and antix.
  • well, not every sprite receives it as if there is a stoppropagation, then sprites below in the stage hierarchy wont get this event.
Sign In or Register to comment.