当前位置: 首页>>代码示例>>C++>>正文


C++ DrawNode::getChildByName方法代码示例

本文整理汇总了C++中DrawNode::getChildByName方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawNode::getChildByName方法的具体用法?C++ DrawNode::getChildByName怎么用?C++ DrawNode::getChildByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DrawNode的用法示例。


在下文中一共展示了DrawNode::getChildByName方法的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()));
}
开发者ID:dare0021,项目名称:October3rd,代码行数:78,代码来源:HelloWorldScene.cpp


注:本文中的DrawNode::getChildByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。