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

2016/9/24

Help With mouseClicked

AAkira AAkira

2016/9/24

#
i have a class which when i click it the world will change, but it seems doesnt work, any help? code for the class
public class Quit extends Property
{

    public void act() 
    
    {
        if (Greenfoot.mouseClicked(this)) {
            Greenfoot.setWorld(new CreditWorld());
        }
    }
}
Super_Hippo Super_Hippo

2016/9/24

#
I am not seeing an error in the code. Is an object of the Quit class added to the world? Does the Quit class have an default image?
danpost danpost

2016/9/24

#
Try adding the following line to the World class constructor (after the 'super' call):
setPaintOrder(Quit.class);
AAkira AAkira

2016/9/25

#
Super_Hippo wrote...
I am not seeing an error in the code. Is an object of the Quit class added to the world? Does the Quit class have an default image?
Its already added to current world and yes, it has image on it
AAkira AAkira

2016/9/25

#
danpost wrote...
Try adding the following line to the World class constructor (after the 'super' call):
setPaintOrder(Quit.class);
already done that but still not working
AAkira AAkira

2016/9/25

#
Super_Hippo wrote...
I am not seeing an error in the code. Is an object of the Quit class added to the world? Does the Quit class have an default image?
im using scenario image (left click the class and set image), not using code to add the image
danpost danpost

2016/9/25

#
Please post the entire CreditWorld class. Oh, and inform as the what type of world the Quit object is in.
AAkira AAkira

2016/9/26

#
Code for LoserWorld which Quit class is in
public class LoserWorld extends World
{
    
    public LoserWorld(int score)
   
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(429, 620, 1);
        prepare();
        GameOver pic = new GameOver();
        addObject(pic,214,348);
        showText("" + score ,250,351);
        Quit quit = new Quit();
        addObject(quit,80,400);
        Restart restart = new Restart();
        addObject(restart,350,400);
    }
    public void prepare() {
    setPaintOrder(Quit.class);
}
code for CreditWorld, basically theres nothing in it because its only show credit picture
public class CreditWorld extends World
{

    public CreditWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(460, 620, 1); 
    }
}
danpost danpost

2016/9/26

#
Okay, that eliminates one possibility. Now, post your entire Property class.
You need to login to post a reply.