#Mirror sprite java game
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @crystal dome! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
public void drawTransformed(Graphics2D g) ```java
{
if (!render) return;
AffineTransform transform = new AffineTransform();
// Apply scaling to current x and y positions to
// ensure shifted left and up when flipped due to scaling.
float shiftx = 0;
float shifty = 0;
if (xscale < 0) shiftx = getWidth();
if (yscale < 0) shifty = getHeight();
transform.translate(Math.round(x)+shiftx+xoff,Math.round(y)+shifty+yoff);
transform.scale(xscale,yscale);
transform.rotate(rotation,getImage().getWidth(null)/2,getImage().getHeight(null)/2);
// Apply transform to the image and draw it
g.drawImage(getImage(),transform,null);
} ```
This message has been formatted automatically. You can disable this using /preferences.
then the draw...
public void draw(Graphics2D g) {
int xo = -(int) player.getX() + 200;
int yo = -(int) player.getY() + 200;
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(backgroundImage, 0, 0, 600, 500, null);
// Apply offsets to sprites then draw them
for (Sprite s : clouds) {
s.setOffsets(xo, yo);
s.draw(g);
}
// Apply offsets to tile map and draw it
tmap.draw(g, xo, yo);
// Apply offsets to player and draw
player.draw(g);
player.setOffsets(xo, yo);
// Show score and status information
String msg = String.format("Score: %d", total / 100);
g.setColor(Color.darkGray);
g.drawString(msg, getWidth() - 100, 50);
if (debug) {
// When in debug mode, you could draw borders around objects
// and write messages to the screen with useful information.
// Try to avoid printing to the console since it will produce
// a lot of output and slow down your game.
tmap.drawBorder(g, xo, yo, Color.black);
g.setColor(Color.red);
player.drawBoundingBox(g);
g.drawString(String.format("Player: %.0f,%.0f", player.getX(), player.getY()), getWidth() - 100, 70);
drawCollidedTiles(g, tmap, xo, yo);
} ```
This message has been formatted automatically. You can disable this using /preferences.
set the scale to -1
that will mirror in that dimension
basically, just negate the scale
if you scale with 2, scale with -2 etc
lemme try
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.