July 8, 201510 yr 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, 201510 yr by Fruity
July 8, 201510 yr 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.
July 8, 201510 yr 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, 201510 yr by blabla123
July 9, 201510 yr 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, 201510 yr by FrostBug
July 9, 201510 yr You can work out the appropriate width like so: int onePercentImage = (int)(image.width / 100); int imageWidth = (onePercentImage * percentTNL);
July 10, 201510 yr Author 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
Create an account or sign in to comment