Best way to click sprite, and make it disappear (Whack-a-Mole Game)

Hello,
I am new to Defold and I am trying to make a Whack-a-Mole type game. The next step in my process is to create a script making is to that when the player clicks on a sprite, it disappears, and appears again at random intervals.
Your help is greatly appreciated
Please let me know if you need anymore details to best answer my question
Thank you in advanced!

So what you need is basically

  1. Add all your holes to a table.
  2. when you click a mole, (use this to check whether it is clicked or not), and delete it
  3. pass a message to increment the score
  4. Then initiate a timer.
  5. After timer delay is over, choose a random position .
  6. Spawn a mole at that position
  7. Initiate another timer
  8. If the player doen’t click it, delete it
  9. Pass Hud a message to decrement a life.
  10. Repeat
3 Likes

Thanks a ton, I really appreciate it. That sounds super complicated so I may come back here for some more guidance. I’m sure that I will be able to figure it out somehow though. Thanks again!

You can also use the GUI component to make a game like that.

It’s not much but here’s a very small example of how you could do it.

whackamole.zip (128.6 KB)

3 Likes

So would using a GUI component as the moles, be a better alternative then having the moles all be game objects?

It’s not necessarily better to use the GUI component but it’s a bit easier to detect clicks.

Here is another post on the same topic.


I, and many others, have made games entirely in GUI scenes. In many cases it can be easier with no direct draw back. That could go for this case too. The only thing that you could need that doesn’t work in GUI is physics.

To do this I would probably use the physics.
Add a physics body that is as big as your sprite to your sprites go.
Have a physics body that sets to your mouse/touch position when you click and sets off screen when you release.
Check if the “touch body” is touching a sprite body.

4 Likes

Thank you.
This was a well done and thorough explanation, I appreciate it!
I will take a look at some of the provided examples and see how I can utilize some of it in my game. Thanks again!

2 Likes