0

I'm developing a small game engine in Java and I use Swing to collect input and display graphics. I'm having a strange bug with MouseMoved events and I'm wondering whether the EDT handles the inputs in a given order or not, to understand if something else is wrong with my code or not. I couldn't find any information online. This is my mouseMoved() method:

gameFrame.addMouseMotionListener(new MouseMotionAdapter() {
    @Override
    public void mouseMoved(MouseEvent e) {
        GameScene lastScene = null;
        synchronized (scenes) {
            if (scenes.size() > 0) {
                lastScene = scenes.get(scenes.size() - 1);
            }
        }
        if (lastScene != null && lastScene.isRunning()) {
            lastScene.mouseMoved((int) (e.getX() / scale), (int) (e.getY() / scale), cameraX, cameraY, scale);
        }
    }
});

According to System.nanotime() it runs in way less than a millisecond.

grecLon
  • 37
  • 6
  • IMHO `MouseMoved` events that are not delivered in chronological order seem pretty useless (think for example of a freehand drawing program), so I would guess that they are always delivered in chronological order without the need to separately document it. – Thomas Kläger Apr 17 '21 at 09:15
  • You can always have a look at the [`InputEvent#getWhen`](https://docs.oracle.com/javase/10/docs/api/java/awt/event/InputEvent.html#getWhen()) result – MadProgrammer Apr 17 '21 at 09:22
  • 1
    *to understand if something else is wrong with my code* - that would be my guess. For one thing there is no need for the "synchronized". Listener code executes on the EDT. The events will be processed in the order they are generated. – camickr Apr 17 '21 at 14:46

0 Answers0