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

2018/5/20

Help with getRotation()

emystery emystery

2018/5/20

#
Hi, so, im having a problem with my program: im trying to make it so, that the image changes if the rotation equals 180. Problem is i'm stupid, and the image is just on its head. Here direction is an integer that equals getRotation()
      if(!isOnSolidGround() && direction == 180)
        {
                setImage("4alt2.png");
            
        } 
        
       if(!isOnSolidGround() && direction == 0)
        {
            
                setImage("4.png"); 
            
        }
my project is also on here, so if you care to try it out and point out some more issues, please tell me http://www.greenfoot.org/scenarios/21219 P.S. - i know that the platforms dont work properly
danpost danpost

2018/5/20

#
I think you might be better off not changing the rotation of the actor and using a "facing" int field to indicate the horizontally facing direction. If I recall correctly, you already had the two fields "direction" and "rotation" in the class -- either not used (rotation) or not being updated when needed (direction). Both these fields are to be removed once the facing field is implemented. The facing field should change only between the values of '1' (right) and '-1' (left). It should be adjusted according to movement key input and it should be used when determining the potentially new x-coordinate for the actor (when changing 'x' with step -- step to be multiplied by facing). You images will not be inverted because you will no longer be rotating the actor and the field can then also be used to determine idle image when needed.
You need to login to post a reply.