Ios 屏幕左侧工作不正常

Ios 屏幕左侧工作不正常,ios,touch,cgrect,Ios,Touch,Cgrect,我正在尝试制作一个程序,让bug在屏幕上运行并被压扁。不过我有个问题。我有这样的代码,当我触摸屏幕上运行的bug时,它就会消失。不过,这只适用于右侧。这是我消除这个bug的代码 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch * touch = [touches anyObject]; CGPoint touchLocation = [touch locationInView:

我正在尝试制作一个程序,让bug在屏幕上运行并被压扁。不过我有个问题。我有这样的代码,当我触摸屏幕上运行的bug时,它就会消失。不过,这只适用于右侧。这是我消除这个bug的代码

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch * touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInView:[touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
    touchLocation = [self convertToNodeSpace: touchLocation];

    if (CGRectContainsPoint(bug.boundingBox, touchLocation)) {
        [self removeChild:bug cleanup:YES];


    }

}
然后,这是我在屏幕右侧生成bug的代码

- (void) addBug {

bug = [CCSprite spriteWithFile:@"bug.jpg"];

CGSize size = [[CCDirector sharedDirector] winSize];
int minY = bug.contentSize.height /2;
int maxY = size.height - bug.contentSize.height /2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;

bug.position = ccp(size.width + bug.contentSize.width/2, actualY);
[self addChild:bug];

int minSpeed = 2.0;
int maxSpeed = 4.0;
int rangeSpeed = maxSpeed - minSpeed;
int actualDuration = (arc4random() % rangeSpeed) + minSpeed;


actionMove = [CCMoveTo actionWithDuration:actualDuration
                                            position:ccp(-bug.contentSize.width/2, actualY)];
actionMoveDone = [CCCallBlockN actionWithBlock:^(CCNode *node) {
    [node removeFromParentAndCleanup:YES];
}];
[bug runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];

}

-(void)gameLogic:(ccTime)dt {
    [self addBug];
}
在init中,我有

    [self setTouchEnabled:YES];

    [self schedule:@selector(gameLogic:) interval:1.0];
如果这很重要的话,我也有背景。我还用日志测试了屏幕左侧是否有bug被触摸但没有被移除,当我在模拟器中单击bug时,没有任何记录,但当我在屏幕右侧单击它们时,它被成功记录。非常感谢你的帮助


*编辑,我调整了gameLogic的间隔:,当屏幕上一次只有一个bug时,左侧可以工作。我应该如何调整我的代码以使其正常工作,这样屏幕上就可以同时出现多个bug,并且我仍然可以将它们全部删除?我猜,我使用的代码为最新的bug创建了一个边界框,并删除了所有其他边界框。任何额外的帮助都会很好!谢谢大家!

您在每个
gameLogic:
调用上都添加了bug,但您只保留指向上次创建的错误的指针,这会导致在
CCToucheSBegined:withEvent:
中对单个错误进行冲突检查。将每个新对象添加到数组或任何适合其他需要的数据结构中,并对照其中的所有对象进行检查