Box2D and wrapping worlds

对着背影说爱祢 提交于 2019-12-13 03:17:22

问题


I really stuck at implementing wrapping world with Box2D. I want to create game object appearing from left when it hides to the right and vice versa and the same for top-down.

My idea is to use object wich contains NSArray with 9 elements for superposition matrix (it's a quantum state when object exists at different locations at the same time, isn't it?).

Every element must contain the body. It covers all situations and has a more clear logic for me. For example, if my object doesn't touch any edges it holds only one "center" body (4th element). If it touches right edge i add "left-warped" body to 3rd element.

The main problem is creating body without adding to the world. First i must just add it to the array and then safely proccess adding outside of

world->Step();

For example… In collision logic (pseudocode)

[self.bodies addObjectAtIndex:index] = [self masterBody];

where

-(b2Body*)masterBody;

returns a template (master copy) for object body. But i can't write this method because there is only one

world->CreateBody(&bodyDef);

method and i must use it to create fixtures.

I can create separately only definition of the body, but full creation (with fixtures) can't be made without adding it to the world. But adding to the world msut be processed outside physics step.

Any ideas? Use separate world for storing template bodies of every game object?

来源:https://stackoverflow.com/questions/8985692/box2d-and-wrapping-worlds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!