Fruity Posted July 8, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
The_Red_Flag Posted July 8, 2015 Share 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. Quote Link to comment Share on other sites More sharing options...
blabla123 Posted July 8, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
FrostBug Posted July 9, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 9, 2015 Share Posted July 9, 2015 You can work out the appropriate width like so: int onePercentImage = (int)(image.width / 100); int imageWidth = (onePercentImage * percentTNL); Quote Link to comment Share on other sites More sharing options...
Fruity Posted July 10, 2015 Author Share 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 Quote Link to comment Share on other sites More sharing options...