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

2014/11/25

HElp

Elden Elden

2014/11/25

#
How Do I Get The Actor To Disappear on the Y Axis http://www.imageupload.co.uk/images/2014/11/09/3.png This Is What Ive Got
    public void act() 
    {  
        int ypos = getY() - 5;
        int xpos = getX();
        setLocation(xpos, ypos);
        if (ypos == getWorld().getHeight()){
            setLocation(getX(), getY() -300);
        }
        else {
            setLocation(getX(), ypos);
        }
    }
    public void MoveAlongY(){
        
    }
}
danpost danpost

2014/11/26

#
What you have got is equivalent to this:
public void act()
{
    setLocation(getX(), getY()-5);
}

public void MoveAlongY()
{
}
My line 3 is basically what you have on lines 3 through 5. The 'if' condition will NEVER be true because 'getX()-5' will always be at least 6 less than 'getWorld().getHeight()' (the highest y-coordinate value an actor can have in a bounded world is one less than the height of the world) and the 'setLocation' in the 'else' block does not change the location of the actor from where it was placed on line 5. Do you want your actor to move down the screen or up? Do you want your actor to be removed from the world when it reaches the edge?
You need to login to post a reply.