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?
Comments
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
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
Fragmenter - animated loop machine and IKONOMIKON - the memory game