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

2017/2/3

Building from another class

Gormatrax Gormatrax

2017/2/3

#
So i have built a Scene class which extends World:
import java.util.Arrays;
import java.util.List;

import greenfoot.*; 



public class Scene extends World
{
	
	public static int WIDTH = 1600;
	public static int HEIGHT = 900;
	public static int Cell_size = 1;
	public static int X_INIT = 1;
	public static int Y_INIT = 1;
	int k;
	Actor Actor_Principal;
	
	List<String> Lista_Fundal = Arrays.asList(
			"facing.png"
			
	);
	
	
    
    public void SetScene(int Scene_Number) //Definirea parametrilor initiali ai scenei
    {
        setBackground(Lista_Fundal.get(Scene_Number));
       
       
    }

    public Scene() //Constructor scena
    {    
        super(WIDTH, HEIGHT, Cell_size);
    }
    
    
}
Now, I want to be able to have a Main class, from where I would declare a Scene and use it thorough the game. This was my attempt:
public class Main {

	Scene s = new Scene();
	s.SetScene(0);
	
			
}
However, this already gives a ton of errors on the second s.SetScene(0) line. Any idea what I'm doing wrong or a better way to do it?
Super_Hippo Super_Hippo

2017/2/3

#
Why do you need this Main class? Why don't you use the scene in the scene class itself? Not sure what your errors are, so I don't know if it could cause it, but if you don't want to manipulate the strings after the scenario started, you can use an array:
private String[] images =
{
    "facing.png"
};

public void setScene(int num)
{
    setBackground(images[num]);
}
You need to login to post a reply.