This site requires JavaScript, please enable it in your browser!
Greenfoot
Username
Password
Remember Me?
Sign Up, Lost Password
Activity
About
Documentation
Download
Discuss
Scenarios
What is happening right now?
Latest Scenarios
nave
Baigalmaa
Flappy Mario
game4
build a house
meow
more
Popular Scenarios
Spacebear
turtle
evil crocodile
Cat Clicker V1....
Street Life
Kingdom: Live i...
more
Popular Users
more
Popular Collections
Optical Illusions
Reusable actors...
Scenario showcase
Demos by danpost
more
New Scenario: nave
By lhouhou - about 1 hour ago
New Scenario: Baigalmaa
By bbaigalaa92 - about 6 hours ago
Baigalmaa togloom
How to call this method in a class from another class.
By Shadowolf, with no replies.
Hello I want to make this object change its image when I let go of the mouse, but I set up all the images it could be set to and made a method but in the other class it only adds the object to the world and doesn't change the image. The class with the method that I want to change: public class TriangleAnswer extends Actor { public void randomize() { int image = (int)(Math.random() * 20) + 1; if(image == 1) { setImage("1.png"); } if(image == 2) { setImage("2.png"); } if(image == 3) { setImage("3.png"); } if(image == 4) { setImage("4.png"); } if(image == 5) { setImage("5.png"); } if(image == 6) { setImage("6.png"); } if(image == 7) { setImage("7.png"); } if(image == 8) { setImage("8.png"); } if(image == 9) { setImage("9.png"); } if(image == 10) { setImage("10.png"); } if(image == 11) { setImage("11.png"); } if(image == 12) { setImage("12.png"); } if(image == 13) { setImage("13.png"); } if(image == 14) { setImage("14.png"); } if(image == 15) { setImage("15.png"); } if(image == 16) { setImage("16.png"); } if(image == 17) { setImage("17.png"); } if(image == 18) { setImage("18.png"); } if(image == 19) { setImage("19.png"); } else { setImage("20.png"); } } } The class I want to call the method in: public class Magic8Ball extends Actor { //Leave this field alone, this will be the Triangle on the screen private TriangleAnswer triangle = new TriangleAnswer(); public void act() { if(Greenfoot.mouseDragged(this)) { <---- // I want to put it here MouseInfo m = Greenfoot.getMouseInfo(); setLocation(m.getX(),m.getY()); if(isTouching(TriangleAnswer.class)) { removeTouching(TriangleAnswer.class); } } if(Greenfoot.mouseDragEnded(this)) { int xMove = (int)(Math.random() *201)-100; int yMove = (int)(Math.random() *201)-100; getWorld().addObject(triangle, getX() + xMove, getY() + yMove); } } } thank you
Update: Flappy Mario
By lhouhou - about 11 hours ago
game Flappy Bird
New Scenario: game4
By munkh-ireedui - about 14 hours ago
New Scenario: build a house
By unurjargal - about 14 hours ago
Update: meow
By Temuulen - about 14 hours ago
d
New Scenario: ENKH-ITGEL
By enkh-itgel - about 14 hours ago
New Scenario: pacman
By Tuvshinzaya - about 14 hours ago
New Scenario: game5
By Tushig - about 14 hours ago
Update: game3
By Tuvshinzaya - about 14 hours ago
Comment on Kingdom: Live into Another World
By ibanana - about 19 hours ago
wow... cool updates
X
Comment on Kingdom: Live into Another World