Hey!
(I’m using Cocos2dx 3.1 if it matters).
Using a DrawNode as a child in am otherwise empty Layer, I am attempting to draw primitives (specifically, a line drawn by points added by the user, like a paintbrush). I draw them as a set of lines.
However, the effect is awful : the primitives are not antialiased, they are jagged… and certainly not fit for a game. Does anyone know what I can do to improve on the effect ?
Here is the relevant code :
void TouchPaddleSprite::draw(Renderer* renderer, const Mat4& transform, bool transformUpdated) {
if (pointsToDraw < 2) return;
if (nPoints > 2) {
for (int i = 0; i < pointsToDraw; ++i) {
drawNode->drawSegment(points[nPoints - i - 2], points[nPoints - i - 1], 2.0f, Color4F::WHITE);
}
}
else if (nPoints == 2) {
drawNode->drawSegment(points[0], points[1], 2.0f, Color4F::WHITE);
}
pointsToDraw = 0; }
The points are added through touchesMoved with these functions:
void TouchPaddleSprite::resetPoints() {
drawNode->clear();
nPoints = 0;
}
void TouchPaddleSprite::addPoint(cocos2d::Vec2 point) {
if (nPoints + 1 > kMaxPoints) { this->resetPoints(); return; }
pointsToDraw++;
points[nPoints++] = point;
}
void TouchPaddleSprite::draw(Renderer* renderer, const Mat4& transform, bool transformUpdated) {
if (pointsToDraw < 2) return;
if (nPoints > 2) {
for (int i = 0; i < pointsToDraw; ++i) {
drawNode->drawSegment(points[nPoints - i - 2], points[nPoints - i - 1], 2.0f, Color4F::WHITE);
}
}
else if (nPoints == 2) {
drawNode->drawSegment(points[0], points[1], 2.0f, Color4F::WHITE);
}
pointsToDraw = 0;
}
I would be grateful for any help and open to any ideas.
I’ve tried porting this guide to Cocos2D-X v3.1 but with no success ; and if anyone has in the past ported it, I would actually be very happy !
screenshot of the ugly lines