0
我試圖檢測具體的精靈與位置,而當我使用'如果'的聲明,有失敗的內置。請幫助觸摸特定的精靈陣列,這是下降代碼
這裏是我的代碼
-(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];
}
}
}
}
請糾正「如果」語句...
[在CCArray之間觸摸特定的CCSprite]的可能重複(http://stackoverflow.com/questions/11079420/touch-specific-ccsprite-among-ccarray) – Morion