Reinitialize ccMotionStreak for every new touch

I am trying to track the movement of a user's finger on the screen for my iPhone / cocos2d game.

For now, I can do this using ccMotionStreak declared in the interface to my GameLayer and initialized in my init method. To draw a custom contact, I insert the following code in touchesMoved:

UITouch *touch = [touches anyObject]; [streak setPosition:[self convertTouchToNodeSpace:touch]]; 

This works until I lift my finger and make a new touch movement on the screen. Instead of drawing a new strip, my game connects the end of the old strip to the beginning of my new scroll and continues the same strip. This is not what I want.

Is there a way to reset my ccMotionStreak? If not, the obvious solution seems to be to create a new strip on every new touch (and delete the old one), but I can't get this to work. When I move the initialization code for my line from the init method and to touchhesBegan, the strip no longer appears at all.

I suppose this should be basic to achieve, but I just can't understand the syntax. I am still learning ObjC / cocos2d. Can anyone help?

This is how I initialize my string in the init method:

 streak = [CCMotionStreak streakWithFade:3.0 minSeg:1 image:@"streak.png" width:4 length:8 color:ccc4(128,128,128,255)]; [self addChild:streak]; 
+4
source share
1 answer

Have you deleted / canceled the old series on ccTouchesEnded and ccTouchesCancelled?

 // in ccTouchesBegan streak = [CCMotionStreak streakWithFade:3.0 minSeg:1 image:@"streak.png" width:4 length:8 color:ccc4(128,128,128,255)]; [streak setPosition:location]; [self addChild:streak]; // in ccTouchesEnded and ccTouchesCancelled if (streak) { [streak removeFromParentAndCleanup:YES]; streak = NULL; } 
0
source

All Articles