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

2018/12/18

Problem with "Greenfoot.mouseClicked"

1
2
3
Nahquin Nahquin

2018/12/18

#
So i have Button but have a prooblem with clicking on it..
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Restart extends Moduls
{
    public void act() 
    {
        if(Greenfoot.mouseClicked(this)){
            SnakeW w = new SnakeW(); 
            Greenfoot.setWorld(w); 
        }
    }   
        
    public Restart(){
        newSize(2);
    }
}
The Greenfoot doesnt set up the SnakeW when clicking
danpost danpost

2018/12/18

#
To test, change act method to this:
public void act()
{
    if (Greenfoot.mouseClicked(null))
    {
        MouseInfo mouse = Greenfoot.getMouseInfo();
        Actor actor = mouse.getActor();
        System.out.println("Actor clicked: "+actor);
        if (actor == this) Greenfoot.setWorld(new SnakeW());
    }
}
Reply here with what the terminal displays.
Nahquin Nahquin

2018/12/18

#
Actor clicked: Wall@587f3c Infinitly repeated. Have to change: Actor actor = mouse.getActor(); Actors in this? and for what if yes.
danpost danpost

2018/12/18

#
Nahquin wrote...
Actor clicked: Wall@587f3c Infinitly repeated. Have to change: Actor actor = mouse.getActor(); Actors in this? and for what if yes.
Mouse clicks are only accepted on top-most actor. Your wall is over your button. Add the following line into your World subclass constructor:
setPaintOrder(Moduls.class);
You can go back to your act method code as originally given.
Nahquin Nahquin

2018/12/18

#
Ok so i added
public void act(){
        setPaintOrder(Restart.class);   
    }
this to the world's act and the click still doesnt work
danpost danpost

2018/12/18

#
Nahquin wrote...
Ok so i added << Code Omitted >> this to the world's act and the click still doesnt work
Okay. Use the test act method in the Restart class and reply with what now shows in the terminal (clear the terminal, first).
Nahquin Nahquin

2018/12/18

#
already used in the Restart class. Still the Wall@587f3c get clicked
danpost danpost

2018/12/18

#
Nahquin wrote...
already used in the Restart class. Still the Wall@587f3c get clicked
See if this change does anything:
setPaintOrder(Restart.class, Wall.class);
Nahquin Nahquin

2018/12/18

#
Wall@182c65b
Nahquin Nahquin

2018/12/18

#
And write it for click dosnt need to click to the button
danpost danpost

2018/12/18

#
Nahquin wrote...
Wall@182c65b
Alright, last try with paint order:
setPaintOrder(Wall.class, Restart.class);
(but I do believe this is the wrong order. If this actually works, then the documentation on the method is inaccurate.
danpost danpost

2018/12/18

#
Nahquin wrote...
And write it for click dosnt need to click to the button
That is correct.
Nahquin Nahquin

2018/12/18

#
Alread use setPaintOrder in world
danpost danpost

2018/12/18

#
Nahquin wrote...
Alread use setPaintOrder in world
As I most recently modified?
Nahquin Nahquin

2018/12/18

#
yepp still wall just diferent number: Wall@45065
There are more replies on the next page.
1
2
3