Cocos2d iphone 请帮助触摸数组中的特定精灵,它们正在删除代码
我试着用位置来检测特定的精灵,当我使用“if”语句时,构建失败了 这是我的密码Cocos2d iphone 请帮助触摸数组中的特定精灵,它们正在删除代码,cocos2d-iphone,Cocos2d Iphone,我试着用位置来检测特定的精灵,当我使用“if”语句时,构建失败了 这是我的密码 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* myTouch = [touches anyObject]; CGPoint location = [myTouch locationInView: [myTouch view]]; location = [[CCDirector sharedDirector]
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView: [myTouch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
int numGrades = [grades count];
for (int i = 0; i < numGrades; i++)
{
// Put each spider at its designated position outside the screen
CCSprite* grade = [grades objectAtIndex:i];
int numGrades = [grades count];
for (int i = 0; i < numGrades; i++)
{
CCSprite* grade = [grades objectAtIndex:i];
请更正“如果”语句 看来您只是想检测到精灵的触碰。您当前的交叉点测试要求您的触摸坐标与精灵的中心点完全匹配,这实际上是不可能的 相反,您应该尝试根据精灵的边界框测试触摸坐标
if (CGRectContainsPoint(grade.boundingBox, location))
{
[grade stopAllActions];
}
也请注意,它是带“s”的stopAllActions
希望这对您有所帮助。可能的副本
if (CGRectContainsPoint(grade.boundingBox, location))
{
[grade stopAllActions];
}