Fruity Posted July 8, 2015 Posted July 8, 2015 (edited) What im aiming for is similar to below : 1 image - but the total width is cropped depending on the percentage. i have percent to next level as so. percentTNL = ((currentXp - currentLevelXp) / (nextLevelXp - currentLevelXp) * 100); But i dont know how to crop the image to have the percent age D: Sorry for being a nub :3 Edited July 8, 2015 by Fruity
The_Red_Flag Posted July 8, 2015 Posted July 8, 2015 Is it possible to have the image move to the right and just have the left side covered by something else? I feel like this might be the best option as dynamic resizing or cropping may be a little tough.
blabla123 Posted July 8, 2015 Posted July 8, 2015 (edited) g.drawRectangle(x,y,width,height); ^ percentTNL or something along this line... I know it doesn't do exactly what you wanted, but it's much easier. Edited July 8, 2015 by blabla123
FrostBug Posted July 9, 2015 Posted July 9, 2015 (edited) try this Rectangle bounds = new Rectangle(Whatever bounds you want to crop to on the game screen); int dx1 = bounds.x; int dy1 = bounds.y; int dx2 = bounds.x + bounds.width; int dy2 = bounds.y + bounds.height; int sx2 = bounds.width; int sy2 = bounds.height; g.drawImage(image, dx1, dy1, dx2, dy2, 0, 0, sx2, sy2, null, null); You can calculate the bounding rectangle by having a pre-defined "full" (100%) rectangle, and transform its width according to your percentage variable. Edited July 9, 2015 by FrostBug 1
Bobrocket Posted July 9, 2015 Posted July 9, 2015 You can work out the appropriate width like so: int onePercentImage = (int)(image.width / 100); int imageWidth = (onePercentImage * percentTNL);
Fruity Posted July 10, 2015 Author Posted July 10, 2015 try this Rectangle bounds = new Rectangle(Whatever bounds you want to crop to on the game screen); int dx1 = bounds.x; int dy1 = bounds.y; int dx2 = bounds.x + bounds.width; int dy2 = bounds.y + bounds.height; int sx2 = bounds.width; int sy2 = bounds.height; g.drawImage(image, dx1, dy1, dx2, dy2, 0, 0, sx2, sy2, null, null); You can calculate the bounding rectangle by having a pre-defined "full" (100%) rectangle, and transform its width according to your percentage variable. Thank you this worked