Search in sources :

Example 1 with ApplicationType

use of com.badlogic.gdx.Application.ApplicationType in project libgdx by libgdx.

the class Controllers method initialize.

private static void initialize() {
    if (managers.containsKey(Gdx.app))
        return;
    String className = null;
    ApplicationType type = Gdx.app.getType();
    ControllerManager manager = null;
    if (type == ApplicationType.Android) {
        if (Gdx.app.getVersion() >= 12) {
            className = "com.badlogic.gdx.controllers.android.AndroidControllers";
        } else {
            Gdx.app.log(TAG, "No controller manager is available for Android versions < API level 12");
            manager = new ControllerManagerStub();
        }
    } else if (type == ApplicationType.Desktop) {
        if (Gdx.graphics.getType() == GraphicsType.LWJGL3) {
            className = "com.badlogic.gdx.controllers.lwjgl3.Lwjgl3ControllerManager";
        } else {
            className = "com.badlogic.gdx.controllers.desktop.DesktopControllerManager";
        }
    } else if (type == ApplicationType.WebGL) {
        className = "com.badlogic.gdx.controllers.gwt.GwtControllers";
    } else {
        Gdx.app.log(TAG, "No controller manager is available for: " + Gdx.app.getType());
        manager = new ControllerManagerStub();
    }
    if (manager == null) {
        try {
            Class controllerManagerClass = ClassReflection.forName(className);
            manager = (ControllerManager) ClassReflection.newInstance(controllerManagerClass);
        } catch (Throwable ex) {
            throw new GdxRuntimeException("Error creating controller manager: " + className, ex);
        }
    }
    managers.put(Gdx.app, manager);
    final Application app = Gdx.app;
    Gdx.app.addLifecycleListener(new LifecycleListener() {

        @Override
        public void resume() {
        }

        @Override
        public void pause() {
        }

        @Override
        public void dispose() {
            managers.remove(app);
            Gdx.app.log(TAG, "removed manager for application, " + managers.size + " managers active");
        }
    });
    Gdx.app.log(TAG, "added manager for application, " + managers.size + " managers active");
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ApplicationType(com.badlogic.gdx.Application.ApplicationType) LifecycleListener(com.badlogic.gdx.LifecycleListener) Application(com.badlogic.gdx.Application)

Example 2 with ApplicationType

use of com.badlogic.gdx.Application.ApplicationType in project libgdx by libgdx.

the class Stage method act.

/** Calls the {@link Actor#act(float)} method on each actor in the stage. Typically called each frame. This method also fires
	 * enter and exit events.
	 * @param delta Time in seconds since the last frame. */
public void act(float delta) {
    // Update over actors. Done in act() because actors may change position, which can fire enter/exit without an input event.
    for (int pointer = 0, n = pointerOverActors.length; pointer < n; pointer++) {
        Actor overLast = pointerOverActors[pointer];
        // Check if pointer is gone.
        if (!pointerTouched[pointer]) {
            if (overLast != null) {
                pointerOverActors[pointer] = null;
                screenToStageCoordinates(tempCoords.set(pointerScreenX[pointer], pointerScreenY[pointer]));
                // Exit over last.
                InputEvent event = Pools.obtain(InputEvent.class);
                event.setType(InputEvent.Type.exit);
                event.setStage(this);
                event.setStageX(tempCoords.x);
                event.setStageY(tempCoords.y);
                event.setRelatedActor(overLast);
                event.setPointer(pointer);
                overLast.fire(event);
                Pools.free(event);
            }
            continue;
        }
        // Update over actor for the pointer.
        pointerOverActors[pointer] = fireEnterAndExit(overLast, pointerScreenX[pointer], pointerScreenY[pointer], pointer);
    }
    // Update over actor for the mouse on the desktop.
    ApplicationType type = Gdx.app.getType();
    if (type == ApplicationType.Desktop || type == ApplicationType.Applet || type == ApplicationType.WebGL)
        mouseOverActor = fireEnterAndExit(mouseOverActor, mouseScreenX, mouseScreenY, -1);
    root.act(delta);
}
Also used : ApplicationType(com.badlogic.gdx.Application.ApplicationType)

Aggregations

ApplicationType (com.badlogic.gdx.Application.ApplicationType)2 Application (com.badlogic.gdx.Application)1 LifecycleListener (com.badlogic.gdx.LifecycleListener)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1