Example usage for com.google.gwt.maeglin89273.game.mengine.core MEngine getMousePosition

List of usage examples for com.google.gwt.maeglin89273.game.mengine.core MEngine getMousePosition

Introduction

In this page you can find the example usage for com.google.gwt.maeglin89273.game.mengine.core MEngine getMousePosition.

Prototype

public static Point getMousePosition() 

Source Link

Usage

From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.ElectronicsVolcanoGame.java

@Override
public void init() {
    volcanoWorld = new VolcanoWorld(getWidth(), getHeight());
    layer = new WorldLayer(volcanoWorld.getBounds(), 2.5f) {

        @Override/*w ww.j  av  a2s  .c o  m*/
        public void updateComponents() {
            volcanoWorld.update();

        }

        @Override
        public void drawComponents(Context2d context) {
            volcanoWorld.draw(context);

        }

    };
    MEngine.addMouseDownHandler(new MouseDownHandler() {

        @Override
        public void onMouseDown(MouseDownEvent event) {
            grabPoint = MEngine.getMousePosition();

        }
    });

    MEngine.addMouseUpHandler(new MouseUpHandler() {

        @Override
        public void onMouseUp(MouseUpEvent event) {
            layer.getCamera().move(MEngine.getMousePosition().delta(grabPoint), false);
            grabPoint = null;
        }

    });
    MEngine.addMouseWheelHandler(new MouseWheelHandler() {

        @Override
        public void onMouseWheel(MouseWheelEvent event) {
            if (event.isNorth())
                layer.getCamera().zoomIn();
            if (event.isSouth())
                layer.getCamera().zoomOut();
        }

    });
    MEngine.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == ' ')
                volcanoWorld.erupt();

        }

    });
}

From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.ElectronicsVolcanoGame.java

@Override
public void update() {
    if (grabPoint != null) {
        Point mP = MEngine.getMousePosition();
        layer.getCamera().move(mP.delta(grabPoint), true);
        grabPoint.setPosition(mP);//from  w  ww .  j ava  2  s. c o  m
    }
    layer.update();
}