Hi everyone. I am in trouble with my game now, it keep crashing when I stress it too much. Meaning I crazily sliding, moving, or tapping my fingers on the screen, it will crash. The crash has no rule. I tried to detect, in the console log shows the message low memory warning. I know it is about the memory stuff, but I am using Cocos2D to make this game, I followed the instructions in best practice. It seems smoother after that but still crashes if I do like what I mentioned above. If like in Cocoa, we have alloc and release, but it Cocos2D, I think we don't need to do so. My game is just loading images, and make animation after touching.
//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];
}
}
}
and this is an example of a loading box
-(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;
}
Please share your knowledge with me if you know about the reasons why my game crashes. Thank you so much