0

In all the examples of games, which I examined, written in C++/C# using SFML, .NET Framework, WPF, Python and HTML5 a sprite reacts on mouseClick made within the sprite's bounding box.

Is there a technique in to make the sprite react to clicks made within the sprite image only?

I examined many games, but not a single one exhibit the necessary behaviour

1 Answer 1

3

The technique is as follows:

  1. Obtain the mouse click coordinates.
  2. Subtract the sprite coordinates, to obtain sprite-local offsets.
  3. Use the sprite-local offsets to look up the pixel in the sprite.
  4. If the pixel is transparent, then the click was not within the sprite image.
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, Mike! Excellent idea. I wish I thought of it myself!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.