Cocos2DImplementationFruit NinjaIn this article, we will introduce the effect of the knife and light in detail.Cocos2DAn Effect in game development. Let's take a look at the details.
Implementation ideas:
√ Obtain the track and number of control points from multi-point touch. Generally, queue is used. The new point is the point at the end of the team. This is represented as point [16].
√ Loop; point and point [I + 1] form a straight line l. Calculate the slope of the straight line and obtain the angle θ from the slope (which can be used to study polar coordinates ), then obtain the normal equation of l (Xcos θ + ysin θ-p = 0 );
Translate the point with the width W (-W) along the normal direction to obtain two moving tracks.
Here, the absolute value of W should be wider in the header, and the tail should be reduced to 0.
Key Algorithms:
- <EM><EM>
- CGPoint pt = ccpSub(p1, p2);
- GLfloat angle = ccpToAngle(pt);
- GLfloat x = sinf(angle) * w;
- GLfloat y = cosf(angle) * w;
- vertex->x = p1.x+x;
- vertex->y = p1.y-y;
- </EM></EM>
Source code download: http://www.cocoachina.com/bbs/job.php? Action = download & aid = 17941
Summary:Cocos2DImplementationFruit NinjaThe content of the "Dao guang effect" tutorial is complete. I hope this article will help you!