I want to click on the particular sprite from the sprite sheet. For instance i have fruits sprite sheet i want to click on the particular fruit.
Thanks, Jubin Mehta
A general solution would be:
Transform the position into the tiles local coordinate space.
pixelPositionX = cursorPositionX - (tilePositionInWorldX - screenPositionX)
pixelPositionY = cursorPositionY - (tilePositionInWorldY - screenPositionY)
Find out if the position is inside the tile.
tilePositionOnSpritesheetX < pixelpositionX < tilePositionOnSpritesheetX + tileSizeX
tilePositionOnSpritesheetY < pixelpositionY < tilePositionOnSpritesheetY + tileSizeY
If it is, check if the alpha value of the pixel at that position is over a certain treshold.
Step 4 is optional, without it, you're checking against the tiles bounding rectangle, with it, clicking is pixel perfect.
Please note that all positions and sizes are assumed to be in pixels.