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

2015/11/3

Bouncing actor off wall without reversing image

bkatrina bkatrina

2015/11/3

#
I'm having trouble with the bouncing of my actor off the wall because the image reverses. How do I not make it flip?
 public void act() 
    {
        move(3);
        checkWalls();
        if(Greenfoot.isKeyDown("space"))
        {
            move(-3);
        }    
    }

    public void checkWalls()
    {  
        boolean atXEdge = getX() < 10 || getX() > getWorld().getWidth()-10;
        boolean atYEdge = getY() < 10 || getY() > getWorld().getHeight()-10;
        if (atXEdge || atYEdge)
        {
            move(-3);
        }
        if (atXEdge) 
        {
            setRotation(540-getRotation());
        }
        if (atYEdge)
        {
            setRotation(360-getRotation());
        }
    }
danpost danpost

2015/11/3

#
You can save the 'virtual' rotation of the actor in a field and have the rotation of the actor set to zero between act cycles (save the virtual rotation and set the actual rotation to zero before exiting the act method; set the rotation to the virtual rotation at the beginning of the act method).
bkatrina bkatrina

2015/11/6

#
How do I do that? huhu so sorry
You need to login to post a reply.