This site requires JavaScript, please enable it in your browser!
Greenfoot back
thinud.bothma@reddam.house
thinud.bothma@reddam.house wrote ...

2020/4/28

Click on Greenfoot image in the world

How do I register a left mouse click on a Greenfoot Image
public class MyWorld extends World{
    GreenfootImage balBinne;
    public MyWorld(){   
        super(800, 600, 1);
        balBinne=new GreenfootImage("balBinne.png");
        getBackground().drawImage(balBinne, 250, 380);
    }//myWorld
  
    
    public void act(){

    }
    
}//myWorld
Super_Hippo Super_Hippo

2020/4/28

#
You could check if a click was detected and check if the click happened between (250|380) and (250+width of image|380+height of image). However, it seems to be a better idea to have an Actor object, assign the image to it and add it to the world. Then you can simply check if a click on that Actor object happened.
An Actor object works perfect, but I do not want the image to be movable. How do you stop the user from moving an actor with the mouse?
danpost danpost

2020/4/28

#
thinud.bothma@reddam.house wrote...
An Actor object works perfect, but I do not want the image to be movable. How do you stop the user from moving an actor with the mouse?
Add the following to its class:
public void setLocation(int x, int y) { }
I can still move the Actor with the mouse. I must not be able to move.
danpost danpost

2020/5/1

#
thinud.bothma@reddam.house wrote...
I can still move the Actor with the mouse. I must not be able to move.
Show the class codes of this actor.
You need to login to post a reply.