受到压力后游戏崩溃

问题描述:

我现在遇到了麻烦,当我压力太大时,它一直在崩溃。意思是我疯狂地滑动,移动或敲击屏幕上的手指,它会崩溃。崩溃没有规则。我试图检测,在控制台日志中显示消息低内存警告。我知道这是关于内存的东西,但我使用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]; 

     } 
    } 
} 

,这是一个装载盒

-(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; 

} 

的例子,请跟我分享一下你的知识,如果你知道的原因,我的游戏崩溃。 非常感谢你

+1

调用堆栈如何? – 2010-01-15 02:53:06

+1

发送给心理医生,听起来像是一个精神问题。 ;-) – 2010-01-15 03:30:28

你没有在这里的代码,但我的猜测是,你在这里的价值除以0。

touchDuration = timeEnd - timeStart; 

据苹果公司称,timeIntervalSinceReferenceDate返回秒,这意味着,如果你第二次timeEnd内称之为 - timeStart == 0,

我推断这从您的崩溃描述。

也许你的游戏消耗太多内存?在这种情况下,如果其他任何事情需要更多的内存,并且游戏已经完成了所有这些,系统本身就会杀死你的游戏。这种情况看起来像游戏中的随机崩溃。

+0

我能做些什么来将内存使用量降至最低?我遵循Cocos2D的最佳做法。它有点帮助,但随机崩溃仍然发生 – Rocker 2010-01-27 08:54:11

使您的代码响应DidRecieveMemoryWarning消息。然后当内存不足时,操作系统应该(它不会总是,特别是如果你的内存使用率快速通过屋顶)通知你,然后你可以摆脱可能已经离开屏幕或类似的对象。

我建议你附加一个调试器,禁用捕捉第一次机会异常,启用抓取第二次机会异常,然后导致你的崩溃。调试器会显示崩溃的调用堆栈。