I've got a CCLayer class with touch enabled and the following methods:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
If I rapidly tap on the iPad screen repeatedly, it will crash-- but not to the point of getting a stack trace.. It will just freeze... The console will read:
2012-10-17 08:43:06.445 game[5432:607] cocos2d: animation stopped
2012-10-17 08:43:06.448 game[5432:607] cocos2d: animation started with frame interval: 4.00
2012-10-17 08:43:07.075 game[5432:607] cocos2d: animation stopped
2012-10-17 08:43:07.081 game[5432:607] cocos2d: animation started with frame interval: 60.00
2012-10-17 08:43:12.557 game[5432:607] cocos2d: animation stopped
2012-10-17 08:43:12.561 game[5432:607] cocos2d: animation started with frame interval: 4.00
Is there a way to rate limit the ccTouchesBegan/ccTouchesEnded methods? This even happens if I remove all the code inside those event handlers-- it's just the act of triggering that method ultra frequently that seems to bog everything down.
Is this happening in a new cocos2d project with just the touch modifications, too? If so, file a bug report on the cocos2d forum.
The log seems to indicate that cocos2d is either being paused or stopped, or both. Check if the CCDirector functions startAnimation, stopAnimation, pause and resume are being called by setting a breakpoint. Check the callstack who is making these calls. If it comes from your code, fix it. If not and this happens in a new project, file a bug report.
Related
I'm using Xcode with Cocos2d version 3.0.
I want to drag sprites around the screen. I've done so successfully using the following code:
(void) touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInNode:self];
sprite1.position=touchLocation;
sprite2.position=touchLocation;
sprite3.position=touchLocation;
sprite4.position=touchLocation;
}
However, sometimes the sprites stop moving after a second. It's not a lag, because they never catch back up with my movement. They just stop! If I let go and start moving my touch again, the sprites start moving fine again / sometimes do the 'freeze thing' again.
Is it a memory issue?
Ok, I'm sure it must be memory. I copied this code onto a simple game with hardly any sprites and it worked perfectly.
Ok I've got it!
I had to unEnable the UISwipeGestureRecognizers while I moved the sprite.
The game was registering my touchesMoved movement as a swipe, and cancelling the touchesMoved commands.
Problem: I have a CCSprite animation that uses 7 frames. It works fine when I run the action with a delay of .04f, however, I need to run this animation at .02f which causes it to completely stop about 2~3 frames into the sprite animation. Bumping it up to .03f gets about 4~5 frames in before the sprite freezes.
I can't post the code because there's way too much. Really I'm looking for a general idea of where to start looking. The CCSprite I'm calling the runaction on is being retained, so that doesn't seem to be the issue. Thoughts?
I am trying to display UIAlert view when my application gets opened from running in the background, but the notification is not getting called until the cocos2d frame interval has dropped from 15 down to 1. I don't understand what this means. Could someone enlighten me. When closing the app it shows this in the debugger.
-[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 15
Then when I reopen the app it shows the same thing.
-[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 15
but after about 1 or 2 seconds then I get this message `
-[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 1
in the debugger and then it calls the notification?
I'm looking for a way to get the current scene so that I'll be able to tell which scene is running at any time.
Thanks!
Check out CCDirector. You can get the running scene like this:
[[CCDirector sharedDirector] runningScene];
From the documentation of cocos2D:
-(CCScene*) runningScene [read, assign]
The current running Scene. Director can only run one Scene at the time
Sandro Meier
Hello, I have created a layer for a demo game application using cocos2D Framework. I have integrating cocos2d with existing application. I need to detect Touch Events for that. But I am not able to Detect that.I have used ccTouchesBegan.
- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self ccTouchesEnded:touches withEvent:event];
}
Even simple touchBegan event is also not fired.
do I have to add anything like delegate or Protocol for that ? I am new in iphone development and also I am learning cocos2d programming for game development . please help.
In the init method of the layer, you need to tell it to respond to touches by setting self.isTouchEnabled = YES;.