This site requires JavaScript, please enable it in your browser!
Greenfoot back
nicholaskeegan79@gmail.com
nicholaskeegan79@gmail.com wrote ...

2020/7/3

Hey i am looking to create an actor which will face left when moving left and vice versa.

To do this I have two actor classes, one of the classes has the normal image and the other has a mirror image of the first class. This is the code i have decided to use; public void move() { Actor Right = getOneObjectAtOffset(0,0, CharacterLeft.class); if(Greenfoot.isKeyDown("right")) { setLocation(getX() + SPEED , getY()); } if(Greenfoot.isKeyDown("left")) { setLocation(getX() - SPEED, getY()); Left L = new Left(); getWorld().addObject(L, getX(), getY()); getWorld().removeObjects(getWorld().getObjects(Right.class)); } } However i continuolsy get this error; "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." Any Suggestions Thanks
danpost danpost

2020/7/3

#
nicholaskeegan79@gmail.com wrote...
To do this I have two actor classes, one of the classes has the normal image and the other has a mirror image of the first class.
A better way is to use just one actor and change its image when needed.
You need to login to post a reply.