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

2012/11/30

Screen Wraping

bbwf bbwf

2012/11/30

#
Hey guys I'm trying to make some screen wraping but can't figure out or remember how to code it. I want to make it so where if my rocket reaches the edge of the world it will appear on the other side at the same spot. I also need to know how to check for world edge (code please!). Thanks.
danpost danpost

2012/11/30

#
In the rocket class, put the following line after the move command
int w=getWorld().getWidth();
int h=getWorld().getHeight()
setLocation((getX()+w)%w, ((getY()+h)%h);
The above will work if your world is unbounded (you use 'super(WIDTH, HEIGHT, CELL_SIZE, false)'. If not, do the evaluation of x and y that is inside the setLocation statement before moving the actor and set to the resulting values.
bbwf bbwf

2012/11/30

#
Heres my rocket class code, nothing works after adding in those lines of code.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Rocket here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Rocket extends Actor
{
    /**
     * Act - do whatever the Rocket wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    
    {
        move(4);
        int w=getWorld().getWidth();
        int h=getWorld().getHeight();
        setLocation((getX()+w)%w, ((getY()+h)%h));
 
        if (Greenfoot.isKeyDown("left"))
        {
            turn(-3);
        }
        if (Greenfoot.isKeyDown("right"))
        {
            turn(3);
        }
         //if (Greenfoot.isKeyDown("down"))
        {
            setLocation(getX(), getY()+3);
        }
          //if (Greenfoot.isKeyDown("up"))
        {
            setLocation(getX(), getY()-3);
        }
        Actor Pear;
        Pear = getOneObjectAtOffset(0, 0, Pear.class);
        if (Pear != null)
        {
            World Space;
            Space = getWorld();
            Space.removeObject(Pear);
        }
    
    }    
}
bbwf bbwf

2012/11/30

#
Got it THANKS!
You need to login to post a reply.