I want to create a mirror image

Hi, I want to create a mirror image effect: when the character is moving left it face left, when is moving right it face right.

The character can move also up and down, but I want only this kind of effect: left and right.

So, if my character have face left and it move up/down, it continues with face left

if the character hava face right and it move up/down, it continues with face right

this is the code:

publicvoid draw(Graphics2D g){

AffineTransform transform =new AffineTransform();

// translate the sprite

transform.setToTranslation(x,y);

// if the sprite is moving left, flip the image

if (dir == dir.OVEST){

transform.scale(-1, 1);

transform.translate(-sprite.getWidth(), 0);

}

g.drawImage(sprite.image,transform,null);

}

The problem is: 'cause my default image have face right, if it move left, it change to face left, but if it move up/down/right, it change to face right.

for example: character is moving left, it change to face left.. then, character is moving up/down, it change to face right.

How I can resolve this problem?

[1492 byte] By [Mesinaa] at [2007-10-3 5:11:53]
# 1
It looks like you need to maintain the "current" facing in addition to the direction. Right now, you only flip the sprite if the direction is dir.OVEST (which I assume means left or west). You should also flip the sprite if the current facing is left.
Herko_ter_Horsta at 2007-7-14 23:18:18 > top of Java-index,Other Topics,Java Game Development...