我尝试检测具有位置的特定精灵,当我使用“if”语句时,构建失败。
这是我的代码
-(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 语句似乎不起作用...我尝试做的是如果我触摸特定的精灵.. 它应该停止移动,但它没有。
if ((grade.position.x==location.x) && (grade.position.y==location.y))
{
[grade stopAllAction];
}
}
}
}
请更正'if'语句...