Hi guys, I want to create a code, that changes the background when I am with the mouth over a specific area of the background. Do you know how to do that?


1 2 3 4 5 6 7 8 9 10 | // field private boolean altBackground; // via act MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse != null && (mouse.getX > 100 && mouse.getX() < 200 && mouse.getY() > 300 && mouse.getY() < 400 ) != altBackground) { altBackground = ! altBackground; setBackground(altBackground ? "altBackground.jpg" : "mainBackground.jpg" ); } |