0

Here is the problem: I'm working with cocos2D and CCLayers, and I use a UIView to catch movements with a Gesture recognizer for a UIScrollMenu. On my layer, there are animated sprites that run an animation forever; when I drag the scrollMenu with the finger and I stop my finger held down, the CCLayer in background is not updated anymore, and the sprites does not move. As soon as I move the finger again, the sprites are updated. The problem should not come from the sprites, because when I stop and move again, the sprite does not play its next frame, but the frame that should have been displayed if it had continued to move normally. I think that the frames are still calculated, but the layer does not update its view anymore.

Would anyone have an idea to avoid that?

I don't do anything in order to update the CCSprites, I just launch on them a CCRepeatForever action, then I let their parent CCLayer care about them. I have tried to schedule this CCLayer, but the update function is not called anymore as soon as I am dragging an item with my finger...

`CCAction *hitAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:hitAnim restoreOriginalFrame:NO]];

[sprite runAction:hitAction];`

The function which is called when I move my finger again (and apparently allows the CCLayer to update) is - (void)scrollViewDidScroll:(UIScrollView *)scrollView

Grhyll
  • 83
  • 1
  • 6

2 Answers2

0

Well, you didn't post any code...but based on a problem I had once in the past this is my best guess. If you are updating your animation (or method calls to do animation) inside of CCTouchesMoved then stop doing that. Simply update any information you might need inside CCTouchesMoved and then update your animation inside of a timer method (like if you use [self scheduleUpdate].

Aaron Goselin
  • 634
  • 7
  • 19
  • First of all, thanks for answering! I did not post any code because, as I said, it is located in a lot of classes, and I don't really know which part could be useful here... About the animation, I am not animating it by myself at all, I just use cocos2D class CCSprite and method "runAction" with a CCRepeatForever action. I don't manage it in my touchesMoved method (not CCTouchesMoved, because I use a UIView to detect movements). If you have an idea about the part of the code in which the problem could be located, I will post it. – Grhyll Jun 20 '11 at 14:55
  • Yeah I would need to see some code where you are animating (with information about context if you don't want to post a huge chunk of code) and also where you detect and handle movements. I can't really just guess. It's possibly a problem with CCRepeatForever though. It can be interrupted and if it isn't started again then it will just do nothing. – Aaron Goselin Jun 20 '11 at 18:25
  • About the animation, it's just launched with: `CCAction *idleAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:idleAnim restoreOriginalFrame:NO]]; [sprite stopAllActions];` – Grhyll Jun 20 '11 at 21:52
  • About the movement detection, there is a `UIScrollView ` at the bottom of the page in which some functions are raised, such as `-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event`, `-(void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event` , `- (void)scrollViewDidScroll:(UIScrollView *)scrollView `... This UIView is a subview added in the CCDirector, over the CCLayer in which I add the sprites on which I call the functions mentioned at the beginning of this post. – Grhyll Jun 20 '11 at 21:52
  • Sorry but I think I'm actually stumped on this one. In every situation where I have tried to use Cocos2D and UIKit together I have had massive trouble and strange unexpected behaviour. Just today I ran into this again (unexpected behaviour) and lost patience with it. I ended up just coding my solution in Cocos2D and dropping UIKit altogether. Hopefully someone else can help you out with this one. If you are still hoping I can figure it out then you can post larger portions of code. Just edit your original question and put the code in there. I will check back to see if you do or not. – Aaron Goselin Jun 21 '11 at 03:08
  • I wouldn't know what to put... Thanks for the help anyway! – Grhyll Jun 21 '11 at 09:21
0

I ended up by posting this question on the cocos2D forum, and here is the answer: http://www.cocos2d-iphone.org/forum/topic/17845

Grhyll
  • 83
  • 1
  • 6