如何在 cocos2dx 中从 DrawNode 中删除色点,但我不想从父级中删除孩子。只需删除它的某些点
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子项,并使用一个子项绘制多个点。那么我怎样才能从绘图节点中删除点,只需删除点并将绘图节点保留在这里。
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;
}
}
};
};
相关文章:
- 将数组的地址分配给变量并删除
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- C/C++编译器通常会删除重复的库吗
- 从链接列表c++中删除一个项目
- C++如何通过用户输入删除列表元素
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 是否需要删除包含对象的"pair"?
- 如何在自删除后将对象设置为nullptr
- 迭代时从向量和内存中删除对象
- 使用函数"remove"删除重复元素
- 如何从多映射中删除特定的重复项
- 运算符C++ "delete []"仅删除 2 个前值
- 删除指向指针的指针是运行时错误吗
- 将指针设置为"nullptr"并不能防止双重删除?
- 为什么示例代码访问IUnknown中已删除的内存
- 如何通过 getter 函数删除矢量的元素?
- 如果是双重注册,如何从Boost树中删除孩子
- 从二进制搜索树中删除只有一个孩子的节点
- 正在删除有两个孩子的目标
- 如何在 cocos2dx 中从 DrawNode 中删除色点,但我不想从父级中删除孩子。只需删除它的某些点