A
A
Arti-Jack2016-12-13 16:10:05
Android
Arti-Jack, 2016-12-13 16:10:05

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:
27615e118d0b4183bbf3efabeaf6dfcf.png
And when I try to draw, nothing comes out normal.
cccd554e18d64b2896efd1fea2e3f027.png
But when rendering other sprites, taken by me on the Internet, everything comes out
1a8efdd390ce4af9a114d0b52a2f2352.png
. 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;

And rendering:
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);

Therefore, such a question:
How will it be correct to draw sprites (observance of sizes, any parameters, etc.)?
PS :
Here are links to resources;
not my
my sprites

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2016-12-13
@Arti-Jack

Well, where is the code that you cram?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question