I need to create joint between two bodies in layer. Joints are to be added in physics world. How can i access physics world in layer?
相关问题
- Bad access to memory using strcat
- Error SSL archive symbol table (run ranlib)
- Connecting a maze/grid's walls so all are inte
- SpriteKit score is acting randomly
- Error when trying to compile using sqlite3_open in
相关文章
- Circle/rectangle collision response
- [cocos2dx android]Rendering CCSprite using raw dat
- Rounded Corners Rect in Cocos 2d-x with Bezier
- AdMob Interstitial Cocos2d-x WP8
- Check If animation is running in cocos2d-x
- How to handle multiple simultaneous elastic collis
- ant debug, and sdk.dir
- Problem with collision detection of a fast moving
My JavaScript implementation. Hope it will help.
you have four options:
1)- override Layer::onEnter() or onEnterTransitionDidFinish () methods then access from theme like this:
2)- create a custom Layer::createScene() method then access from Layer::init() like this:
3)- add a PhysicsWorld getter method to the director (involves some library code customization's):
first go to CCDirector.h and then add a forward declaration of the scene class under NS_CC_BEGIN like this:
then go to the private section of the Director class and add these two lines like this:
then go to the public section of the Director class and add this getter method like this:
this is an overview of the changes made in CCDirector.h file:
so after that we go to CCScene.cpp into a method with this signature (bool Scene::initWithPhysics()) in it you will find a call to PhysicsWorld::construct(this) add just right after that method call this line:
and this should be the overview of what we did in CCScene.cpp:
now as soon as Scene::createWithPhysics() gets called anywhere the director will get a copy of the PhysicsWorld pointer which can be accessed using our director getWorld() method anywhere anytime!! (because the director is a singleton as you know) and thats all without exposing _myPhysicsWorld to the user meaning he can only read _myPhysicsWorld from the outside!!
4)- make your own Custom PhysicsWorld class and since PhysicsWorld::construct() is protected which means it can be easily inherited.
now you can use it like this:
remember that you can even make it a singleton class if you want to!
Edit:
I forgot to mention that there is another good solution in here:
http://discuss.cocos2d-x.org/t/physics-joint-distance-problem/17926/2