This site requires JavaScript, please enable it in your browser!
Greenfoot back
Sathya_srikanth
Sathya_srikanth wrote ...

2020/12/31

reversed movement

Sathya_srikanth Sathya_srikanth

2020/12/31

#
so i wanted the actor jerry to get mirrored vertically when "a" is pressed ( while it's moving) basically I want jerry to face to the side it is moving...but when I tried this code when ever I pressed "a" its started glitching
public void act() 
    {
        if(Greenfoot.isKeyDown("w"))
        move(4);
        if(Greenfoot.isKeyDown("a"))                 
        { move(-4);
          turn(180);
          getImage().mirrorVertically();
            
        } 
danpost danpost

2020/12/31

#
Sathya_srikanth wrote...
so i wanted the actor jerry to get mirrored vertically when "a" is pressed ( while it's moving) basically I want jerry to face to the side it is moving...but when I tried this code when ever I pressed "a" its started glitching << Code Omitted >>
You will need to add a field to track which direction was last moved; then, change the image when the field does not match the current state. Either that or keep both images in an array (or in two separate fields); then when the required image is not active, set it active.
You need to login to post a reply.