I wrote a code to draw 10 yellow triangles on the screen and rotate them to animate like this I will add 2 frames below:
All this is very nice, but when I add number of rectangles to be about 800 then I see this:
.
In the case when I have 500 triangles I see the following problems:
As you can see I don't even have those colors. (I have only black and the yellow one.) Actually, you can see there any color, depending on the number of triangles. I think this is some OpenGL problem. I an new to OpenGL and I guess I misused something in OpenGL. Here is the code. It is in cocos2d-x (C++) but surely you can understand what is being done here:
Color4F color1e(239.0f / 255, 255.0f / 255, 138.0f / 255, 1);
auto sunNode = DrawNode::create();
sunNode->setContentSize(_size);
int bansCount = 1000;
Vec2 center(_size / 2);
float angleStep = (2 * 3.1415926) / bansCount;
auto rotated = [angleStep, center](float mult) {
Vec2 vc(0, 0);
vc.rotate(center, angleStep * mult);
return vc - center;
};
for(int i = 0; i < bansCount; i+=2) {
sunNode->drawTriangle(
Vec2(0,0), // vertex 1
rotated(i), // vertex 2
rotated(i + 1), // vertex 3
color1e // color of vertices
);
}
addChild(sunNode, 2); // add to sceen
sunNode->setPosition(center); // position on center
// infinitely rotate
sunNode->runAction(RepeatForever::create(RotateBy::create(0.05, 3.1415926 / 10)));
Code full is here, in case someone want to look at or experiment: https://github.com/jonyrock/Cocos2dxDrawingArtifacts