IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Problémy s KeyEvent

Aktivity
Avatar
James
Člen
Avatar
James:25.9.2013 16:34

Když si dám na začátku třídy "private int key; private KeyEvent e;" a pak "this.key = this.e.getKey­Code();" a hází to věčně chybu ale nani neni napsaná pls poraďte ... :(

Odpovědět
25.9.2013 16:34
Slovo nikdy znamená že cesta k cíly je pouze o něco těžší než se zdálo.
Avatar
David Hartinger
Vlastník
Avatar
Odpovídá na James
David Hartinger:25.9.2013 16:41

Dokud neuvedeš zdrojový kód a znění chyby, tak ti nikdo nepomůže.

Nahoru Odpovědět
25.9.2013 16:41
New kid back on the block with a R.I.P
Avatar
James
Člen
Avatar
Odpovídá na David Hartinger
James:25.9.2013 16:46

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.

Nahoru Odpovědět
25.9.2013 16:46
Slovo nikdy znamená že cesta k cíly je pouze o něco těžší než se zdálo.
Avatar
David Hartinger
Vlastník
Avatar
Odpovídá na James
David Hartinger:25.9.2013 16:49

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.

Nahoru Odpovědět
25.9.2013 16:49
New kid back on the block with a R.I.P
Avatar
James
Člen
Avatar
James:25.9.2013 16:50

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"

Nahoru Odpovědět
25.9.2013 16:50
Slovo nikdy znamená že cesta k cíly je pouze o něco těžší než se zdálo.
Avatar
David Hartinger
Vlastník
Avatar
Odpovídá na James
David Hartinger:25.9.2013 16:54

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ší.

Nahoru Odpovědět
25.9.2013 16:54
New kid back on the block with a R.I.P
Avatar
James
Člen
Avatar
Odpovídá na David Hartinger
James:25.9.2013 18:17

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á.. :(

Nahoru Odpovědět
25.9.2013 18:17
Slovo nikdy znamená že cesta k cíly je pouze o něco těžší než se zdálo.
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 7 zpráv z 7.