java - Libgdx give each texture image properties? -
as of today load texture this:
texture texture = new texture(path); sprite sprite = new sprite(texture); batch.draw(sprite.gettexture(), x,y);
simple that.
but have little problem, have lot of entities types, , each have different size, however, have isometric map, , need center each sprite on tile (not sprites bigger tile, it's not goes on 4 tiles or something, little bigger tile, , needs offset).
so need packing system, can pack sprite image (or set of images same size) , properties included inside, have offsetx
, offsety
can use that:
batch.draw(sprite.gettexture(), x + offsetx, y + offsety);
is there such thing in libgdx?
i tried on doing this:
int x = (i * gametile.tile_width / 2) - (j * gametile.tile_width / 2) - (texture.getwidth() / 2); int y = (i * gametile.tile_height / 2) + (j * gametile.tile_height / 2) - (texture.getheight() / 2);
i
, j
tile position in array.
this do. pick image size @ least big biggest sprite. make sprite source images @ size, putting invisible padding around them needed center them in rectangle. use stripwhitespace feature of libgdx texturepacker. , keep allowrotation off. atlas won't bigger before, has offset data can use.
at runtime, references atlasregions instead of implicitly casting textureregions. atlasregion has offset parameters need. subtract half width , height of source images size , add center point of want draw it.
Comments
Post a Comment