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

2016/5/16

Actors not showing?

TheBrains1001 TheBrains1001

2016/5/16

#
This is the main screen:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @]author (your name) 
 * @version (a version number or a date)
 */
public class MainScreen extends World
{

    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MainScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 1000, 1); 
		String s = Greenfoot.ask("What group do you want to access?");
		if(s=="21")
		{
			Greenfoot.setWorld(new Group21());
    	}
		if(s=="22")
		{
			Greenfoot.setWorld(new Group22());
    	}
		if(s=="23")
		{
			Greenfoot.setWorld(new Group23());
    	}
		if(s=="24")
		{
			Greenfoot.setWorld(new Group24());
    	}
		if(s=="25")
		{
			Greenfoot.setWorld(new Group25());
    	}
    }
}
and i tested it with Group21
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Group21 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Group21 extends World
{
    /**
     * Constructor for objects of class Group21.
     * 
     */
    public Group21()
    {    
        super(1000,1000,1);
        addObject(new Consecrate(),500,500);
    }
    public void act()
    {
        
    }
}
but no actors are showing and I put it with an 800x600 picture
TheBrains1001 TheBrains1001

2016/5/16

#
and background of 21 isnt showing
danpost danpost

2016/5/16

#
It is probably because the literal "21" is a separate String object from the String object that is created by using the 'ask' method. Try this format:
if ("21".equals(s))
TheBrains1001 TheBrains1001

2016/5/16

#
thank you!
TheBrains1001 TheBrains1001

2016/5/16

#
The greenfoot.ask thing keeps showing after i answer the question. what do i do
danpost danpost

2016/5/16

#
TheBrains1001 wrote...
The greenfoot.ask thing keeps showing after i answer the question. what do i do
Move lines 20 through 40 of the MainScreen class to a 'public void started()' method.
You need to login to post a reply.