protected void onDraw(Canvas canvas) {//view 里的绘制入口
/** 遍历box2d world中的body,并绘制其形状 */
for (Body b = world.getBodyList(); b != null; b = b.getNext()) {
xf.set(b.getTransform());
for (Fixture f = b.getFixtureList(); f != null; f = f.getNext()) {
if (b.isActive() == false) {
color.set(0.5f, 0.5f, 0.3f);
drawShape(canvas, f, xf, color);
} else if (b.getType() == BodyType.STATIC) {
color.set(0.5f, 0.9f, 0.3f);
drawShape(canvas, f, xf, color);
} else if (b.getType() == BodyType.KINEMATIC) {
color.set(0.5f, 0.5f, 0.9f);
drawShape(canvas, f, xf, color);
} else if (b.isAwake() == false) {
color.set(0.5f, 0.5f, 0.5f);
drawShape(canvas, f, xf, color);
} else {
color.set(0.9f, 0.7f, 0.7f);
drawShape(canvas, f, xf, color);
}
}
}
}
/****************************************/
/***** drawBox2dWorld ****/
/****************************************/
private final Transform xf = new Transfor
JBox2D For Android - 用canvas绘制shape
最新推荐文章于 2024-10-04 11:56:13 发布
本文介绍了如何在Android中利用JBox2D库通过canvas来绘制形状。作者通过参考JBox2D的Java示例和官方手册进行学习,并提供了一个演示示例的下载链接。
摘要由CSDN通过智能技术生成