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

2017/12/8

Getting Rotation

Bandito Bandito

2017/12/8

#
I've been trying for a while to get"get.Rotation()" to work for a while and it just doesn't seem to want to work, the error message says non-static method getRotation() cannot be referenced from a static context. Here is my code -
 public int humanRotation;  
    public Bullet()
    {       
        GreenfootImage myImage = getImage();
        int myNewWidth = (int)myImage.getWidth()/4;
        int myNewHeight = (int)myImage.getHeight()/4;
        myImage.scale(myNewWidth,myNewHeight);
    }

    public void act() 
    {
        shoot();
        move(-4);
    } 

    public void shoot()
    { 
        humanRotation = Human.getRotation();
        setRotation(humanRotation);
    }
}
Super_Hippo Super_Hippo

2017/12/8

#
Human is a class, not an object. A class does not have a rotation. Try to pass the rotation of the human as a parameter to the bullets constructor when it adds the bullet to the world. If it should really turn with the human even after it was shot instead of moving in a fixed direction, you need to pass the human object itself, so you have a reference to it.
Bandito Bandito

2017/12/9

#
Alright thanks, that worked.
You need to login to post a reply.