i'm trying to draw a continues spline on every onTouchMoved call, the functionality is supposed to be similar to the line drawing used in the iOS game - flight control.
i'm using it in the following manner:
constructor init:
conPointsArray = new PointArray();
conPointsArray->initWithCapacity(DEF_ARRAY_SIZE);
lineDrawer = DrawNode::create();
the onTouchMoved callback usage:
void line::onTouchMoved(cocos2d::Touch *Touch, cocos2d::Event *Event)
{
conPointsArray->addControlPoint(Touch->getLocation());
lineDrawer->drawCardinalSpline((conPointsArray), 0.5f, 100, Color4F::BLUE);
CCLOG("on touch moved x: %f y %f", Touch->getLocation().x, Touch->getLocation().y);
}
But the app is always crashing in a certain openGL function.
I assumed the reason for it is because the array is constantly changing and openGL is having trouble with it (and the fact i'm always sending the same array which is a bad idea, but just to see how things work), so i moved the drawing call to onTouchEnded, And indeed, The line was drawn, but only (as expected) after the onTouch action has ended.
What is the solution/best practice for this issue?
Cheers.
CCRenderTexture
for drawing. \$\endgroup\$RenderTexture
is available. \$\endgroup\$RenderTexture
is best solution fo such applications. you can usevisit()
method ofSprite
and draw(=visit
) a point ( probably a circle sprite) on your canvas(=RenderTexture
) while touch is moving(=onTouchMoved
) \$\endgroup\$