I use two instances of an actor. The instructor of every instance gets 4 different keynames. The goal is to control each Actor-instance with his own keyset.
But only the first instance reacts to his keyset, the second doesn't!
Why???
Here is the code (only the important snippet):
Thanks for explanation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | public class Player extends Actor { private Point destination; private final String rechts, unten, oben, links; // keynames for the directions private String name; // playername // Constructor: public Player(String rechts, String unten, String links, String oben, Point destination, String name, String filename) { this .rechts = rechts; this .unten = unten; this .links = links; this .oben = oben; this .destination = destination; this .name = name; this .setImage(filename); } public void act() { String key = Greenfoot.getKey(); if (key != null ) { if (key.equals(rechts)) { setRotation( 0 ); move( 1 ); } else if (key.equals(unten)) { setRotation( 90 ); move( 1 ); } else if (key.equals(links)) { setRotation( 180 ); move( 1 ); } else if (key.equals(oben)) { setRotation( 270 ); move( 1 ); } } } } |