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

2020/2/16

Location of actor

tbag tbag

2020/2/16

#
How do I make an actor(A) appear where another actor(B) is located at?? and by appear I meant at the preset location of actor B and actor A must move along with actor B unless I press another key to release it.
danpost danpost

2020/2/16

#
tbag wrote...
How do I make an actor(A) appear where another actor(B) is located at?? and by appear I meant at the preset location of actor B and actor A must move along with actor B unless I press another key to release it.
Add a field to ActorB to hold an ActorA object:
/** In ActorB Class */
// add field
private Actor actorA; // 'null' by default

// via act, after moving
if (actorA != null) actorA.setLocation(getX(), getY());

// to release
if (Greenfoot.isKeyDown(<< release key >>)) actorA = null;
You need to login to post a reply.