Handling Mouse Clicks on Objects

Hey, me again.

I’ve started working on Risk, it’s due in about a week so I thought I’d better get started until I realized that I don’t know how to handle mouse inputs. I understand how the bindings work and I can write a bit of code that can check whether the mouse x and y are within a certain box, but due to the game I’m going to need something a little more complex than that. Countries aren’t perfect squares or spheres, I need a way to handle clicks that’s pixel perfect.

I did do some research and found out that there’s a pretty good click handler when designing GUIs, that could possibly work. Considering I don’t need anything to move and I don’t need any kind of physics I could try to write the whole thing as a GUI, all the input is mouse input so it might work. Not exactly sure how to use GUIs with sprites but I could figure that out, what I need to know is if the click handler is pixel perfect according to the sprite.

I also found something about using the physics engine and if I attach a collision object to the mouse then I could do some sort of collision detection on the mouse click with objects, the problem with this is that (as far as I know), the only collision objects I can use are squares and spheres, is there a way to make a more advanced collision object that wraps around the pixels?

Thanks for your help :slight_smile:

Hi @DatCodingGuy!
Maybe you could try using a collision object “attached” to the mouse point coordinates, and for the countries have a custom collision shape? There is support for it, but it might not be well documented, but have a look at this old post: Does defold support only three shapes for collision? (SOLVED)