#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) glLineWidth(2.0f); //glEnable(GL_LINE_WIDTH); #else glLineWidth(2.0f); glEnable(GL_LINE_SMOOTH); #endif ccDrawColor4F(1.0f,1.0f,0.5f); BattleTerrain *terrain = BattleScene::getCurrentScene()->getTerrain(); if(!terrain) return; for (int i = 0; i < terrain->getWidth(); ++i) { GridPosition down = GridPosition(i,0); GridPosition up = GridPosition(i,BattleScene::getCurrentScene()->getTerrain()->getHeight()); CCPoint downPoint = ccp(GridUtil::sharedGridUtil().gridEdgeToPix(down).x,GridUtil::sharedGridUtil().gridEdgeToPix(down).y); CCPoint upPoint = ccp(GridUtil::sharedGridUtil().gridEdgeToPix(up).x,GridUtil::sharedGridUtil().gridEdgeToPix(up).y); ccDrawLine(downPoint,upPoint); }
新项目的方式,重写新的draw函数,在onDraw中绘制
void SceneLayer::draw(Renderer *renderer,const Mat4& transform,uint32_t flags) { _customCommand.init(_globalZOrder,transform,flags); _customCommand.func = CC_CALLBACK_0(SceneLayer::onDraw,this,flags); renderer->addCommand(&_customCommand); }
先将drawNode节点添加到父节点中
_drawNode = CCDrawNode::create(); addChild(_drawNode);
_drawNode->clear();
_drawNode->clear(); for (int i = 0; i < terrain->getWidth(); ++i) { GridPosition down = GridPosition(i,GridUtil::sharedGridUtil().gridEdgeToPix(up).y); _drawNode->drawLine(downPoint,upPoint,ccColor4F(1.0f,0.5f)); //ccDrawLine(downPoint,upPoint); }原文链接:https://www.f2er.com/cocos2dx/340214.html