Problems with Java's Paint method, ridiculous refresh velocity

后端 未结 3 1437
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 23:12

I\'m developing a very simple version of R-Type as work for the university, but despite it works, the craft velocity is a lot of slow, so the movement is ugly and clumsy. I

3条回答
  •  北海茫月
    2020-11-27 23:51

    • The image fondo should already be scaled to 1200x600.
    • I am not sure, but is super.paint(g) needed? You might also use paintComponent.

    The event handling (you seem to be moving by 1 pixel on key down), must be done correctly. I would have set the direction and speed (1px), and leave it to a swing timer to do the continuous moving.

    Repainting best is done resilient/flexible: repaint(20L) (50 frames per second); events like key-down maybe with EventQueue.invokeLater(new Runnable() { ... });.

    Especially you might use repaint with the changed area.

提交回复
热议问题