Reputation: 510
I had a problem with position of actor
Here is actor class:
public class Test extends Actor {
Sprite sprite;
Vector2 actorPosition;
public Test() {
Texture t = new Texture("img.png");
sprite = new Sprite(t);
sprite.setSize(t.getWidth(), t.getHeight());
actorPosition = new Vector2();
// set the size and position of actor
setSize(sprite.getWidth(), sprite.getHeight());
setPosition(actorPosition.x, actorPosition.y);
debug();
}
public void setActorPosition(Vector2 actorPosition) {
this.actorPosition = actorPosition;
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(sprite, actorPosition.x, actorPosition.y, getWidth(), getHeight());
}
}
When I call the setActorPosition
method, the sprite drawing in a specific position is fine but the actor position is still at (0, 0)
.
I want the actor and sprite to be draw at the same position using this method because I want to control this position in another class.
How can I do this?
Upvotes: 0
Views: 73
Reputation: 1593
You can set the Actor's position using:
setX(float x);
setY(float y);
You could do it like this:
public void setActorPosition(Vector2 actorPosition) {
this.actorPosition = actorPosition;
setX(actorPosition.x);
setY(actorPosition.y);
}
Upvotes: 1