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

2017/9/7

stop image orientation changing

greennotpurpleaki greennotpurpleaki

2017/9/7

#
I am using 'SetRotation' move a character up,down,left and right. I am also swapping image each time (so that they 'look' up,down,left and right). However, my images are chagign their orientation. How do I swap image, make the actor move but stop the orientation of the image from changing? Example code I am using below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
move(2);       
        if (Greenfoot.isKeyDown("right"))
        {
            setRotation(0);
            setImage(right);           
        }   
        if (Greenfoot.isKeyDown("down"))
        {
            setRotation(90);
            setImage(down);           
        }
        if (Greenfoot.isKeyDown("left"))
        {           
            setRotation(180);
            setImage(left);
             
        }
        if (Greenfoot.isKeyDown("up"))
        {
            setRotation(270);   
            setImage(up);
                    
        }
Super_Hippo Super_Hippo

2017/9/7

#
I think you should turn first and then move. After that, you can set the rotation back to 0. Or you just use the 'setLocation' method instead of rotating and moving. Or you turn the images.
greennotpurpleaki greennotpurpleaki

2017/9/7

#
I tried setting the rotation back to 0 but it didn't work. Could you show me an example of what my you think my code should look like?
Super_Hippo Super_Hippo

2017/9/7

#
Did you try it like this?
1
2
3
4
//remove line 1
//rest of your code
move(2);
setRotation(0);
greennotpurpleaki greennotpurpleaki

2017/9/7

#
Excellent, I'm almost there. Left and right are fine, but any ideas on the move setting for up and down?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (Greenfoot.isKeyDown("right"))
        {
            move(2);
            setRotation(0);
            setImage(right);    
            setRotation(0);
        }   
        if (Greenfoot.isKeyDown("down"))
        {
            move(2); // ?????
            setRotation(90);
            setImage(down);  
            setRotation(0);
        }
Super_Hippo Super_Hippo

2017/9/7

#
I meant it like this, not every direction on its own:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
if (Greenfoot.isKeyDown("right"))
{
    setImage(right);           
}   
if (Greenfoot.isKeyDown("down"))
{
    setRotation(90);
    setImage(down);           
}
if (Greenfoot.isKeyDown("left"))
{           
    setRotation(180);
    setImage(left);
}
if (Greenfoot.isKeyDown("up"))
{
    setRotation(270);   
    setImage(up);    
}
move(2);
setRotation(0);
greennotpurpleaki greennotpurpleaki

2017/9/7

#
Bingo! Thanks very much for this
You need to login to post a reply.