2
그래서 저는 Java로 게임을 작성하고 있습니다. 플레이어, 적, 샷을 표현하기 위해 drawRect() 메소드를 사용하기 시작했습니다. 모든 것이 훌륭했습니다. 그 다음 나는 공상에 들려고 노력하기로 결정했다. 각 개체의 .png 이미지를 직접 만들고 Graphics2D drawImage() 메서드를 사용했습니다. 모든 것이 천천히 시작되었습니다. 프로세스 속도를 높이는 다른 방법이 있습니까?자바 JPanel 애니메이션
내 애니메이션은 스윙 타이머
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D)g;
player1.paintShips(g);
g2d.drawImage(bGround, 14, 14, this);
try{
for(Shot s: liveRounds){ //liveRounds is an ArrayList of Shots
if(!inBounds.contains(s.getRect()) || villains.collision(s)){
if(villains.collision(s)){
villains.collided(s, this);
}
liveRounds.remove(s);
roundCount--;
}
else{
s.paintShot(g, this);
}
}
}catch(ConcurrentModificationException e){};
villains.paintEnemyGrid(g, this);
g2d.setColor(Color.cyan);
g2d.draw(hitZone1);
g2d.setColor(Color.red);
g.drawString("X: " + player1.getX(1) + " Y: " + player1.getY(1), 370, 150);
g2d.draw(inBounds);
g.drawString(score + "", 440, 40);
g.dispose();
}
애니메이션에 어떤 조언 튜토리얼을 기반으로? 감사합니다.
타이머의 지연은 얼마나됩니까? 왜 당신은'ConcurrentModificationException'을 잡아서 무시하고 있습니까? 객체를 반복 할 때'Collection' 객체를 제거하려면 while 루프에서 수동으로'Iterator'를 사용하고'Iterator # remove'를 사용해야합니다. – Jeffrey
10로 설정했는데 너무 빠를까요? – user1320716
10ms 지연은 초당 100 프레임입니다. 그것은 거의 확실하게 너무 빠릅니다. – Jeffrey