本文整理汇总了C++中DrawNode::drawLine方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawNode::drawLine方法的具体用法?C++ DrawNode::drawLine怎么用?C++ DrawNode::drawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawNode
的用法示例。
在下文中一共展示了DrawNode::drawLine方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: color
TouchPoint(const Vec2 &touchPoint, const Color3B &touchColor)
{
m_point = touchPoint;
DrawNode* drawNode = DrawNode::create();
auto s = Director::getInstance()->getWinSize();
Color4F color(touchColor.r / 255.0f, touchColor.g / 255.0f, touchColor.b / 255.0f, 1.0f);
drawNode->drawLine(Vec2(0, touchPoint.y), Vec2(s.width, touchPoint.y), color);
drawNode->drawLine(Vec2(touchPoint.x, 0), Vec2(touchPoint.x, s.height), color);
drawNode->drawDot(touchPoint, 3, color);
addChild(drawNode);
}
示例2: addUnderline
void ITools::addUnderline(void* vv)
{
Text* tt = (Text*)vv;
Color4B color = tt->getTextColor();
DrawNode* drawLine = DrawNode::create();
drawLine->drawLine(Vec2(0,0), Vec2(tt->getContentSize().width,0), Color4F((float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255));
drawLine->setPosition(Vec2(0,2));
tt->addChild(drawLine);
}
示例3: 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);
}
}
示例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: drawDebug
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {
Director* director = Director::getInstance();
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
DrawNode* drawNode = DrawNode::create();
if (_debugSlots) {
// Slots.
// DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
glLineWidth(1);
Vec2 points[4];
V3F_C4B_T2F_Quad quad;
for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
spSlot* slot = _skeleton->drawOrder[i];
if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
points[0] = Vec2(_worldVertices[0], _worldVertices[1]);
points[1] = Vec2(_worldVertices[2], _worldVertices[3]);
points[2] = Vec2(_worldVertices[4], _worldVertices[5]);
points[3] = Vec2(_worldVertices[6], _worldVertices[7]);
drawNode->drawPoly(points, 4, true, Color4F::BLUE);
}
}
if (_debugBones) {
// Bone lengths.
glLineWidth(2);
for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
spBone *bone = _skeleton->bones[i];
float x = bone->data->length * bone->a + bone->worldX;
float y = bone->data->length * bone->c + bone->worldY;
drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED);
}
// Bone origins.
auto color = Color4F::BLUE; // Root bone is blue.
for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
spBone *bone = _skeleton->bones[i];
drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color);
if (i == 0) color = Color4F::GREEN;
}
}
drawNode->draw(renderer, transform, transformFlags);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
示例6: drawPath
void HelloWorld::drawPath(const std::vector<TileData*>& path)
{
this->removeChildByName(DrawNodeStr);
DrawNode* drawNode = DrawNode::create();
Size mapSize = m_gamemap->getMapSize();
Size tilesize = m_gamemap->getTileSize();
int mapheight = mapSize.height * tilesize.height;
int origin_x = path[0]->position().first * tilesize.width + tilesize.width / 2;
int origin_y = path[0]->position().second * tilesize.height + tilesize.height / 2;
Vec2 origin(origin_x, mapheight - origin_y);
for (int index = 1; index < path.size(); ++index)
{
int destination_x = path[index]->position().first * tilesize.width + tilesize.width / 2;
int destination_y = path[index]->position().second * tilesize.height + tilesize.height / 2;
Vec2 destination(destination_x, mapheight - destination_y);
drawNode->drawLine(origin, destination, Color4F(0.0, 1.0, 0.0, 1.0));
origin = destination;
}
this->addChild(drawNode, 0, DrawNodeStr);
}
示例7: theGame
Waypoint::Waypoint(HelloWorld *theGame, const Vec2& location, Waypoint *nextWaypoint) : theGame(theGame), nextWaypoint(nextWaypoint)
{
this->myPosition = location;
this->setPosition(cocos2d::Vec2::ZERO);
#ifdef DRAW_DEBUG_INFO
DrawNode *circle = DrawNode::create();
circle->drawCircle(location, 6, 360, 30, false, Color4F::GREEN);
this->addChild(circle);
DrawNode *circle2 = DrawNode::create();
circle2->drawCircle(location, 2, 360, 30, false, Color4F::GREEN);
this->addChild(circle2);
if (nextWaypoint) {
DrawNode *line = DrawNode::create();
line->drawLine(this->myPosition, nextWaypoint->myPosition, Color4F::GREEN);
this->addChild(line);
}
#endif
theGame->addChild(this);
}
示例8: render
void GLView::render()
{
m_render = Director::getInstance()->getRenderer();
initTexture2d();
ClippingNode* clippingNode = ClippingNode::create();
Sprite* stencil = Sprite::createWithFileName("E://5.png");
Sprite* back = Sprite::createWithFileName("E://3.png");
// back->setPosition(200, 10);
stencil->setPosition(200, 10);
clippingNode->setSprite(back);
clippingNode->setStencil(stencil);
clippingNode->setAlpha(1.0);
bool saveImage = false; //截图功能 RenderTexure
bool testClippingNode = false; //遮罩功能ClippingNode
bool testDrawNodePoint = false; //DrawNode功能之画点
bool testDrawNodeLine = true; //DrawNode功能之画线
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(_mainWindow))
{
glClearColor(0.2, 0.2, 0.2, 1);
glClear(GL_COLOR_BUFFER_BIT);
if (saveImage)
{
/* 测试 RenderTexture
Size size = Director::getInstance()->getWinSize();
RenderTexture* renderTexure = RenderTexture::create(20,20);
renderTexure->begin();
renderTexure->end();
renderTexure->onBegin();
for (Sprite* sprite : _sprites)
{
sprite->setPosition(20, 20);
sprite->visit(&m_render);
sprite->setPosition(0, 0);
}
m_render.draw();
renderTexure->onEnd();
renderTexure->saveToFile("1.png");
saveImage = false;
CC_SAFE_DELETE(renderTexure);*/
}
else if (testClippingNode){
/* 测试ClippingNode
auto _director = Director::getInstance();
clippingNode->onBeforeVisit();
stencil->visit(&m_render);
m_render.draw();
clippingNode->onAfterVisitStencil();
back->visit(&m_render);
m_render.draw();
clippingNode->onAfterVisit();*/
} else if (testDrawNodePoint)
{
DrawNode* drawNode = DrawNode::create();
CHECK_GL_ERROR_DEBUG();
for (int i = 1; i <= 100; i++)
{
drawNode->drawPoint(Vec2(100+i, 100), 1, Color4F(255.0, 0, 0, 255.0));
}
drawNode->onDrawPoinit();
// CHECK_GL_ERROR_DEBUG();
}else if (testDrawNodeLine)
{
DrawNode* drawNode = DrawNode::create();
CHECK_GL_ERROR_DEBUG();
drawNode->drawLine(Vec2(100, 100), Vec2(200, 200), Color4F(255.0, 0, 0, 255.0));
drawNode->drawLine(Vec2(100, 200), Vec2(200, 100), Color4F(255.0, 0, 0, 255.0));
drawNode->onDrawLine();
}
else{
for (Sprite* sprite : _sprites)
{
sprite->visit(&m_render);
}
m_render.draw();
}
/* Swap front and back buffers */
glfwSwapBuffers(_mainWindow);
/* Poll for and process events */
glfwPollEvents();
}
}
示例9: init
// UIListViewTest_Magnetic
bool UIListViewTest_Magnetic::init()
{
if(!UIScene::init())
{
return false;
}
Size layerSize = _uiLayer->getContentSize();
_titleLabel = Text::create("Magnetic scroll", "fonts/Marker Felt.ttf", 32);
_titleLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_titleLabel->setPosition(Vec2(layerSize / 2) + Vec2(0, _titleLabel->getContentSize().height * 3.15f));
_uiLayer->addChild(_titleLabel, 3);
// Create the list view
_listView = ListView::create();
_listView->setDirection(getListViewDirection());
_listView->setBounceEnabled(true);
_listView->setBackGroundImage("cocosui/green_edit.png");
_listView->setBackGroundImageScale9Enabled(true);
_listView->setContentSize(layerSize / 2);
_listView->setScrollBarPositionFromCorner(Vec2(7, 7));
_listView->setItemsMargin(2.0f);
_listView->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_listView->setPosition(layerSize / 2);
_uiLayer->addChild(_listView);
// Guide line for center align
{
DrawNode* pNode = DrawNode::create();
Vec2 center = layerSize / 2;
if(getListViewDirection() == ScrollView::Direction::HORIZONTAL)
{
float halfY = 110;
pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1));
}
else
{
float halfX = 150;
pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1));
}
pNode->setLineWidth(2);
_uiLayer->addChild(pNode);
}
// Show the indexes of items on each boundary.
{
for(int i = 0; i < 5; ++i)
{
_indexLabels[i] = Text::create(" ", "fonts/Marker Felt.ttf", 12);
_indexLabels[i]->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_uiLayer->addChild(_indexLabels[i]);
}
float deltaX = 145, deltaY = 90;
_indexLabels[0]->setPosition(_uiLayer->getContentSize() / 2 + Size(-deltaX, 0)); // left
_indexLabels[1]->setPosition(_uiLayer->getContentSize() / 2 + Size(deltaX, 0)); // right
_indexLabels[2]->setPosition(_uiLayer->getContentSize() / 2 + Size(0, deltaY)); // top
_indexLabels[3]->setPosition(_uiLayer->getContentSize() / 2 + Size(0, -deltaY)); // bottom
_indexLabels[4]->setPosition(_uiLayer->getContentSize() / 2 + Size(deltaX, deltaY)); // center
// Callback
_listView->ScrollView::addEventListener([this](Ref* ref, ScrollView::EventType eventType) {
ListView* listView = dynamic_cast<ListView*>(ref);
if(listView == nullptr || eventType != ScrollView::EventType::CONTAINER_MOVED)
{
return;
}
auto left = listView->getLeftmostItemInCurrentView();
auto right = listView->getRightmostItemInCurrentView();
auto top = listView->getTopmostItemInCurrentView();
auto bottom = listView->getBottommostItemInCurrentView();
auto center = listView->getCenterItemInCurrentView();
_indexLabels[0]->setString(StringUtils::format("Left\nindex=%zd", listView->getIndex(left)));
_indexLabels[1]->setString(StringUtils::format("RIght\nindex=%zd", listView->getIndex(right)));
_indexLabels[2]->setString(StringUtils::format("Top index=%zd", listView->getIndex(top)));
_indexLabels[3]->setString(StringUtils::format("Bottom index=%zd", listView->getIndex(bottom)));
_indexLabels[4]->setString(StringUtils::format("Center\nindex=%zd", listView->getIndex(center)));
});
}
// Initial magnetic type
_listView->setMagneticType(ListView::MagneticType::NONE);
_titleLabel->setString("MagneticType - NONE");
// Magnetic change button
auto pButton = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
pButton->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
pButton->setScale(0.8f);
pButton->setPosition(Vec2(layerSize / 2) + Vec2(130, -60));
pButton->setTitleText("Next Magnetic");
pButton->addClickEventListener([this](Ref*) {
ListView::MagneticType eCurrentType = _listView->getMagneticType();
ListView::MagneticType eNextType;
std::string sString;
if(eCurrentType == ListView::MagneticType::NONE)
{
eNextType = ListView::MagneticType::CENTER;
sString = "CENTER";
//.........这里部分代码省略.........
示例10: loadAssets
void GameController::loadAssets()
{
//background
background = Sprite::create("score.png");
background->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2));
background->setAnchorPoint(Vec2(0.5, 0.5));
background->setScale(1.7);
this->addChild(background);
//layer for joining player parts
player_layer = Layer::create();
//initializing archer instance
Archer * archer = Archer::create();
//initializing player body sprites
playerBottomHalf = archer->getPlayerLowerBody();
playerUpperHalf = archer->getPlayerUpperBody();
playerHand = archer->getPlayerArm();
playerBottomHalf->setAnchorPoint(Vec2(0, 0));
//adding player body sprites to the player layer
player_layer->addChild(playerBottomHalf);
//setting player layer position on the screen
player_layer->setPosition(Vec2(origin.x + (visibleSize.width * 0.8) , origin.y + (visibleSize.height * 0.04)));
player_layer->setContentSize(Size(MAX(playerBottomHalf->getContentSize().width, playerUpperHalf->getContentSize().width) , playerBottomHalf->getContentSize().height + playerUpperHalf->getContentSize().height/2));
this->addChild(player_layer);
//setting player upper body layer
upper_body_layer = Layer::create();
upper_body_layer->setContentSize(playerUpperHalf->getContentSize());
upper_body_layer->ignoreAnchorPointForPosition(false);
upper_body_layer->setAnchorPoint(Vec2(1,0.5));
upper_body_layer->setPosition(Vec2(playerBottomHalf->getContentSize().width * 0.8, playerBottomHalf->getContentSize().height ));
//adding the laft half of the upper body to the upper layer
upper_body_layer->addChild(playerUpperHalf);
playerUpperHalf->setPosition(Vec2(0, 0));
playerUpperHalf->setAnchorPoint(Vec2(0 , 0));
//adding the arm to the upper body layer
upper_body_layer->addChild(playerHand);
playerHand->setPosition(Vec2(playerBottomHalf->getContentSize().width/2, playerUpperHalf->getContentSize().height * 0.55));
playerHand->setAnchorPoint(Vec2(0, 1));
//adding the bow part
DrawNode* bowPart = DrawNode::create();
upper_body_layer->addChild(bowPart);
bowPart->drawLine(Vec2(playerUpperHalf->getContentSize().width * 0.44, playerUpperHalf->getContentSize().height), Vec2(playerUpperHalf->getContentSize().width * 0.44, 0), Color4F::WHITE);
//initializing arrow
arrow = Sprite::create("arrow.png");
upper_body_layer->addChild(arrow);
arrow->setPosition(Vec2(0, upper_body_layer->getContentSize().height/2));
//adding the upper layer to the main player layer
player_layer->addChild(upper_body_layer);
//for storing player arm base position
player_arm_position_x = playerHand->getPosition().x;
//for storing arrow base position
arrow_position_x = arrow->getPosition().x;
arrow_position_y = arrow->getPosition().y;
//setting up sprite for touch start touch position
touch_start_circle = Sprite::create("white_dot.png");
this->addChild(touch_start_circle);
touch_start_circle->setVisible(false);
//setting up sprite for touch end position
touch_end_circle = Sprite::create("white_dot.png");
this->addChild(touch_end_circle);
touch_end_circle->setVisible(false);
//layer for board
board_layer = Layer::create();
this->addChild(board_layer);
//initializing board instance
Board * target= Board::create();
//initializing board sprite
board = target->getBoard();
board_layer->addChild(board);
board->setAnchorPoint(Vec2(0, 0));
//.........这里部分代码省略.........