Diskuze: Problémy s KeyEvent
V předchozím kvízu, Online test znalostí Java, jsme si ověřili nabyté zkušenosti z kurzu.

Člen

Zobrazeno 7 zpráv z 7.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Online test znalostí Java, jsme si ověřili nabyté zkušenosti z kurzu.
Dokud neuvedeš zdrojový kód a znění chyby, tak ti nikdo nepomůže.
This kind of launch is configured to open the Debug perspectice when it suspends. This Debug perspective is desinged to support application debugging. It incorporates views for disokaying debug stact, variables and breakpoint management. a k tomu otázka :do you eant open this prespection now? a když da´m yes tak nic se neďeje program beží dál ale nic se nevikresluje PS:ďelám menší hru.
Protože to spouštíš jako debug. Chybu máš někde jinde a bez kódu to asi těžko zjistíme. Mimochodem, na hru tu jsou teď tutoriály a pod nimi je vždy ke stažení projekt. Můžeš si tak najít chybu.
jo a kód je :
public class Player extends Entity{
private Vector positionPlayer;
private Vector velocity;
private boolean isFalling;
private int key;
private KeyEvent e;
public Player(Game layer) {
super(layer);
this.color = Color.GREEN;
this.width = 20;
this.height = this.width;
this.positionPlayer = new Vector(1280 / 2 - (this.width / 2), 720 / 2 - (this.height / 2));
this.velocity = new Vector(positionPlayer.x - positionPlayer.x, positionPlayer.y - positionPlayer.y);
this.isFalling = false;
}
public void render(Graphics g) {
g.setColor(color);
g.fillRect(this.positionPlayer.x, this.positionPlayer.y, this.width, this.height);
}
public void update() {
this.positionPlayer.x += this.velocity.x;
this.positionPlayer.y += this.velocity.y;
this.key = this.e.getKeyCode();
if (key == KeyEvent.VK_A){
}
if (this.positionPlayer.y + this.height <= 720){
this.velocity.y = 8;
this.isFalling = true;
}else{
this.velocity.y = 0;
this.isFalling = false;
}
}
}
"jo a importi jsem tam nedal"
To máš úplně špatně, tu událost ti musí něco vyvolat. Koukni na ten seriál, co tu teď vychází, přesně to se tam řeší.
no ďelal jsem to podle vašeho tutoriálu:
public class Player extends Entity{
private Vector positionPlayer;
public Vector velocity;
private Enumerator enumerator;
private boolean isFalling;
public Player(Game layer) {
super(layer);
this.color = Color.GREEN;
this.width = 20;
this.height = this.width;
this.positionPlayer = new Vector(1280 / 2 - (this.width / 2), 720 / 2 - (this.height / 2));
this.velocity = new Vector(this.positionPlayer.x - this.positionPlayer.x, this.positionPlayer.y - this.positionPlayer.y);
this.isFalling = false;
}
public Enumerator getKeyDown(){
return enumerator;
}
public void setKeyDown(Enumerator enumer){
this.enumerator = enumer;
}
public void render(Graphics g) {
g.setColor(color);
g.fillRect(this.positionPlayer.x, this.positionPlayer.y, this.width, this.height);
}
public void update() {
this.positionPlayer.x += this.velocity.x;
this.positionPlayer.y += this.velocity.y;
if (this.positionPlayer.y + this.height <= 720){
this.velocity.y = 8;
this.isFalling = true;
}else{
this.velocity.y = 0;
this.isFalling = false;
}
switch (getKeyDown()){
case Up:
break;
case Down:
break;
case Left:
this.velocity.x = -3;
break;
case Right:
this.velocity.x = 3;
break;
case SprintLeft:
this.velocity.x = -6;
break;
case SprintRight:
this.velocity.x = 6;
break;
case Jump:
break;
}
}
}
class KeyManager extends KeyAdapter{
private int key;
private Player pl;
public void KeyPressed(KeyEvent e){
key = e.getKeyCode();
if (key == KeyEvent.VK_A){
pl.setKeyDown(Enumerator.Left);
}
}
}
ale stále chyba a zase ta samá..
Zobrazeno 7 zpráv z 7.