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

2016/11/2

Screen Wrap

LimeLava LimeLava

2016/11/2

#
I am using this
int w=getWorld().getWidth();
int h=getWorld().getHeight()
setLocation((getX()+w)%w, ((getY()+h)%h);
to screen wrap my pbject but it seems to not be working. Here is the class for what i want to screen wrap.
public class Apple extends Actor
{
    private int numApples = 3;
    /**
     * Act - do whatever the Apple wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        remove();
        move();
        int w=getWorld().getWidth();
        int h=getWorld().getHeight();
        setLocation((getX()+w)%w, ((getY()+h)%h));
    }    
    public void remove()
    {
        
        if (isTouching( Camel.class))
        {
            getWorld().removeObject(this);
        }
        if (isTouching (Shooter.class))
        {
            getWorld().removeObject(this);
        }
    }
    public void move()
    {
        setLocation(getX()+Greenfoot.getRandomNumber(4)-2,getY() +Greenfoot.getRandomNumber(4)-2);
    }
}
LimeLava LimeLava

2016/11/2

#
Never Mind I used a different thing and figured it out
You need to login to post a reply.