Cocos2dx:删除运动体一旦他们离开屏幕
Cocos2dx : Deleting kinematic bodies once they are off screen
我正在尝试创造一款平台游戏。在我的游戏中,随机平台出现并从屏幕的右侧移动到左侧。
Using :
b2Vec2 impulse = b2Vec2(-5, 0);
platformBody->SetLinearVelocity(impulse);
但是当我看到我的统计数据时,call/countRef(统计数据的第一行)的数量总是随着新平台从右向左移动而增加。我想知道如何才能删除现有的平台,一旦他们已经移动通过左屏幕(屏幕外)。我所有的平台都是b2_kinematic body (Box2D)。
编辑答案:
我通过以下方法解决了这个问题:
for(std::vector::size_type I = 0;= m_platforms.size();我+ +)
{
if (m_platforms[i]->GetPosition().x < 0.0f && m_platforms[i]->GetType() == b2_kinematicBody) { CCSprite *sprite = (CCSprite *) m_platforms[i]->GetUserData(); sprite->removeFromParentAndCleanup(true); world->DestroyBody(m_platforms[i]); } }
您可以在主循环中检查您的body是否在屏幕之外,如果是,则销毁它们。的东西。
if (platformBody->GetPosition().x < SCREEN_X_LIMIT) {
world->DestroyBody(platformBody);
// Also, remove attached sprite if exists
}
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 即使没有满足他们的条件,我也无法通过一些 do-while 循环
- 在函数范围内在堆栈上分配的数组在离开函数时是否总是被释放?
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- 如何使用递归循环我的代码(当用户输入无效输入时,它会再次提示他们)?
- 我怎样才能有 2 个程序并让用户选择他们想要使用的程序?
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 离开范围后如何保护局部变量的值?
- C++程序过早地离开我的 for 循环
- 将"Compass"与相机旋转隔离开GL
- 我的boost managed_shared_memory在离开作用域时似乎不会从内存空间中取消映射
- 即使在离开作用域后,如何访问在堆上分配的变量C++?
- 离开方法时重置变量值
- 全局静态生存期?他们会让你的程序崩溃吗?
- 如何正确消除继承类型定义的歧义?以及如何简化他们的创作?
- 程序在遍历所有值之前离开循环. 数组的
- 鼠标离开 GLFW窗口后触发 GLFW 鼠标回调?
- 我的单例中的数组在离开函数后没有保留信息,然后在尝试再次访问信息时崩溃
- C++:告诉用户输入 A、B 或 C,但如果他们输入不同的字符怎么办?
- Cocos2dx:删除运动体一旦他们离开屏幕