Easy way to detect touch/click events on my sprite?

I’m quite new to game development and I used to work with Apples SpriteKit framework. With SpriteKit it was quite easy to detect if a certain object in my game was touched or clicked. So in my game I want to detect if my sprite, that serves as control element, is being clicked or touched. Is there an easy way to detect that or do I need to do the math by myself?

Are they in gui or game objects?

Here is a example by @britzl for click on game object

If it is in the gui then this tutorial may help you

4 Likes

Thank you. They are in game objects. Does that example on Github work for non-square sprites such as circles as well?

If you click on the alpha it will register as a click on the sprite.

If you have complex shapes maybe doing it with physics and collisions is better

3 Likes

This is an excellent suggestion and it works really well. I used this approach for my physics based linker/switcher example. Have a small collision object follow the mouse/touch position and have collision shapes set up on your game objects to detect when the mouse/touch object collides with it.

2 Likes