First, you're only checking for touch DOWN, you also need to check for touch INSIDE. currently, that button will be triggered from anywhere on the screen.
Secondly, even if you add the condition for touching INSIDE, Even though you have two separate rules for capturing touches, they are both fired all the time. So one is setting it to 1 and the other one set it immediately back to 0. causing it to flicker.
I make toggle buttons like this:
Create two attributes in the toggle button: myCurrentState(integer) buttonIsBeingPressed(boolean)
Rule ALL When Mouse is DOWN When Mouse is INSIDE When buttonIsBeingPressed is FALSE Change Attribute: buttonIsBeingPressed to TRUE Change Attribute: myCurrentState to (myCurrentState+1)%2
Rule When myCurrentState = 0 Change Attribute: gameSoundsOnOff to 1 Change Image: SoundsOFF.png
Rule When myCurrentState = 1 Change Attribute: gameSoundsOnOff to 0 Change Image: SoundsON.png
Rule When Mouse is UP Change Attribute: buttonIsBeingPressed to FALSE
Comments
I was working on the setting page and testing with a text actor to see if it change the attribute and the image, but it does nothing.
First, you're only checking for touch DOWN, you also need to check for touch INSIDE. currently, that button will be triggered from anywhere on the screen.
Secondly, even if you add the condition for touching INSIDE,
Even though you have two separate rules for capturing touches, they are both fired all the time.
So one is setting it to 1 and the other one set it immediately back to 0. causing it to flicker.
I make toggle buttons like this:
Create two attributes in the toggle button:
myCurrentState(integer)
buttonIsBeingPressed(boolean)
Rule
ALL
When Mouse is DOWN
When Mouse is INSIDE
When buttonIsBeingPressed is FALSE
Change Attribute: buttonIsBeingPressed to TRUE
Change Attribute: myCurrentState to (myCurrentState+1)%2
Rule
When myCurrentState = 0
Change Attribute: gameSoundsOnOff to 1
Change Image: SoundsOFF.png
Rule
When myCurrentState = 1
Change Attribute: gameSoundsOnOff to 0
Change Image: SoundsON.png
Rule
When Mouse is UP
Change Attribute: buttonIsBeingPressed to FALSE
Hope this helps!
Joe
I didn't thought you needed so many rules for a simple button