{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
//正方形
auto rect=DrawNode::create();
rect->drawRect(Vec2(0,0),Vec2(300,300),Color4F(1.0,1.0));
//点
auto dot = DrawNode::create();
dot->drawDot(Vec2(0,10,1.0,1.0));
addChild(rect);
rect->addChild(dot);
rect->setPosition(visibleSize / 2);
dot->setPosition(Vec2(10,10));//本地空间
rect->setContentSize(Size(300,300));
rect->setAnchorPoint(Vec2(0.5,0.5));
schedule([dot,rect](float f){
rect->setRotation(rect->getRotation() + 1);
auto p = dot->convertToWorldSpace(Vec2(0,0));
CCLOG("%f,%f",p.x,p.y);
},"Test");
return true;
}
原文链接:https://www.f2er.com/cocos2dx/342331.html