[Solved] Draw offsets from TextureRegion

Anything libgdx related goes here!

[Solved] Draw offsets from TextureRegion

Postby JCabello » Sun Mar 18, 2018 5:28 pm

Hi, Im trying to draw the offsets of my animations to change their wrong positions to correct positions but I dont know how to do this.

Im doing tests with a static frame of a animation changing his values manually where I suspect that it can work well but I havent results.

Here the features of the frame.

Running
rotate: false
xy: 1, 1
size: 33, 51
orig: 128, 128
offset: 58, 27
index: 1

And my SpriteBatch code to draw the animation, Im using too batch.begin() and batch.end().

25,30 is the position where I want my frame. And rotation 180 is for flip the frame.

Code: Select all
Vector2 pointHero = twoDToIso(new Vector2(25,30));
batch.draw(currentFrame,pointHero.x,pointHero.y,0,0,currentFrame.getRegionWidth(),currentFrame.getRegionHeight(),1,1,180);


I dont know where put the values of my offset.

And Im using a function to transform my cartesian coordinates to isometric coordinates.

Code: Select all
public Vector2 twoDToIso(Vector2 punto) {
        Vector2 tempP = new Vector2(0, 0);
        tempP.x = (punto.x - punto.y) * 32;
        tempP.y = (punto.x + punto.y) * 16;
        return tempP;
    }


Can you modify my code to know where draw my offset? And, where I should put my xy: 1, 1?

Thanks You!
Last edited by JCabello on Sun Mar 18, 2018 7:16 pm, edited 1 time in total.
JCabello
 
Posts: 31
Joined: Sat Feb 10, 2018 5:40 pm

Re: Draw offsets from TextureRegion

Postby evilentity » Sun Mar 18, 2018 6:18 pm

Nowhere, thats position in the atlas.
AtlasRegion region gives you what you need, offsetX and offsetY with nice docs. A little lower, you have AtlasSprite that takes that stuff into account.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4348
Joined: Wed Aug 24, 2011 11:37 am

Re: Draw offsets from TextureRegion

Postby JCabello » Sun Mar 18, 2018 7:15 pm

Oh my god, Thanks you! AtlasSprite resolve my problem.
JCabello
 
Posts: 31
Joined: Sat Feb 10, 2018 5:40 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest