本文整理汇总了C++中DrawNode::getChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawNode::getChildren方法的具体用法?C++ DrawNode::getChildren怎么用?C++ DrawNode::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawNode
的用法示例。
在下文中一共展示了DrawNode::getChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lookAt
///all screen move functions should use this
void HelloWorld::lookAt(Vec2 pos)
{
Vec2 visible = Director::getInstance()->getVisibleSize();
this->setPosition(-1*(pos - visible/2));
protractor->setPosition(lookingAt());
notifier->setPosition(lookingAt());
//draw grid
Vec2 botleft = screenspaceToWorldspace(Vec2::ZERO);
Vec2 topright = screenspaceToWorldspace(visible);
Vec2 drawSpaceBotLeft = botleft - GRID_LABEL_SPACING;
Vec2 drawSpaceTopRight = topright + GRID_LABEL_SPACING;
DrawNode* gridSprite = (DrawNode*)getChildByName("gridSprite");
if (gridSprite)
{
gridSprite->clear();
std::vector<std::string> toRemove;
for (auto child : gridSprite->getChildren())
{
if (!onScreen(child->getPosition(), Vec2(GRID_LABEL_SPACING)))
toRemove.push_back(child->getName());
}
for (auto name : toRemove)
{
gridSprite->removeChildByName(name);
}
}
else
{
gridSprite = DrawNode::create();
gridSprite->setName("gridSprite");
addChild(gridSprite, 0);
}
//vertical lines
for (int i= drawSpaceBotLeft.x; i<drawSpaceTopRight.x; i++)
{
if(i % (int)GRID_SPACING.x)
continue;
gridSprite->drawSegment(Vec2(i, drawSpaceBotLeft.y), Vec2(i, drawSpaceBotLeft.y+visible.y+2*GRID_LABEL_SPACING.y),
GRID_LINE_THICKNESS, Color4F(1,1,1,0.1));
if(!(i % (int)GRID_LABEL_SPACING.x))
{
std::string txt = std::to_string(i);
auto label = gridSprite->getChildByName("v" + txt);
if (!label)
{
label = Label::createWithTTF(txt, "fonts/arial.ttf", GRID_LABEL_SIZE);
label->setName("v" + txt);
gridSprite->addChild(label);
}
label->setPosition(Vec2(i, topright.y - GRID_LABEL_SIZE * 2));
}
}
//horizontal lines
for (int i= drawSpaceBotLeft.y; i<drawSpaceTopRight.y; i++)
{
if(i % (int)GRID_SPACING.y)
continue;
gridSprite->drawSegment(Vec2(drawSpaceBotLeft.x, i), Vec2(drawSpaceBotLeft.x+visible.x + 2 * GRID_LABEL_SPACING.x, i),
GRID_LINE_THICKNESS, Color4F(1,1,1,0.1));
if(!(i % (int)GRID_LABEL_SPACING.y))
{
std::string txt = std::to_string(i);
auto label = gridSprite->getChildByName("h" + txt);
if (!label)
{
label = Label::createWithTTF(txt, "fonts/arial.ttf", GRID_LABEL_SIZE);
label->setName("h" + txt);
gridSprite->addChild(label);
}
label->setPosition(Vec2(botleft.x + GRID_LABEL_SIZE * 2, i));
}
}
repaintCursor();
Commorose* c = (Commorose*)commorose;
c->setPosition(screenspaceToWorldspace(c->getPositionOnScreen()));
}