Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
Hello, Im making a button that is supposed to toggle between frame 0 and frame 1 when it is clicked on/off. This can be easily solved by using a boolean. My issue is that I am going to have more that one button and I dont want to create a new boolean and a new button sprite for each one.
Here is a simple way to toggle between 0 and 1:
Sprite Set animation frame to (Self.AnimationFrame=0)
Yes that does work but its not what im trying to do.
it needs to turn on when it was previously off and turn off when it was on.
like when you click the button it will switch between on/off
My code does exactly that!
Mouse on clicked Button -> Button Set animation frame to (Self.AnimationFrame=0)
Develop games in your browser. Powerful, performant & highly capable.
No it doesn't, your code just sets it to frame 0. Which means that if it was on frame 0 and you clicked it, it would just stay on frame 0. Its supposed to go to frame 1. Also, the animation speed is set to 0. I think I understand what you are talking about though. You mean that it starts on frame 0, the animation plays and goes to frame 1, and when you click the button it will reset back to frame 0?
Set animation frame to Self.AnimationFrame = 0 ? 1 : 0
I think dops method also works. It resolves to 1 if the frame is 0 and vice versa
No it doesn't
No it doesn't
Why don't you just try it?
(b=0) will invert the value of b. If (b=0), the result will be 1, if (b=1), the result will be 0.
WackyToaster's method also works, but mine is four characters shorter :)
Whoops I misread what you had said, so when I went to test it earlier I made it wrong. It works great though, thanks.