Ignoring the touches on transparent areas of a sprite

Ignoring the touches on transparent areas of a sprite
0.0 0


In my app there is a background image of 480x800. Then I have a play button which when i place on the center of the screen it is positioned correctly. The size of the play button is also 480x800 although the button itself is small and the area around it is transparent.
How can I detect if the user has click on the play button itself and not the background?
Example using a code would be highly appreciated.

Thank you.


You could check where the touch is, and return false on ccTouchBegan if it isn’t in the right coordinates.
But I wouldn’t recommend that, is there a specific reason why the button has to be bigger than what the clickable area is going to be?
In other words, why not crop the button?


Even if i crop the button, there is still few area around the image which is transparent and I dont want the button function called if that transparent area is touched.
I found this solution but I dont understand it. Its for iphone but I want it for android : http://stackoverflow.com/questions/10889170/cocos2d-2-0-ignoring-touches-to-transparent-areas-of-layers-sprites



It was discussed early in: http://cocos2d-x.org/boards/6/topics/19694?r=20060#message-20060
That solution is work.