I seem to be having an issue with the alpha being ignored when doing a drawpolygon on a CCDrawNode. What I expect to happen is, if I draw with 50 alpha (.5), I will be able to see through the drawn shapes to other Sprites behind the drawnode. But instead, the fills are always at 100 opacity. Is this a bug, or am I confused?
I have the same issue with CCDrawNode not respecting alpha and always drawing with 100% opacity.
>
`Adipose Dan
Yours solution work fine, but it’s a lot (and I mean a lot) slower than CCDrawNode.
Is any hope for update for CCDrawNode?
Adam,
I seem to remember that dynamically allocating an array like I did above can be expensive. Maybe if you made it a `CCPOint[4]@ and moved it into the class definition, it would speed things up:
class DrawNode : public CCNode {
public:
CCPoint filledVertices[4];
struct rect {
float left, top, right, bottom;
ccColor4F color;
};
vector rects;
DrawNode() {
}
virtual void draw() {
for(auto it = rects.begin(); it != rects.end(); ++it) {
rect r = *it;
filledVertices[0]=ccp(r.left,r.top);
filledVertices[1]=ccp(r.right,r.top);
filledVertices[2]=ccp(r.right,r.bottom);
filledVertices[3]=ccp(r.left,r.bottom);
ccDrawSolidPoly(filledVertices, 4, r.color);
}
}
void addRect(rect r) {
rects.push_back(r);
}
static DrawNode* create() {
DrawNode *dr = new DrawNode();
if (dr) {
dr->autorelease();
return dr;
}
CC_SAFE_DELETE(dr);
return nullptr;
}
};
I haven’t tested this, but let me know if it’s any faster.
Not sure if this is what you’re seeing, but I had a similar issue with CCDrawNode not respecting alpha on android. I was able to fix what I was seeing by changing a line in CCDrawNode::render()
this line:
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(ccV2F_C4B_T2F), (GLvoid *)offsetof(ccV2F_C4B_T2F, colors));