Hey, I’ve created 2 buttons for my clicker game so I can change the color of the background from white to black and inversely. On PC they’re activated by the keys 1 and 2. How can I make them get activated by clicks/touch without adding to the counter when I click them (Currently the counter raises when I click on the background). The buttons are 2 sprites.
You have plenty of options, but I’d say that the best solution would be to convert from sprites to a gui for the buttons and use gui.pick_node() (see this example: https://www.defold.com/examples/gui/button/).
If you really want to keep them as sprites you need to find a way to detect a click on them. One way would be to acquire input focus and check action.pressed and action.x and action.y to determine if you’re approximately over one or the other. For more precise detection you could stick trigger collision objects on them and have a cursor collision object follow mouse/touch to detect collision (for more details, check and perhaps use this lib: https://github.com/britzl/defold-input)
Thats sooo useful, I have been using hitboxes and manually doing input in script. This is so useful, can’t wait to try this
Thanks, the buttons are working even better now