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

2020/4/28

Button doesn't work

neoaspect neoaspect

2020/4/28

#
Hi, I'm relatively new to Greenfoot and coding in general. Currently, I'm experiencing an issue on a button I've created that is supposed to change the world to the StartScreen when clicked on but it doesn't. No errors show up in the code and I'm not quite sure how to solve this. The code goes:
public void act() 
    {
        MouseInfo mouse = Greenfoot.getMouseInfo();
        //Change Button.class to the name of your button class.
        if (mouse != null) {
            //change the file to what you want for when the mouse is not over the button.
            setImage("next1.png");
            java.util.List objects = getWorld().getObjectsAt(mouse.getX(), mouse.getY(), NextButton2.class);
            for (Object object : objects)
            {
                if (object == this)
                {
                    //change the file to what you want for when the mouse is over the button.
                    setImage("next2.png");
                }
            }
        }
        if (Greenfoot.mouseClicked(this)) {
            Greenfoot.setWorld(new StartScreen());
        }    
    }    
danpost danpost

2020/4/28

#
Can you grab and move by dragging the button with the mouse while the scenario is paused?
neoaspect neoaspect

2020/4/28

#
No I cannot
danpost danpost

2020/4/28

#
neoaspect wrote...
No I cannot
Then you probably have another actor's image over on top of the button.
You need to login to post a reply.