I have the following code in Game.java:
public void start ()
{
Thread thread = new Thread(this);
thread.start();
this.world = new World();
}
In the world class, I have the actual items of my game, a set of Walls, food and a player.
public class World {
private Food food;
private HashSet<Wall> walls = new HashSet<Wall>();
private Player player;
...
}
The problem is as follows: I want to have my keylisteners in the player class but I can't seem to figure out how to get this...
I've tried by implementing the KeyListener class in Player.java and implementing the 3 functions that come with that. However, player.java does not allow me to use this.addKeyListener(this) So my keyevents are never triggered...
How can I make this work?
您需要在Applet
/ JApplet
上调用addKeyListener
并传递( 相同 !) player
实例作为侦听器。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.