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

2015/4/5

Transferring Actors From One World To Another

Xelon1620 Xelon1620

2015/4/5

#
Im wanting to get an Actor that I spawned in one world to transfer to the next world when I use Greenfoot.setWorld. When I click the button to choose the arena I want to play on it removes my selected characters from the game when going to the next world. How do you code it to where certain actors stay.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
/**
 * Write a description of class SeaWorldButton here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SeaWorldButton extends Button
{
    public static int WorldSelector = 1;
    public SeaWorldButton() 
    {
        super("Play");
        x = 25;
        y = 100;
        label = "SeaWorld Arena";
        WIDTH = 200;
        HEIGHT = 200;
        ink = Color.blue;
        FONT_SIZE = 20.0f;
        bckg = Color.black;
        makeImage();
        setting = 1;
    }    
    public void act()
    {
       if(Greenfoot.mouseClicked(this))
       {
           Greenfoot.setWorld(new SeaWorldLevel());
       }
    }
}
danpost danpost

2015/4/5

#
(1) are both worlds of the same type (created from the same class) (2) how many actors are you wanting to transfer and of what types (3) how are these actors defined and added into each world at this point (4) what is your initial world class and what preliminary code does it contain (fields, constructors and prepare methods)
Xelon1620 Xelon1620

2015/4/5

#
danpost wrote...
(1) are both worlds of the same type (created from the same class) (2) how many actors are you wanting to transfer and of what types (3) how are these actors defined and added into each world at this point (4) what is your initial world class and what preliminary code does it contain (fields, constructors and prepare methods)
One world is a Selection Screen and The One I need these characters transferred to is an arena. I need 2 actors transferred and they are Smooth Movers They are added into the selection screen through a button and the code
public void act()
    {
        if(Greenfoot.mouseClicked(this))
        {
           getWorld().addObject(new Stormtrooper(1),190,130);
           getWorld().addObject(new BobaFett(2),800,130); 
        }
    }
And in my selection screen world all I have is
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class ArenaSelection here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SelectionScreen extends Screen
{
    public SelectionScreen()
    {    
       addObject(new LavaButton(),157,670);
       addObject(new SpaceShipButton(),379,670);
       addObject(new SeaWorldButton(),604,670);
       addObject(new CityScapeButton(),828,670);
       addObject(new StarWarsButton(),300,430);
       addObject(new BatmanButton(),700,430);
       addObject(new Platforms(2),200,200);
       addObject(new Platforms(2),800,200);
       addObject(new MenuButtons(2),500,100);
    }   
}
Xelon1620 Xelon1620

2015/4/5

#
Never Mind I found the answer to my problems on a earlier post of yours. Thank you for your help
You need to login to post a reply.