lets say i am print a image on screen. with (x1,y1,x2,y2,sx1,xy1,sx2,sy2)
g.drawImage(player_image, x, y, x+width, y+height
0, 0, 30, 20 ,Sprite_Sheet.m1);
so how would i flipthis image vertically.
lets say i am print a image on screen. with (x1,y1,x2,y2,sx1,xy1,sx2,sy2)
g.drawImage(player_image, x, y, x+width, y+height
0, 0, 30, 20 ,Sprite_Sheet.m1);
so how would i flipthis image vertically.
Graphics2D (the actual class of the Graphics you draw on) supports a huge set of transforms that modify how subsequent draw operations work. So, for eaxmple the g.rotate method causes all subsequent draws to be rotated by the specified angle. Similarly you can set a scale transform that scales subsequent drawing - and here's the bit you were waiting for - a negative scale factor reflects the image in the correwsponding axis, eg g.scale(1.0, -1.0) keeps the size the same but reflects the drawing vertically. You will probably have to shift the origin of your Graphics2D to keep the reflected image in the right place.
See the Graphics2D API doc for details, the AffineTransform API for the maths behind it.
just want to make sure.
so i should use the:
Graphics2D g2
than roate the image
player_image.rotate(2pii);
than scale the image
g.scale(1.0, -1.0)
than print image with g2
g2.drawImage(player_image, x, y, x+width, y+height
0, 0, 30, 20 ,Sprite_Sheet.m1);
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, 0); //translate to center
g2d.drawImage(...);
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.