cocos2dx中如何去掉DrawNode的色点,又不想把parent的removeChild去掉。只需删除其中的一些点

how can I remove the color point from DrawNode in cocos2dx, but I don't want to removeChild from parent. Just remove some point of it

我在我的代码中添加了一个 drawNode child 并使用一个 child 绘制许多 points.Then 我怎样才能从 drawNode 中删除点,只需删除点并将 drawNode 保留在这里。

    auto m_pDrawPoint = DrawNode::create();
    this->addChild(m_pDrawPoint);                   
    for (int i = 0; i < 10; i++)
    {
      m_pDrawPoint->drawPoint(screenP[i], 20, Color4F::GREEN);

    }
     // I  want remove some of  point Like remove the screenP[3] 

cocos2d-x中没有clearPoint。当调用 DrawNode::drawPoint 时,drawNode 只是将位置、点大小和颜色保存在一个裸数组上。除非覆盖 DrawNode,否则您无权访问此数组。如果你想清除一些点,使用DrawNode::clear删除点然后重新绘制你需要的点是个好主意。

//编辑

    auto m_pDrawPoint = DrawNode::create();
    this->addChild(m_pDrawPoint);                   
    for (int i = 0; i < 10; i++)
    {
      m_pDrawPoint->drawPoint(screenP[i], 20, Color4F::GREEN);
      m_points.push_back(screenP[i]);
    }

void Foo::removePoint(const Vec2& point){
    for(int i=0; i<=m_points.size(); i++){
        if(point==m_points[i]){
            //this is a trick
            m_points[i] = m_points[m_points.size()];
            m_points.pop_back();
            break;
        }
    }
    m_pDrawPoint.drawPoints(m_points.data(), m_points.size(),20, Color4F::GREEN);
}

子类化 DrawNode 似乎更简单。

class MyDrawNode: public DrawNode{
public:
    void removePoint(const Vec2& point){
        for(int i=0; i<_bufferCountGLPoint; i++){
            V2F_C4B_T2F *p = (V2F_C4B_T2F*)(_bufferGLPoint + i);
            // point==p->vertices doesn't work as expected sometimes.
            if( (point - p->vertices).lengthSquared() < 0.0001f ){
                *p = _bufferGLPoint + _bufferCountGLPoint - 1;
                _bufferCountGLPoint++;
                break;
            }
        }
    };

};