0
\$\begingroup\$

I want to make my character respawn in the last Checkpoint he has reached. I've already stored the position of the checkpoint but I'm not very sure of how to set that position to the Sprite/Body of the character to make it appear in the position I want to. Do I have to use the Sprite or the Body? Here's how I initialize my character:

    mPlayerSprite = new AnimatedSprite(mapOffset, 0, playerTexture);

    final FixtureDef mPlayerFixtureDef = PhysicsFactory.createFixtureDef(0, 0f, 0f, false, CATEGORYBIT_PLAYER, MASKBITS_PLAYER, (short) 0);
    mPlayerBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, mPlayerSprite, BodyType.DynamicBody, mPlayerFixtureDef);

    mPlayerSprite.setUserData(playerName);
    mPlayerBody.setUserData(playerName);
    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mPlayerSprite, mPlayerBody, true, false));

    mScene.attachChild(mPlayerSprite);
    mEntityList.add(mPlayerSprite);

Thanks in advance!

\$\endgroup\$
1
\$\begingroup\$

If you use body, then 'sprite.setPosition(..)' does not work. You should 'body.setTransform()'

float PMR = PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;
mPlayerBody.setTransform(checkPointImage.getX() / PMR, checkPointImage.getY() / PMR);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.