Hey,
I have a short question:
I would like to click on an object with the mouse, after which something happens - for example, I click on an box and then it opens the next level in a game.
Can someone help me?
Thanks already in advance =)


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public void act() { MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse!= null ){ button = mouse.getButton(); if (button == 1 && Greenfoot.mouseClicked( null )) { if (mouse.getY() = getY() && mouse.getX() = getX()) { World nextWorld = new World2(); Greenfoot.setWorld(nextWorld); } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import greenfoot.*; public class Menue extends World { public Menue() { super ( 1000 , 600 , 1 ); button e = new button(); addObject(e, 700 , 500 ); } public void act() { test(); } public void test(){ MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse!= null ){ button = mouse.getButton(); if (a == 1 && Greenfoot.mouseClicked( null )) { if (mouse.getY() = getY() && mouse.getX() = getX()) { World nextWorld = new World2(); Greenfoot.setWorld(nextWorld); } } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import greenfoot.*; public class Menue extends World { public int button; public Menue() { super ( 1000 , 600 , 1 ); button e = new button(); addObject(e, 700 , 500 ); } public void act() { test(); } public void test(){ MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse!= null ){ button = mouse.getButton(); if (a == 1 && Greenfoot.mouseClicked( null )) { if (mouse.getY() = getY() && mouse.getX() = getX()) { World nextWorld = new World2(); Greenfoot.setWorld(nextWorld); } } } } } |
1 | if (mouse.getY() = getY() && mouse.getX() = getX()) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import greenfoot.*; public class Menue extends World { public int button; public Menue() { super ( 1000 , 600 , 1 ); button e = new button(); addObject(e, 700 , 500 ); } public void act() { test(); } public void test(){ MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse!= null ){ button = mouse.getButton(); if (button == 1 && Greenfoot.mouseClicked( null )) { if (mouse.getY() = getY() && mouse.getX() = getX()) { World nextWorld = new World2(); Greenfoot.setWorld(nextWorld); } } } } } |