I want to know , if you can , join two sprites in libgdx .
Let me explain, I have a spaceship that I have to turn in my game ... and is the first sprite .
another sprite I would put on the tip of the spacecraft so that when it turns me I through the second sprite I can always know the coordinates and so derive a vector in order to advance my ship .
I'm new to libgdx and if anyone had any idea would be grateful.
Thank You.
EDIT : I would follow that always render the position of the other sprites , currently does not happen , tips ? Thank You.
@Override
public void render () {
sprite.setPosition(Gdx.graphics.getWidth() / 2 - sprite.getWidth()/2, Gdx.graphics.getHeight() / 2 - sprite.getHeight()/2);
point.setPosition(sprite.getX() + (sprite.getWidth()/2 - point.getWidth()/2), sprite.getY() + (sprite.getHeight() / 2 + point.getHeight()));
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)){
//sprite.setPosition(Gdx.input.getX() - sprite.getWidth()/2, Gdx.graphics.getHeight() - Gdx.input.getY() - sprite.getHeight()/2);
if(Gdx.input.getX() < Gdx.graphics.getWidth() / 2)
{
//System.out.println("x: " + Gdx.input.getX() + " - y: " + Gdx.input.getY());
sprite.setRotation(rotation++);
}
else
{
System.out.println("x: " + Gdx.input.getX() + " - y: " + Gdx.input.getY());
sprite.setRotation(rotation--);
point.setRotation(rotation--);
}
}
batch.begin();
spacesprite.draw(batch);
sprite.draw(batch);
point.draw(batch);
batch.end();
}
EDIT 2
As you can see in the picture , I would like that when I rotate the sprite of the spacecraft , the red dot ( which is another sprite ) remain on the tip of the spacecraft . So you can calculate a vector with the points of origin of the two sprites .
I hope to have been clear . A union of two sprites is not possible in libgdx else?
EDIT 3
picture , I wish that when the ship rotates the red ball remains always on the tip of the spacecraft . is it possible?
If your two sprite have the same width can use this:
this is psudo code mor or less.
if diferente width
I can not test now, but so you have an idea.
New
I do not know if is this what you mean if not so comment it and delete:
P.s: points* is a Vector2:
the pointC vector is the center of the two vectors.
if that's what you want, and ask yourself, how to rotate? sprites can this helps.
LibGDX - Rotate a 2d array of sprites around their center