O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the motion streak effect

Motion streak is a very common effect in games these days, and it is very easy to achieve.

Getting ready

No additional preparation is required for this.

How to do it…

To add the effect, we need to first make some additions to the MainScene.h file, as follows. We need a global MotionStreak object, and we need the update function so that the streak effect follows the hero.

So, the MainScene.h file should now be as follows:

@interface MainScene : CCNode{

  CCSprite* hero;

  CCMotionStreak* streak;
}

+(CCScene*)scene;
- (void)update:(CCTime)delta;

@end

Next, in the MainScene.m file, we will add the following to first enable touches, then add the touch-related functions, and finally update the function:

- (void)onEnter { [super ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required