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

2017/1/2

User Input - Storage

4
5
6
7
danpost danpost

2017/1/10

#
Okay -- Super_Hippo hit it precisely. The reason that they do not reset is because the fields are static. I doubt that any of the fields need to be static. I get the feeling that some of them do not need to be fields at all (but, would have to see the rest of the class and understand what 'd', 'j' and 'k' refer to). Is there any reason that you made the fields 'static' to begin with?
JulianYoung JulianYoung

2017/1/10

#
Okay thank you for your Help its working now.
JulianYoung JulianYoung

2017/1/10

#
How do you change the background of world in the code. THe user picks the size of the grid 10 by 10 ect how do i make it so that if for instance the variable that causes the grid to be a 9 by 9 is called what would i put in this if statment.
if(variable){
change image from this to that

}
i have tried
if(Grid==8){
                            setImage ("Greenfoot Background.png");
            
        }
but it cannot find method setImage. this is in my game world
Super_Hippo Super_Hippo

2017/1/10

#
The method for setting a background to a World is 'setBackground...' instead of 'setImage...' which is for Actors.
JulianYoung JulianYoung

2017/1/10

#
Thanks that's great!!
JulianYoung JulianYoung

2017/1/10

#
I have a problem. Look at the photo below its is my options. for some reason after i click run and then reset it and chose a different option it does not change it. code is below plz help. code for page of image and buttons button by 8 by 8 9 by 9 and 10 by 10 are the same but with corrosponding number e.g 8 by 8 = 8 9 by 9 = 9
import greenfoot.*;


public class Layout1 extends Actor
{
    public void act() 
    {
       GreenfootImage image = getImage();  
        image.scale(40, 40);       
        setImage(image);
        if (Greenfoot.mouseClicked(this)) {
            Game.Grid=8;
    }    
}}
next is the code for my run button
  Greenfoot.setWorld(new Game());
            if(Game.Grid==8){
               Game.x=500;
                Game.y=500;
            }
            if(Game.Grid==9){
                Game.x=550;
                Game.y=550;
            }
            if(Game.Grid==10){

                Game.x=600;
                Game.y=600;
            }
finally here is the code for my world game
 public static int y=500;


    /**
     * Constructor for objects of class Game.
     * 
     */
    public Game()
    {    

        super(x, y, 1); 
        if(Grid==8){
            setBackground ("Greenfoot Background.png");

        }
        if(Grid==9){

            System.out.println(x+""+y);
            setBackground ("Backnine.png");

        }
        if(Grid==10){

            setBackground ("Backten.png");

        }
any help would be appreciated i do not know why when i reset it sometimes it doesn't change the image or the size of world.
danpost danpost

2017/1/10

#
In your run button ('Play' button) code, how about setting the 'x' and 'y' before creating and setting a new Game world active.
JulianYoung JulianYoung

2017/1/10

#
How would i do that. as in before the
        super(x, y, 1); 
in the game world(when i tried putting anything but that first i got a error message)
danpost danpost

2017/1/10

#
You wrote:
JulianYoung wrote...
next is the code for my run button
Greenfoot.setWorld(new Game());
if(Game.Grid==8){
    Game.x=500;
    Game.y=500;
}
if(Game.Grid==9){
    Game.x=550;
    Game.y=550;
}
if(Game.Grid==10){
    Game.x=600;
    Game.y=600;
}
I wrote:
danpost wrote...
In your run button ('Play' button) code
Move the first line to be the last.
JulianYoung JulianYoung

2017/1/10

#
YAY! Thanks for help!!
You need to login to post a reply.
4
5
6
7