문제

I'm working on a game based on cocos2dx, now I need to draw an arbitrary curve as the finger moves on the screen,then the curve will become the path along which my hero walks.Any idea will be appreciated.

도움이 되었습니까?

해결책

Curve is connected line.
so you can draw curve using connected line.

Accumulate the points in cctouchesmove/cctouchemove event function.
Make line sprite, add and draw them.

and also cocos2d-x have curve classes. 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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top