Cocos2d + Box2d - 如何调试/显示身体?

2024-08-11移动开发问题
2

本文介绍了Cocos2d + Box2d - 如何调试/显示身体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我使用 Cocos2d (2.0) 和随附的 Box2d 创建了一个非常简单的设置.我的世界中有一些实体,但还没有与它们关联的精灵,我想调试它们的方向、位置等.

I've created a pretty simple setup using Cocos2d (2.0) and Box2d that comes packaged with it. I have a few bodies in my world, but don't have sprites linked up with them yet and I want to debug their orientations, positions, etc.

这似乎是一项非常标准的任务,但我不知道如何轻松地做到这一点.根据我的研究,它似乎与这些方法有关:

This seems like a pretty standard task, but I could not find out how to do this easily. From my research it seems related to these methods:

_world->SetDebugDraw(...);
_world->DrawDebugData(...);
// and the GLES-Render class

帮助?

推荐答案

我想出来以防万一其他人偶然发现.

I figured it out in case anyone else stumbles across this.

  1. 在您的初始化中,您要创建一个调试绘图对象(GLESDebugDraw 自带 Cocos2d+Box2d).
  2. 设置标志以指定您想要绘制的内容(形状、重心、关节等).
  3. 将其分配给您的世界对象.

b2Draw *debugDraw = new GLESDebugDraw(PTM_RATIO);

debugDraw->SetFlags(GLESDebugDraw::e_shapeBit);

_world->SetDebugDraw(debugDraw);

那么,诀窍就是你需要重写ccLayer的draw方法并调用:

Then, the trick is that you need to override ccLayer's draw method and call:

_world->DrawDebugData();

它必须在 draw 方法中,否则这将不起作用.我最初尝试将它放在我自己的预定方法中(我在其中调用 _world->step()),但这没有用.

It must be in the draw method otherwise this won't work. I initially tried to put it in my own scheduled method (where I call _world->step()) and this did not work.

这篇关于Cocos2d + Box2d - 如何调试/显示身体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7