We alway rectangular sprite notion everywhere.
See the below image. Assume it is my mobile screen having cocos2d0x green layer covering the screen. Now, I add a sprite, which is not rectangular but any shape.
How to see whether my touch is in white area!!
I cannot do sprite->getBoundingBox().containsPoint() because the by notion sprite are always rectangular even though its texture may not be rectangle.
Wait for 4.0 to arrive with its planned mesh/polygon sprite … just kidding. Unfortunately I don’t believe there’s an out-of-box solution at hand just yet, though using the physics system would be close.
You could add invisible touch nodes.
You could use the physics engine and give the sprite a polygonal physics body
You can look into pixel-perfect collision detection using either render textures or storing the image data in a regular byte[][] array.
Other?
To start I would focus on simplicity, by either using a scaled down rect based off its boundingbox (say add 1/4 width and height to the rect.origin and multiply size by .5f), or maybe #1 or #2 if you’re using physics engine. You can always attach your own polygon or shape and do your own touch inside point detection.
If you go the physics route it’s probably easier to just look at the code in cpp-tests/Classes/PhysicsTest/PhysicsTest.cpp for example. Look at the code for touch handling. PhysicsDemo::onTouchBegan/Moved/Ended. They set a tag on draggable (touchable) physics bodies and then detect touches on them if the tag is set.
Otherwise @Javy has a good code to use if you setup your CustomSprite : public cocos2d::Sprite with an extra boundingPolygon. You’ll have to define the polygon points somewhere using PhysicsDesigner, or in code. This way you could also first test the boundingBox if you want as a first “pass” and then check intersection with polygon after.