I dont understand how to fix this error:
Because my World Classes says:
OK - this is the code with causes the error: (Class called "underMouse"
"mouse" code:
Please help!!! Thanks!
PStiger
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:656) at greenfoot.Actor.getX(Actor.java:157) at underMouse.act(underMouse.java:15) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194)
addObject(new mouse(), 100, 100); addObject(new underMouse(),111,92);
public void act() { mouse m = new mouse(); int x = m.getX(); int y = m.getY(); int r = m.getRotation(); if (Greenfoot.isKeyDown("w") || Greenfoot.isKeyDown("s")) { turnTo(r); moveTo(x+11,y-8); } }
public void act() { MouseInfo mouse = Greenfoot.getMouseInfo(); if(mouse != null) setRotation((int)(180*Math.atan2(mouse.getY()-getY(),mouse.getX()-getX())/Math.PI)); if (Greenfoot.isKeyDown("w")) { turnTo(getRotation()); move(2); } if (Greenfoot.isKeyDown("s")) { turnTo(getRotation()); move(-2); } }