coccs2d-x代码积累(一)判断点击的是哪个精灵

本文为firedragonpzy原创,转载务必在明显处注明:
转载自【Softeware MyZone】原文链接: http://www.firedragonpzy.com.cn/index.php/archives/90



CCRect atlasRect(CCSprite* sprite)
{
	CCRect rc = sprite->getTextureRect();
	return CCRectMake(-rc.size.width/2, -rc.size.height/2, rc.size.width, rc.size.height);
}


CCSprite* Prop::selectSpriteForTouch(CCTouch* pTouch)
{
	CCSprite* sprite =  NULL;
	CCMutableArray<CCSprite*>::CCMutableArrayIterator it;
	for (it = allProps->begin(); it != allProps->end(); it++)
	{
		sprite = *it;
		CCPoint point = sprite->convertTouchToNodeSpaceAR(pTouch);
		if (CCRect::CCRectContainsPoint(atlasRect(sprite),point))
		{
			return sprite;
		}
	}
	
	return NULL;
}

//获取并处理点击的精灵
void Prop::ccTouchEnded(CCTouch* pTouch, CCEvent* event)
{
	CCSprite* sprite = selectSpriteForTouch(pTouch);
}

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