Hey,
in my Programm i create a player, which extends a Sprite, and adds some features to it.
im using Box2d;
i create the sprite like this :
sprite = new Sprite(tex);
sprite.setPosition(X, Y);
sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
so every update call i set the Sprite to the location of its body:
Vector2 position = body.getPosition();
sprite.setPosition(position.x-sprite.getWidth()/2,position.y-sprite.getHeight()/2);
sprite.setRotation( MathUtils.radiansToDegrees*body.getAngle());
after that i simply draw the sprite with :
sprite.draw(batch);
now this works just perfectly.
However, i want a second Sprite, without a physics body to appear left,right,top or bellow of the player Sprite.
This Second sprite is supposed to stay exactly at its location besides the player, in this case left, even if the player does full rotations and fancy stuff.
Both Sprites have the same Dimensions.
ive drawn how the Second sprite is supposed to behave here : (secondsprite beeing black)
its kinda complicated but i will try to explain what happens.
I manage to get my second sprite to stay left of the playerSprite, or on top, or Right, or below as long as the player is not rotated.
However as soon as i start to rotate, the second sprite doesnt stay at the right place, it rotates in the right angle, but it kinda leaves the playSprites Side.
this creates the Second Sprite :
SecondSprite = new Sprite(new Texture(Gdx.files.internal("data/second.png")));
SecondSprite.setPosition(X-SecondSprite.getWidth(), Y);
SecondSprite.setOrigin(SecondSprite.getWidth()/2, SecondSprite.getHeight()/2);
SecondSprite.setRotation(k);
the code that sets the Second Sprites position is :
Vector2 left = new Vector2(body.getPosition().x-sprite.getWidth(),body.getPosition().y);
SecondSprite.setPosition(left.x-sprite.getWidth()/2,right.y-sprite.getHeight()/2);
SecondSprite.setRotation( MathUtils.radiansToDegrees*body.getAngle());
But as mentioned it doesn work the way its supposed to be, im struggling with that problem since 2 days and dont get the Hang of it.
Would be really nice if someone could help me out.
Thanks in advance.
EDIT
best would be if theres a way to access the coordinate System the Sprite is using. If that would be possible it would help me out a lot, even in other situations.
If tryed the “Sprite.Translate” stuff but that gives me strange results.