user8340536 user8340536 - 1 year ago 60
Android Question

How to implement double in setRegions

I wrote this code (extract):

regions = TextureRegion.split (texture1, 178, 177.8);


177.8 is underlined red. I know that there has to be an integer but is there any posibility to implement a double to this method?

Answer Source

As Abhishek said double values won't work as you can't copy half a pixel. If you want to convert the value to the nearest int you can use:

double width = 177.0;
double height = 177.8;
regions = TextureRegion.split (texture1,((int) width), ((int)height));

If you want the lowest whole number you can use math.floor() or largest whole number math.ceil()

// smallest
regions = TextureRegion.split (texture1,((int)Math.floor(width)), ((int)Math.floor(height)));

// largest
regions = TextureRegion.split (texture1,((int)Math.ceil(width)), ((int)Math.ceil(height)));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download