Original article, reproduced please indicate the source: http://blog.csdn.net/zhy_cheng/article/details/8434598
To make the moving object have a tail effect, you can use ccmotionstreak.
Here I use [Cocos2d-x game engine development Note (12)] particle system to achieve user interaction with the example of special effects, making the effect more cool.
Add the following to the header file:
Ccmotionstreak * strike;
Then add the following code to the init function:
Strike = ccmotionstreak: streakwithfade (1.0f, // The duration of the tail: 16366f, // the size of the tail: 16366f, // the size of the image: ccc3 (255,255, 0 ), // color "sprite.png" // used image); addchild (Strike, 1); strike-> setposition (CCP (240,160 ));
Then change the position in the cctouchmoved function.
Strike-> setposition (ptouch-> getlocation ());
Set the position in the cctouchbegan Function
Strike-> setposition (ptouch-> getlocation ());
Okay, I'm done. The following figure shows the running effect on the G2 mobile phone of my Jiayu.
Source code download: Click to download