简体   繁体   English

如何在cocos2dx中绘制任意曲线

[英]How to draw an arbitrary curve in cocos2dx

我正在开发基于cocos2dx的游戏,现在我需要在手指在屏幕上移动时绘制一条任意曲线,然后该曲线将成为英雄行走的路径。任何想法都会受到赞赏。

Curve is connected line. 曲线是连接线。
so you can draw curve using connected line. 因此您可以使用连接线绘制曲线。

Accumulate the points in cctouchesmove/cctouchemove event function. cctouchesmove/cctouchemove事件功能中累积点。
Make line sprite, add and draw them. 制作线条精灵,添加并绘制它们。

and also cocos2d-x have curve classes. 并且cocos2d-x也具有曲线类。 if you use them, you can run action easily. 如果使用它们,则可以轻松执行操作。

CCCardinalSplineTo
CCCardinalSplineBy
CCCatmullRomTo
CCCatmullRomBy
CCBezierBy
CCBezierTo

And for drawing, this is sample code. 对于绘图,这是示例代码。

void HelloWorld::draw()  
{  
    // move to 50,50 since the "by" path will start at 50,50  
    kmGLPushMatrix();
    kmGLTranslatef(50, 50, 0);
    ccDrawCardinalSpline(m_pArray, 7, 100);

    kmGLPopMatrix();

    CCSize s = CCDirector::sharedDirector()->getWinSize();  

    kmGLPushMatrix();  
    kmGLTranslatef(s.width/2, 50, 0);  
    ccDrawCardinalSpline(m_pArray, 1, 100);  
    kmGLPopMatrix();  
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM