I have a problem drawing smooth lines with my finger I’m doing the same thing as this guy here:
The only change I made is that in the onTouchesMoved method instead of a CCSet I have a std::vector<Touch*> and instead of
CCTouch *touch = (CCTouch *)touches->anyObject();
I have
Touch *touch = touches[0];
The rest is the same.
The program works, but the line is not continuous… it has holes. Any idea how to fix this issue? I saw in the comments that other people also have problems with this in the v3 version of cocos2dx.
Thanks! But I already managed to fix that problem and I did it with drawing primitives.
Here is the code if someone in the future has the same problem:
OnTouchesMoved method:
Touch *touch = touches[0];
Point start = touch->getLocationInView();
start = Director::getInstance()->convertToGL(start);
Point end = touch->getPreviousLocationInView();
end = Director::getInstance()->convertToGL(end);
if (end.getDistance(start) > 2)
{
drawCurPoint(start, end);
}
drawCurPoint method:
Point dir = end - start;
dir = dir.getPerp();
Point perpendicular = dir.getNormalized();
Point A = start + (perpendicular * (DOT_RADIUS / 2));
Point B = start - (perpendicular * (DOT_RADIUS / 2));
Point C = end + (perpendicular * (DOT_RADIUS / 2));
Point D = end - (perpendicular * (DOT_RADIUS / 2));
Point poly[4] = {A, C, D, B};
dot->drawSolidPoly(poly, 4, Color4F::BLACK);
dot->drawDot(end, DOT_RADIUS, Color4F::BLACK);
And by the way… I think that creating everytime the same Sprite* is not that optimal… you should use FrameCache for that if you dont want to kill your program