【Cocos2D-X 游戏引擎】初窥门径(8)判断精灵点击

在场景中添加几个精灵

	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);



判断点击的点是否在精灵自身的范围内,也就是判断是否点击了精灵:

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","");
	}
} 

【Cocos2D-X 游戏引擎】初窥门径(8)判断精灵点击_第1张图片





转载请注明出处:http://blog.csdn.net/Vestigge






你可能感兴趣的:(cocos2d-x)