Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

libGDX SpriteBatch.draw() origin not working as expected

$
0
0

I’m having a weird issue with SpriteBatch.draw(). I’m using the Ashley Super Jumper demo (https://github.com/siondream/ashley-superjumper) as the basis for my code. Here’s the render queue:

for(Entity entity : renderQueue) {
        TextureComponent tex = textureMapper.get(entity);

        if(tex.region == null) {
            continue;
        }

        TransformComponent t = transformMapper.get(entity);

        float width = tex.region.getRegionWidth();
        float height = tex.region.getRegionHeight();
        //float originX = width * 0.5f; // this is from the demo
        //float originY = height * 0.5f;
        float originX = t.origin.x; // I moved origin to 't' so I could adjust it for debugging
        float originY = t.origin.y;

        spriteBatch.draw(
                tex.region,
                t.position.x - width / 2, // the demo uses originX/originY for these
                t.position.y - height / 2,
                originX,
                originY,
                width,
                height,
                t.scale.x * PIXELS_TO_METERS,
                t.scale.y * PIXELS_TO_METERS,
                MathUtils.radiansToDegrees * t.rotation);
    }

What I expect to happen, as I adjust originX and originY, is that when I rotate the image, the point around which it rotates changes. Instead, changing originX/Y moves the image around the screen, and rotating rotates about the center of the image, regardless of originX/Y. My understanding is that the origin should only affect scaling and rotating, i.e. not the position, but it’s behaving the exact opposite. Am I missing something here?


Viewing all articles
Browse latest Browse all 434

Trending Articles