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

2017/12/4

help

I've made my object move when I press an arrow key. However my image also rotates. Can I make it face a certain direction? I want The image facing right, even if I turn it "up" or "down" or "left".
danpost danpost

2017/12/4

#
Save the rotation in a field. Set it at beginning of act and then save it at the end before setting zero rotation:
private int rotation = 0;

public void act()
{
    setRotation(rotation);
    // other action code
    rotation = getRotation();
    setRotation(0);
}
danpost wrote...
Save the rotation in a field. Set it at beginning of act and then save it at the end before setting zero rotation:
private int rotation = 0;

public void act()
{
    setRotation(rotation);
    // other action code
    rotation = getRotation();
    setRotation(0);
}
whats a field?
danpost danpost

2017/12/4

#
_The_Black_Swordsman_ wrote...
whats a field?
Line 1 is a field declaration line -- a variable that is declared within a class, but not within a method or constructor (which are just plain variables). Each object created from the class comes with a placeholder for, in this case, an 'int' value called 'rotation' given an initial value of '0'. As 'private', no other class has direct access to the field. The field will exist as long as the object it belongs to exists. A field can be of any of the primary types (int, double, float, boolean, etc.) or it can reference an object of the specified type (Actor, World, Object, etc).
You need to login to post a reply.