Tuesday, December 29, 2015

Custom Cocos2d-x motion streak

First I read the post of this place:


Ok lets think about this, when you create a motion streak node in cocos2d-x you need to use something like this, I take this from the web site of Planar box. So you  need to create a schedule update to make it work, but bassicaly the MotionStreak by itself have that so making some little changes you can have the amazing effect working with less code.

 bool MyLayer::init()  
   /* ... initialize layer ... */  
   //add a sprite  
   _sprite = Sprite::create("circle.png");  
   //add a MotionStreak  
   _streak = MotionStreak::create(0.15f, 5, 50, Color3B::RED, "circle.png");  
   //schedule the update() function  
   return true;  
 void MyLayer::update(float dt)  
//Of course this was taken from this website

Can made it more easier?

Yes. this is the example also taken from planar box.

     //add a MotionStreak  
     auto streak = MotionStreak::create(0.15f, 5, 50, Color3B::RED, "circle.png");  
     streak->setFastMode(true); //use this if you have a complex scene  
     //follow the circle sprite's center position  
     streak->followNode(circle, Vec2(circle->getContentSize().width * 0.5f, circle->getContentSize().height * 0.5f));  

How to use it ?

First you need to have created a new cocos2d-x project
change this files CCMotionStreak.h & CCMotionStreak.cpp
they must be in a place like here

And replace it with this files that you can find here.

Thanks to PlanarBox to the examplesI was able to create an updated version.


  1. Replies
    1. Sorry I didn't get the notification.
      Please tell me what version of cocos2d-x are you using ?
      I'm gonna check what happened.