Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » HALP keyPressed is repeated(idk why. im new here.)
HALP keyPressed is repeated [message #1794020] Wed, 22 August 2018 14:10
danar keren is currently offline danar kerenFriend
Messages: 1
Registered: August 2018
Junior Member
ok so i put this on my keyinput class
package com.game.main;

package com.game.main;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;


public class KeyInput extends KeyAdapter{


private Handler handler;

public KeyInput(Handler handler) {
this.handler = handler;
}
@Override
public void keyPressed(KeyEvent e){

int key = e.getKeyCode();
for(int i = 0; i < handler.object.size(); i++){
GameObject tempObject = handler.object.get(i);

if(tempObject.getid() == ID.Player) {
if(e.getKeyCode() == KeyEvent.VK_W) tempObject.setvelY(tempObject.getvelY() - 5);
if(e.getKeyCode() == KeyEvent.VK_A) tempObject.setvelX(tempObject.getvelX() - 5);
if(e.getKeyCode() == KeyEvent.VK_S) tempObject.setvelY(tempObject.getvelY() + 5);
if(e.getKeyCode() == KeyEvent.VK_D) tempObject.setvelX(tempObject.getvelX() + 5);
}
}
if(key == KeyEvent.VK_ESCAPE)System.exit(1);

System.out.println("you pressed " + key);
}


public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
for(int i = 0; i < handler.object.size(); i++){
GameObject tempObject = handler.object.get(i);

if(tempObject.getid() == ID.Player) {
if(key == KeyEvent.VK_W) tempObject.setvelY(0);
if(key == KeyEvent.VK_D) tempObject.setvelX(0);
if(key == KeyEvent.VK_A) tempObject.setvelX(0);
if(key == KeyEvent.VK_S) tempObject.setvelY(0);
}
}


System.out.println("you released " + key);
}


}

ok im new here im still learning
(thx to this guy
RealTutsGML)

this is the log when i hold the W key:
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you pressed 87
you released 87

halp plszz my life depends on this
Previous Topic:Accessing XML Code from GSN in Visio
Next Topic:Unexpected results of creating module-info.java
Goto Forum:
  


Current Time: Tue Sep 18 20:06:44 GMT 2018

Powered by FUDForum. Page generated in 0.02780 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top