This site requires JavaScript, please enable it in your browser!
Greenfoot back
SystemZero
SystemZero wrote ...

2017/7/16

Obstacles in the map.

SystemZero SystemZero

2017/7/16

#
I have this
 if(getX().Luchador== getX().Obstacle && getY().Luchador== getY().Obstacle){
            move=-1;
        }
What i need to do is when the Luchador touch the obstacle, the direccion of the Luchador changes, but there is a problem.
Super_Hippo Super_Hippo

2017/7/16

#
Try to use the isTouching method:
if (isTouching(Obstacle.class))
{
    //do something
}
SystemZero SystemZero

2017/7/17

#
Super_Hippo wrote...
Try to use the isTouching method:
if (isTouching(Obstacle.class))
{
    //do something
}
I use your code, but there“s a problem: 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:711) at greenfoot.Actor.isTouching(Actor.java:972) at Luchador.act(Luchador.java:178) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211) Im doing this:
if (isTouching(Obstaculo.class))
           {
             setRotation(Greenfoot.getRandomNumber(8));
           }
Super_Hippo Super_Hippo

2017/7/17

#
Did you put the code into the act method? If this is already the case, make sure you don't remove the object from the world before this code is executed.
You need to login to post a reply.