0

I am surely overlooking something, but is there an easy to draw for example only half a sprite in LibGDX? I originally thought I could do this with setBounds() but this distorts the sprite and does not clip it.

1
  • It's not built in. You need to modify the UVs of the TextureRegion/Sprite.
    – Tenfour04
    Apr 15, 2015 at 19:28

2 Answers 2

0

do not know if this is what you want, or is the most efficient way but that's what I happened to read your question, I hope I understand and serve you this:

Variable class:

Texture testTexture = new Texture (Gdx.files.internal("badlogic.jpg"));

In render method for example:

    //batch is a SpriteBatch.
    batch.draw(testTexture, 50, 50,
                            0, 0, 
                            testTexture.getWidth() /2,
                            testTexture.getHeight());

this is the method in SrpiteBatch.class:

public void draw (Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)

Now for example in you sprite (simple test):

    batch.draw(yourSprite.getTexture(), 50, 50,
               0, 0, yourSprite.getTexture().getWidth() /2,
                     yourSprite.getTexture().getHeight() );

Edit Note:

to re-look the answer, I thought it would be nice to say that this makes, show only one area of the texture as you say, but perhaps should be noted that the texture remains the same size, I say this because if you texture used to detect collisions, keep in mind, that although half display, texture remains as large than the original

0

There was also Scissors class:

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/utils/ScissorStack.html

I think I tried it once...but it worked well on desktop and not on android...so I didn't use it. Maybe it's fixed meanwhile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.