Anhcor points have no effect to drawNodes? In this case, a polygon

Hi!

Why don’t the anchor points have effect to the drawNodes?

In my case I’ve created a polygon using a drawNode and set its position with the anchor points in mind, I set them to 0.5, 0.0 but no matter what I set them to, the polygon always seems to have 0.5, 0.5??

Thanks

Have you set the content size for the DrawNode? I just tested this and setting the anchor point did nothing for me until I set the DrawNode’s content size.

@grimfate Do you think this is a bug? I mean when you create a DrawNode, shouldn’t we set the contentsize automatically based upon the parameters provided at creation?

const int numberStripes = 10;
const int stripeWidth = displaySize.width / numberStripes;
const int stripeHeight = displaySize.height;
const int verts = 4;
int startXPos = 0, startYPos = 0;

cocos2d::Color4F red = cocos2d::Color4F(1.0f, 0.0f, 0.0f, 1);

cocos2d::Point stripe1[] = {cocos2d::Point(startXPos,startYPos),
    cocos2d::Point(startXPos,stripeHeight),
    cocos2d::Point(stripeWidth,stripeHeight),
    cocos2d::Point(stripeWidth,startYPos)};
cocos2d::DrawNode* dotNode = cocos2d::DrawNode::create();
dotNode->drawPolygon(stripe1, verts, red, 0, red);
layer->addChild(dotNode, 0);

I feel like in an example like this, we are specifying the content size, but you are correct. If I take these same parameters and do dotNode->setContentSize(...) things are better.

I am not sure if it is a bug. I imagine they chose to do it this way for a reason. It would be good if they included a function to automatically set the content size, though.

I would imagine it is not set because it doesn’t know when you have finished drawing - so when would you want it to calculate the size?

I would do it whenever something is drawn on the DrawNode. So whenever I draw a shape, it would expand the bounding box of the DrawNode to include the new shape.

Sure - but that’s wasted CPU cycles if I just know I am going to draw 100 things - better let the developer decide when they are done drawing?

Then have a function that can be called to generate the bounding box :stuck_out_tongue:

Anyway, I’m not suggesting I know the best way to implement it. It’s just that this is the second time I have seen someone ask for this in the last little while and it makes sense that there should be some built-in way to do this.

But why can’t you just do something like this: [code]
rectNode = DrawNode::create();
Vec2 rectangle[4];

rectangle[0] = Vec2(-(230), -(40));
rectangle[1] = Vec2((230), -(40));
rectangle[2] = Vec2((230), (40));
rectangle[3] = Vec2(-(230),(40));

rectNode->drawPolygon(rectangle, 4, colorBehind, 1, colorBehind);
rectNode->setAnchorPoint(Vec2(0.0, 0.0));
rectNode->setPosition(Vec2( origin.x + 5, origin.y + visibleSize.height));
this->addChild(rectNode, 1);
[/code]

I mean it knows that the shape is done so why can’t i set the anchor point of the finished shape??

Thanks again!

Right, that is the point of this topic is that you can’t seem to setAnchorPoint , or rather it has no effect, until you manually use setContentSize()…then setAnchorPoint() works as expected.

Ok, do you think it’ll get changed ?

I am going to create a GitHub issue and talk to the engine developers about it. I will post the Issue ID once I create it.

Well, because after the drawPolygon it doesn’t KNOW that you aren’t going to have another drawXXX call - so should it set the content size now, or wait (as it my change after the next draw).

I think the idea is that the Draw Node is an infinite canvas until you stop drawing - so you need some way to tell it you have stopped drawing so it can set the size - if that’s what you want!

Surely the workflow should be to do just that - draw your stuff then ask the node to set its content size.

Seems to me the only issue is that folk don’t realise that’s what they need to do.