0
我有一個帶有很多Sprite(spriteX)的NSDictionary
(allSprites),並且在我的Touch Method中我想檢查是否觸及了Sprite。NSDictionary中的CCSprite不會對BoundingBox產生反應
我的問題是它不會對boundingBox做出反應。我沒有看到我的錯誤!這是NSDictionary
的問題嗎?我沒有任何錯誤或任何東西......但它不起作用。
是否有另一種方法檢查NSDictionary
中的boundingBox?有人能幫助我嗎?
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in [event allTouches]) {
for (NSValue* value in allSprites) {
CGPoint location = [touch locationInView:touch.view];
location = [[CCDirector sharedDirector] convertToGL:location];
if(CGRectContainsPoint([spriteX boundingBox], location)){
NSLog(@"sprite was touched");
}
}
}
}
非常感謝!!!!這工作很棒!!!!!!!!!!! – user2444915
我會將'location = ...'行移出循環。 – Kreiri