게임에 타이머가 필요합니다 ... 운 좋게도 많이 찾았습니다.자바 타이머가 필요합니다
도와주세요.
// code not compiled nor tested. It was typed free-hand.
// so it was not meant to be copy, pasted and used, but rather to show you
// the idea.
public void mouseClicked(MouseEvent e) {
mouseX = e.getX();
mouseY = e.getY();
// don't use if (shot == false). Instead do:
if (!shot) {
Ink = 0;
}
// likewise, no need to use if (ready == true). Instead do:
if (ready) {
shot = true;
// turn off your ability to shoot here by setting a boolean.
ableToShoot = false;
// start a Swing Timer that does not repeat
// in the Timer turn back on the ability to shoot by setting a boolean
Timer swingTimer = new Timer(TIMER_DELAY_TIME, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// allow shots here
ableToShoot = true;
}
});
swingTimer.setRepeats(false);
swingTimer.start();
}
}
참고 : 스윙 타이머를 사용하여 다시
public void mouseClicked(MouseEvent e) {
mouseX = e.getX();
mouseY = e.getY();
if(shot == false){
Ink = 0;
}
if(ready == true){
shot = true;
// I need a timer here to wait a second and then stop shooting.
}
}
: 개선 Timer'과 행운을 스윙 '에 대한 검색. 튜토리얼을 확인한 후에도 도움이 필요하다면, 타이머를 사용하려는 대상과 코드가 작동하지 않는 방법에 대해 자세히 알려주십시오. –
@HovercraftFullOfEels 나중에 보았습니다. 나는 코멘트를 삭제했다. –