Add several genie in the scene
[Cpp]
MSprite1 = CCSprite: create ("Sprite.png ");
MSprite1-> setPosition (ccp (150, mSize. height/2 ));
This-> addChild (mSprite1 );
MSprite2 = CCSprite: create ("Sprite.png ");
MSprite2-> setPosition (ccp (300, mSize. height/2 ));
This-> addChild (mSprite2 );
MSprite1 = CCSprite: create ("Sprite.png ");
MSprite1-> setPosition (ccp (150, mSize. height/2 ));
This-> addChild (mSprite1 );
MSprite2 = CCSprite: create ("Sprite.png ");
MSprite2-> setPosition (ccp (300, mSize. height/2 ));
This-> addChild (mSprite2 );
Determine whether the clicked point is within the sprite's own range, that is, whether the clicked genie is:
[Cpp]
Void TouchScene: ccTouchEnded (CCTouch * pTouch, CCEvent * pEvent)
{
CCPoint touchPoint = convertTouchToNodeSpace (pTouch );
If (mSprite1-> boundingBox (). containsPoint (touchPoint ))
{
CCMessageBox ("mSprite1 touched ","");
}
If (mSprite2-> boundingBox (). containsPoint (touchPoint ))
{
CCMessageBox ("mSprite2 touched ","");
}
}
Void TouchScene: ccTouchEnded (CCTouch * pTouch, CCEvent * pEvent)
{
CCPoint touchPoint = convertTouchToNodeSpace (pTouch );
If (mSprite1-> boundingBox (). containsPoint (touchPoint ))
{
CCMessageBox ("mSprite1 touched ","");
}
If (mSprite2-> boundingBox (). containsPoint (touchPoint ))
{
CCMessageBox ("mSprite2 touched ","");
}
}