java - Displaying a part of an image in libGDX - looks stretched -


i'm trying build progress bar in libgdx, have 1 full horizontal image , in 2 lines trying display 2 different widths of image:

imagefull: enter image description here

imagefull.draw(batch,10,80,600,50); imagefull.draw(batch,10,20,100,50); 

the result is: enter image description here

its looks when width 'small' stretched , looks bad.

why can't display part of image without destroying left side of image?

any ideas how fix it?

that normal behavior. if stretch image without keeping it's aspect ratio deform, not know stretchable part itself.

9-patch here cannot draw sprite doing (maybe spritedrawable though?).

if use scene2d actor named progressbar. feed 9-patch image, should stretch correctly. or use image if want control yourself, , feed image ninepatch.

a quick way create ninepatch specify it's stretching regions hardcoding it.

texture = new ninepatch(yourtexture, a, b, c, d) 

where abcd corresponds following image:

enter image description here

now create scene2d image ninepatch , should stretch properly.

if have texture in atlas can supply line split:a,b,c,d image data in .atlas file , scene2d automatically pick ninepatch.

if don't want use scene2d and/or ninepatch (but recommend use it) have code behavior yourself. or cut texture , stick caps on left , right side of rectangle. scene2d invented , ton more gui functionality.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -