本文整理汇总了C++中DrawNode::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawNode::clear方法的具体用法?C++ DrawNode::clear怎么用?C++ DrawNode::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawNode
的用法示例。
在下文中一共展示了DrawNode::clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onTouchEnded
void MainGame::onTouchEnded(Touch* touch, Event* event)
{
CCLOG("touch ended.");
DrawNode* node = (cocos2d::DrawNode*) this->getChildByTag(100);
node->clear();
}
示例2: redraw
void redraw()
{
drawNode->clear();
vector<Unit>::iterator itor;
for (itor = unitList.begin(); itor != unitList.end(); ++itor)
{
drawNode->drawCircle(itor->pos, 10, 360, 10, false, Color4F::BLUE);
drawNode->drawLine(itor->pos, itor->pos + itor->velocity * 30, Color4F::GREEN);
}
}
示例3: setSquareStencil
void ClippingNode::setSquareStencil()
{
isSquareStencil = true;
if(getStencil() == nullptr || dynamic_cast<DrawNode*>(getStencil()) == nullptr)
{
setStencil(DrawNode::create());
//addChild(getStencil()); //If you need to see what the stencil is like, for debug purpose
}
DrawNode* stencil = (DrawNode*)getStencil();
stencil->clear();
Vec2 rectangle[4];
rectangle[0] = Vec2(0, 0);
rectangle[1] = Vec2(this->getContentSize().width / this->getScaleX(), 0);
rectangle[2] = Vec2(this->getContentSize().width / this->getScaleX(), this->getContentSize().height / this->getScaleY());
rectangle[3] = Vec2(0, this->getContentSize().height / this->getScaleY());
Color4F white(1, 1, 1, 1);
stencil->drawPolygon(rectangle, 4, white, 1, white);
}
示例4: debugDraw
void Sprite::debugDraw(bool on)
{
DrawNode* draw = getChildByName<DrawNode*>("debugDraw");
if(on)
{
if(!draw)
{
draw = DrawNode::create();
draw->setName("debugDraw");
addChild(draw);
}
draw->setVisible(true);
draw->clear();
//draw lines
auto last = _polyInfo.triangles.indexCount/3;
auto _indices = _polyInfo.triangles.indices;
auto _verts = _polyInfo.triangles.verts;
for(unsigned int i = 0; i < last; i++)
{
//draw 3 lines
Vec3 from =_verts[_indices[i*3]].vertices;
Vec3 to = _verts[_indices[i*3+1]].vertices;
draw->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
from =_verts[_indices[i*3+1]].vertices;
to = _verts[_indices[i*3+2]].vertices;
draw->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
from =_verts[_indices[i*3+2]].vertices;
to = _verts[_indices[i*3]].vertices;
draw->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN);
}
}
else
{
if(draw)
draw->setVisible(false);
}
}
示例5: 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()));
}