Answer the question
In order to leave comments, you need to log in
How to properly draw sprites for libGDX?
Good day!
There was such problem that I cannot correctly use sprites in any way.
Here are the walking sprites for the test, which I'm trying to fit correctly:
And when I try to draw, nothing comes out normal.
But when rendering other sprites, taken by me on the Internet, everything comes out
. And as a result, I see a change of images on the screen.
Here is the code:
int FRAME_COLS = 2;
int FRAME_ROWS = 1;
Animation walkAnimation;
Texture walkSheet;
TextureRegion[] walkFrames;
TextureRegion currentFrame;
float stateTime;
private TextureRegion walk1;
private TextureRegion walk2;
walkSheet = new Texture(Gdx.files.internal("sprites/player/walk/rob3.png"));
TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() / FRAME_ROWS);
walkFrames = new TextureRegion[FRAME_ROWS * FRAME_COLS];
int index = 0;
for (int i = 0; i < FRAME_ROWS; i++) {
for (int j = 0; j < FRAME_COLS; j++) {
walkFrames[index++] = tmp[i][j];
}
}
walkAnimation = new Animation(0.025f, walkFrames);
stateTime = 0f;
Animation a = null;
stateTime += Gdx.graphics.getDeltaTime();
currentFrame = walkAnimation.getKeyFrame(stateTime, true);
if (moveRight) currentFrame = walk1;
if (moveleft) currentFrame = walk2;
//
batch.draw(currentFrame, getX() + 318, getY() + 0, 300f, 300f);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question