I'm experimenting with Scene2D to see if it fits fot the game I want to develop. Say I have an Actor with the origin in the center of its TextureRegion.
My setup method contains this code:
float width = WorldUtils.pixelsToMeters(Assets.bullet.getRegionWidth());
float height = WorldUtils.pixelsToMeters(Assets.bullet.getRegionHeight());
setPosition(x, y);
setOrigin(width / 2, height / 2);
setSize(width, height);
setRotation(angle);
Where WorldUtils.pixelsToMeters(float)
is just a method to convert pixels to world units (basically 64px = 1 meter).
My draw() method is like this:
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a);
batch.draw(Assets.bullet, getX()-getOriginX(), getY()-getOriginY(), getOriginX(), getOriginY(),
getWidth(), getHeight(), 1, 1, getRotation());
}
This way the actor's position is equal to its center position. This simplifies a lot of stuff like moving the actor to a specific (x, y) in the game world. Otherwise everytime I have to use this actor's position I have to take in account for its screen representation's size... and it doesn't make much sense.
But the way I setup things come at the cost of messing up with event handling. From what I understand Scene2D event handling assumes I'm using (0, 0) as origin of the actor's bounding box. So when I touch/click on my actor during execution it can handle only the ones slightly up-right it real position (obviously).
Is there a way to fix this without touching the library code? I would like to handle certain objects with origin in the center and others with origin in the bottom-left corner.
Maybe I misunderstood how to setup my actor?