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

2013/3/21

Passing variables to other classes? possible?

RobTheRipper RobTheRipper

2013/3/21

#
lets say i want Actor X to roam around the world, and when he encounters Actor Z, i want Actor Y to be affected... is there a way to do this?
danpost danpost

2013/3/21

#
If there is one ActorY object in the world and always one ActorY object in the world then:
ActorY actorY  = (ActorY)getWorld().getObjects(ActorY).get(0);
will set 'actorY' to the ActorY object and you can then use dot notation on 'actorY' to access methods and fields in the ActorY class.
RobTheRipper RobTheRipper

2013/3/21

#
what about if there are multiple Actors, and i want only the one actor X touches, to be effected?
danpost danpost

2013/3/21

#
In your initial post, you mention 3 different actors. I will, from your secondary post, now assume that Actor Z and Actor Y are the same actor. Therefore:
ActorY actorY = (ActorY) getOneIntersectingObject(ActorY.class);
You need to login to post a reply.