强调后游戏崩溃了

Roc*_*ker 3 objective-c

我现在的游戏遇到了麻烦,当我过分强调时它会不断崩溃.意思是我疯狂地滑动,移动或敲击屏幕上的手指,它会崩溃.崩溃没有规则.我试图检测,在控制台日志中显示消息低内存警告.我知道这是关于内存的东西,但我使用Cocos2D来制作这个游戏,我按照最佳实践的说明进行操作.之后看起来更顺畅,但如果我喜欢上面提到的话,它仍然会崩溃.如果像Cocoa一样,我们有alloc和release,但它是Cocos2D,我想我们不需要这样做.我的游戏只是加载图片,触摸后制作动画.

//where the fingers ended , this will determine the correct actions made. 
-(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)events
{
    int touchCount = 0;
    NSSet *allTouches3 = [events allTouches];
    for( UITouch *touch in allTouches3)
    {
        location3 = [touch locationInView: [touch view]];
        location3 = [[Director sharedDirector] convertCoordinate: location3];

        NSLog(@"end TOUCHed x2: %3.3f, y2: %3.3f",location3.x,location3.y);
        touchCount++;
    }
    [self removeChildByTag:kTagWord cleanup:YES]; 

    timeEnd = [NSDate timeIntervalSinceReferenceDate];
    touchDuration = timeEnd - timeStart;
    //float rangeX = location3.x - location.x;
    rangeY2 = location3.y - location.y;

    //loading the succesful opened box with 2 touches same direction 
    if ((touchCount > 0 && touchCount ==2) && (rangeY2 > 0.0 && rangeY2 <15.0))
    {
        box++;
        self.isTouchEnabled = NO;
        [self removeErrorText];

        if (box == 1)
        {
            [self loadingTheRest];
        }
        else if (box == 2)
        {
            [self loadingTheRest1];
        }
        else if (box ==3)
        {
            [self loadingTheRest2];
        }

        if (currentBox == 0 )
        {
            [self addText];
            [self boxOpenAnimation];
            [self schedule:@selector(enableTheTouches) interval:1.0f];

        } else if(currentBox == 1 )
        {
            [self addText1];
            [self boxOpenAnimationPink];
            //[self schedule:@selector(winGame) interval:0.4f];
            [self schedule:@selector(enableTheTouches) interval:1.0f];

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一个装箱的例子

-(void)loadingTheRest
{
    //LOADING OTHER COLOURS
    AtlasSpriteManager *managerPink  = [AtlasSpriteManager spriteManagerWithFile:@"PinkNew.png"];
    AtlasSpriteManager *error2  = [AtlasSpriteManager spriteManagerWithFile:@"PinkErrors.png"];
    [self addChild:managerPink z:1 tag:kTagSpriteManagerPink ];
    [self addChild:error2 z:1 tag:kTagSpriteErrorPink ];

}

-(void)boxOpenAnimation
{
    if (isBusy==YES)
    {
            return;
    }
    isBusy=YES;

    [self removeBoxColours];
    AtlasSpriteManager *mrg = (AtlasSpriteManager *)[self getChildByTag:kTagSpriteManager];
    AtlasSprite *box = [AtlasSprite spriteWithRect:CGRectMake(482, 322,480, 320) spriteManager:mrg];
    box.position = ccp(240,160);
    [mrg addChild:bra z:1 tag:1984];

    AtlasAnimation *animation = [AtlasAnimation animationWithName:@"open" delay:0.1];

    [animation addFrameWithRect: CGRectMake(1, 322, 480, 320) ];    
    [animation addFrameWithRect:CGRectMake(482, 1, 480, 320)];
    [animation addFrameWithRect:CGRectMake(1, 1, 480, 320)];
    [animation addFrameWithRect:CGRectMake(1, 643, 480, 320)];
    id action = [Animate actionWithAnimation:animation];

    [box runAction:action];
    [self loadingTheRest];
    isBusy=NO;

}
Run Code Online (Sandbox Code Playgroud)

如果您知道我的游戏崩溃的原因,请与我分享您的知识.非常感谢

小智 7

你这里没有代码,但我的猜测是你用这里的值除以0.

touchDuration = timeEnd - timeStart;
Run Code Online (Sandbox Code Playgroud)

根据Apple的说法,timeIntervalSinceReferenceDate返回秒,这意味着如果你在第二次调用它之后 - timeStart == 0.

我从你对崩溃的描述中推断出这一点.