我正在关注Ray的教程,制作一个简单的iPhone游戏(这里:http://goo.gl/fwPi),并决定我想让敌人在被触及时被淘汰.
我最初的方法是在触摸位置生成一个小的CCSprite精灵,然后使用CGRectMake创建一个所述精灵的边界框,以检测敌人的精灵是否被触摸.就像雷与射弹/敌人一样.但是,当然,我这样做的方式不起作用,我无法从这个洞中挖掘自己.
这是相关的代码段.任何帮助表示赞赏:
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// Choose one of the touches to work with
UITouch *touch = [touches anyObject];
CGPoint location = [self convertTouchToNodeSpace: touch];
location = [[CCDirector sharedDirector] convertToGL:location];
CCSprite *touchedarea = [CCSprite spriteWithFile:@"Icon-72.png" rect:CGRectMake(location.x, location.y, 2, 2)];
touchedarea.tag = 2;
[self addChild:touchedarea];
[_touchedareas addObject:touchedarea];
}
- (void)update:(ccTime)dt {
NSMutableArray *touchedareasToDelete = [[NSMutableArray alloc] init];
for (CCSprite *touchedarea in _touchedareas) {
CGRect touchedareaRect = CGRectMake(
touchedarea.position.x,
touchedarea.position.y,
touchedarea.contentSize.width,
touchedarea.contentSize.height);
NSMutableArray *targetsToDelete …