Add physics to sprites called from Cocostudio?

  • Freddiew
    Likes 0

    Problem 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 admin
    Likes 0

    You can’t clone the physics bodies.

  • Freddiew
    Likes 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 admin
    Likes 0

    Do you mean use a single body for multiple objects?

  • Freddiew
    Likes 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 admin
    Likes 0

    As far as we are aware they can’t be cloned/copied 

  • Freddiew
    Likes 0

    So the only way is to put different names and add physics one by one?

    Thanks so much.

  • Sonar Systems admin
    Likes 0

    yh unfortunately

Login to reply