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??
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 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.
Then have a function that can be called to generate the bounding box
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.
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.
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.