Hey there. I don't know if anyones read a book on Java Games Development by David Brakeen.

Well, here's where I need help. When I detect when the left and right key has been pressed I want to switch the sprite to look the corresponding way.

What I have tried so far is in my draw method, I use an if statement to check which way the sprite is travelling, then if the sprite is travelling left, I use a transform to set the way the sprite is looking.

This is what I have so far:

CODE
public void draw(Graphics2D g) {
        // draw background
        g.drawImage(bgImage, 0, 0, null);

        // draw sprite
        g.drawImage(player.getImage(),
            Math.round(player.getX()),
            Math.round(player.getY()),
            null);
        
        
        //If the player is facing travelling left, then switch the sprite around to face left.    
        transform = new AffineTransform();
        if (player.getVelocityX() < 0){
            transform.scale(-1,1);
            transform.translate(-player.getWidth(), 0);
            g.setTransform(transform);
            g.drawImage(player.getImage(), transform, null);
            
        }
        
    }


Needless to say this didn't work, when I tried running, when I pressed the left key, a new sprite appeared in the top corner and was looking the same way as before so it didn't even switch.

Any help would be great =]

Dan