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);

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


Thanks in advance!


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);

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.