-
FreddiewLikes 0Problem Description
I used several sprites to create a level with cocostudio. I cloned the sprite in the scene, also call with the same name and same tag. Now I call the sprites from the code to add physical but my problem is that the physical only adds to the first cloned sprite but the others not.
As I do so that all cloned sprites have physics without having to call one by one.
example:
A ground called "Ground" in the cocostudio, now this ground is cloned many times throughout the scene but when you add physical from the code only the first sprite called "Ground" is added the physical and the others not.
I call the sprite:
Sprite *ground = (Sprite *)rootNode->getChildByName("Ground");
and so I add the physical:
auto groundBody = PhysicsBody::createBox(ground->getContentSize());
groundBody->setCollisionBitmask(GROUND_COLLIDER);
groundBody->setContactTestBitmask(true);
groundBody->setDynamic(false);
ground->setPhysicsBody(groundBody);and this is the result:
-
Sonar Systems adminLikes 0
You can’t clone the physics bodies.
-
FreddiewLikes 0
Yes, but there must be a way for all objects called by the same name or having the same tag have physics without calling one by one.
-
Sonar Systems adminLikes 0
Do you mean use a single body for multiple objects?
-
FreddiewLikes 0
Exactly, but those multiple objects are the same, if you look at the image that we publish, the object with physics is the same as the next and these objects they have configured with the same name in cocostudio so that when called from the code and we add them the physics body is also added to all objects with the same name. But the physics body just applied to the first object as seen in the image.
-
Sonar Systems adminLikes 0
As far as we are aware they can’t be cloned/copied
-
FreddiewLikes 0
So the only way is to put different names and add physics one by one?
Thanks so much.
-
Sonar Systems adminLikes 0
yh unfortunately
Login to reply