-1
我加入精灵到的NSMutableArray这样的:阅读精灵,检测碰撞
NSMutableArray * movableSprites;
NSString *image = [images objectAtIndex:3];
CCSprite *sprite = [CCSprite spriteWithFile:image];
sprite.position = ccp(AREA_A2_X2 - (i * 56), AREA_A3A5A4_Y);
[self addChild:sprite];
[movableSprites addObject:sprite];
到目前为止好。
现在我试图检测它们之间的冲突。用户能够移动精灵,但我想让精灵被彼此阻挡。
因此,当我在翻译他们时,我希望它在那里发生。顺便说一下,它是碰撞检测的最佳去处吗?
- (void)panForTranslation:(CGPoint)translation {
if (selSprite) {
我打算做以下的循环:
CGRect rect1 = [SpriteUtilities positionRect:selSprite];
CGRect rect2 = [SpriteUtilities positionRect:EVERY_OTHER_SPRITE];
if (!CGRectIsNull(CGRectIntersection(rect1, rect2))) {
//handle collision
}
的事情是...我没有找到一个NSMutableArray的方法来检索组图对象。
谢谢您的帮助。
如果你使用问题的代码,接下来你会想知道为什么数组是空的! – YvesLeBorg
............为什么? – RickON
你没有创建数组对象,就像moveableSprites = [[NSMutableArray array] retain]; (保留,如果你不使用ARC,不要忘记释放dealloc)。 – YvesLeBorg