com.badlogic.gdx.Application.ApplicationType Java Examples
The following examples show how to use
com.badlogic.gdx.Application.ApplicationType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GLTFDemo.java From gdx-gltf with Apache License 2.0 | 6 votes |
private void loadModelIndex() { rootFolder = Gdx.files.internal(samplesPath); String indexFilename = Gdx.app.getType() == ApplicationType.WebGL || Gdx.app.getType() == ApplicationType.Android ? "model-index-web.json" : "model-index.json"; FileHandle file = rootFolder.child(indexFilename); entries = new Json().fromJson(Array.class, ModelEntry.class, file); ui.entrySelector.setItems(entries); if(AUTOLOAD_ENTRY != null && AUTOLOAD_VARIANT != null){ for(int i=0 ; i<entries.size ; i++){ ModelEntry entry = entries.get(i); if(entry.name.equals(AUTOLOAD_ENTRY)){ ui.entrySelector.setSelected(entry); // will be auto select if there is only one variant. if(entry.variants.size != 1){ ui.variantSelector.setSelected(AUTOLOAD_VARIANT); } break; } } } }
Example #2
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 6 votes |
private void installDesktopGDXDialogs() { if (Gdx.app.getType() != ApplicationType.Desktop) { showDebugSkipInstall(ApplicationType.Desktop.name()); return; } try { final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.desktop.DesktopGDXDialogs"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance(); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.Desktop.name()); } catch (ReflectionException e) { showErrorInstall(ApplicationType.Desktop.name(), "desktop"); e.printStackTrace(); } }
Example #3
Source File: GDXDialogsSystem.java From gdx-dialogs with Apache License 2.0 | 6 votes |
private void installHTMLGDXDialogs() { if (Gdx.app.getType() != ApplicationType.WebGL) { showDebugSkipInstall(ApplicationType.WebGL.name()); return; } try { final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.html.HTMLGDXDialogs"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance(); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.WebGL.name()); } catch (ReflectionException e) { showErrorInstall(ApplicationType.WebGL.name(), "html"); e.printStackTrace(); } }
Example #4
Source File: Invaders.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
@Override public void create () { Array<Controller> controllers = Controllers.getControllers(); if (controllers.size > 0) { controller = controllers.first(); } Controllers.addListener(controllerListener); setScreen(new MainMenu(this)); music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/8.12.mp3", FileType.Internal)); music.setLooping(true); music.play(); Gdx.input.setInputProcessor(new InputAdapter() { @Override public boolean keyUp (int keycode) { if (keycode == Keys.ENTER && Gdx.app.getType() == ApplicationType.WebGL) { if (!Gdx.graphics.isFullscreen()) Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayModes()[0]); } return true; } }); fps = new FPSLogger(); }
Example #5
Source File: MusicManager.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
public void playMusic() { if (music != null && !music.isPlaying()) { try { music.play(); music.setLooping(desc.isLoop()); music.setVolume(desc.getVolume() * VOLUME_MULTIPLIER); } catch (Exception e) { // DEAL WITH OPENAL BUG if (Gdx.app.getType() == ApplicationType.Desktop && e.getMessage().contains("40963")) { EngineLogger.debug("!!!!!!!!!!!!!!!!!!!!!!!ERROR playing music trying again...!!!!!!!!!!!!!!!"); MusicDesc desc2 = desc; desc = null; setMusic(desc2); return; } EngineLogger.error("Error Playing music: " + desc.getFilename(), e); } } }
Example #6
Source File: MainMenu.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
@Override public void draw (float delta) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); viewMatrix.setToOrtho2D(0, 0, 480, 320); spriteBatch.setProjectionMatrix(viewMatrix); spriteBatch.setTransformMatrix(transformMatrix); spriteBatch.begin(); spriteBatch.disableBlending(); spriteBatch.setColor(Color.WHITE); spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false); spriteBatch.enableBlending(); spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 0, 512, 256, false, false); spriteBatch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA); glyphLayout.setText(font, "Touch screen to start!"); font.draw(spriteBatch, glyphLayout, 240 - glyphLayout.width / 2, 128); if (Gdx.app.getType() == ApplicationType.WebGL) { glyphLayout.setText(font, "Press Enter for Fullscreen Mode"); font.draw(spriteBatch, glyphLayout, 240 - glyphLayout.width / 2, 128 - font.getLineHeight()); } spriteBatch.end(); }
Example #7
Source File: Compatibility.java From Cubes with MIT License | 6 votes |
public void startCubes() { compatibility = this; Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler.instance); Thread.currentThread().setUncaughtExceptionHandler(UncaughtExceptionHandler.instance); try { if (applicationType == ApplicationType.HeadlessDesktop) { run(new ServerAdapter()); } else { run(new ClientAdapter()); } } catch (Exception e) { try { Log.error("Failed to start", CubesException.get(e)); } catch (Exception ex) { if (ex instanceof CubesException) { throw (CubesException) ex; } else { throw CubesException.get(e); } } } }
Example #8
Source File: FileLoading.java From ud406 with MIT License | 5 votes |
public static String decrypt(String encrypted) { try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); if (Gdx.app.getType() == ApplicationType.Android){ throw new Exception("This demo works only with the desktop backend"); } byte[] encryptedBytes = Base64.decodeBase64(encrypted); return new String(cipher.doFinal(encryptedBytes)); } catch (Exception e) { Gdx.app.error(TAG, "Couldn't decrypt message: " + encrypted, e); } return "Failed"; }
Example #9
Source File: FileUtils.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
/** * For android, the exists method is very slow, this is a fast * implementation * * @return true if file exists */ public static boolean exists(FileHandle fh) { if (Gdx.app.getType() == ApplicationType.Android) { try { fh.read().close(); return true; } catch (Exception e) { return false; } } return fh.exists(); }
Example #10
Source File: CreditsScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
private void processCreditMusic(final String s) { if (music != null) music.dispose(); final String file = EngineAssetManager.getInstance().checkIOSSoundName("music/" + s); new Thread() { @Override public void run() { music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(file)); try { music.play(); music.setVolume(0.5f); } catch (Exception e) { // DEAL WITH OPENAL BUG if (Gdx.app.getType() == ApplicationType.Desktop && e.getMessage().contains("40963")) { EngineLogger.debug("!!!!!!!!!!!!!!!!!!!!!!!ERROR playing music trying again...!!!!!!!!!!!!!!!"); music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(file)); music.play(); music.setVolume(0.5f); return; } EngineLogger.error("Error Playing music: " + file); } } }.start(); }
Example #11
Source File: UI.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public void resume() { if (Gdx.app.getType() != ApplicationType.Desktop) { // RESTORE GL CONTEXT RectangleRenderer.dispose(); } if (screen != null) screen.resume(); }
Example #12
Source File: World.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public void saveGameState() throws IOException { boolean takeScreenshot = false; // Only take screenshot for desktop. For iOs or Android is slow. if (Gdx.app.getType() == ApplicationType.Desktop) takeScreenshot = true; serialization.saveGameState(GAMESTATE_FILENAME, takeScreenshot); }
Example #13
Source File: Keybinds.java From Cubes with MIT License | 5 votes |
public static SettingGroup init() { if (settingGroup == null) { Settings.addSetting(KEYBIND_FORWARD, new KeybindSetting(Keys.W)); Settings.addSetting(KEYBIND_BACK, new KeybindSetting(Keys.S)); Settings.addSetting(KEYBIND_LEFT, new KeybindSetting(Keys.A)); Settings.addSetting(KEYBIND_RIGHT, new KeybindSetting(Keys.D)); Settings.addSetting(KEYBIND_JUMP, new KeybindSetting(Keys.SPACE)); Settings.addSetting(KEYBIND_DESCEND, new KeybindSetting(Keys.SHIFT_LEFT)); Settings.addSetting(KEYBIND_THROW, new KeybindSetting(Keys.Q)); Settings.addSetting(KEYBIND_INVENTORY, new KeybindSetting(Keys.E)); Settings.addSetting(KEYBIND_CHAT, new KeybindSetting(Keys.F4)); Settings.addSetting(KEYBIND_FULLSCREEN, new KeybindSetting(Keys.F11)); Settings.addSetting(KEYBIND_HIDEGUI, new KeybindSetting(Keys.F1)); Settings.addSetting(KEYBIND_SCREENSHOT, new KeybindSetting(Keys.F2)); Settings.addSetting(KEYBIND_DEBUG, new KeybindSetting(Keys.F3)); Settings.addSetting(KEYBIND_AREABOUNDARIES, new KeybindSetting(Keys.F7)); settingGroup = new SettingGroup() { @Override public boolean shouldDisplay() { return Compatibility.get().getApplicationType() == ApplicationType.Desktop; } }; settingGroup.add(KEYBIND_FORWARD).add(KEYBIND_BACK).add(KEYBIND_LEFT).add(KEYBIND_RIGHT).add(KEYBIND_JUMP).add(KEYBIND_DESCEND); settingGroup.add(KEYBIND_INVENTORY).add(KEYBIND_CHAT); settingGroup.add(KEYBIND_FULLSCREEN).add(KEYBIND_HIDEGUI).add(KEYBIND_SCREENSHOT).add(KEYBIND_DEBUG).add(KEYBIND_AREABOUNDARIES); } return settingGroup; }
Example #14
Source File: SeventhGame.java From seventh with GNU General Public License v2.0 | 5 votes |
/** * Hide the Mouse cursor * * @param visible */ private void setHWCursorVisible(boolean visible) { if (Gdx.app.getType() != ApplicationType.Desktop && Gdx.app instanceof LwjglApplication) { return; } try { /* make sure the mouse doesn't move off the screen */ seventh.client.gfx.Cursor cursor = this.uiManager.getCursor(); cursor.setClampEnabled(config.getVideo().isFullscreen()); Gdx.input.setCursorCatched(config.getVideo().isFullscreen()); //Gdx.input.setCursorCatched(true); //Gdx.input.setCursorPosition(getScreenWidth()/2, getScreenHeight()/2); Cursor emptyCursor = null; if (Mouse.isCreated()) { int min = org.lwjgl.input.Cursor.getMinCursorSize(); IntBuffer tmp = BufferUtils.createIntBuffer(min * min); emptyCursor = new org.lwjgl.input.Cursor(min, min, min / 2, min / 2, 1, tmp, null); } else { Cons.println("Could not create empty cursor before Mouse object is created"); } if (/*Mouse.isInsideWindow() &&*/ emptyCursor != null) { Mouse.setNativeCursor(visible ? null : emptyCursor); } } catch(LWJGLException e) { Cons.println("*** Unable to hide cursor: " + e); } }
Example #15
Source File: BulletSteeringTest.java From gdx-ai with Apache License 2.0 | 5 votes |
public static void init () { if (initialized) return; // Need to initialize bullet before using it. if (Gdx.app.getType() == ApplicationType.Desktop && customDesktopLib != null) { System.load(customDesktopLib); } else Bullet.init(); Gdx.app.log("Bullet", "Version = " + LinearMath.btGetVersion()); initialized = true; }
Example #16
Source File: FileLoading.java From ud406 with MIT License | 5 votes |
public static String encrypt(String message) { try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedBytes = cipher.doFinal(message.getBytes()); if (Gdx.app.getType() == ApplicationType.Android){ throw new Exception("This demo works only with the desktop backend"); } return Base64.encodeBase64String(encryptedBytes); } catch (Exception e) { Gdx.app.error(TAG, "Couldn't encrypt message: " + message, e); } return "Failed"; }
Example #17
Source File: FileLoading.java From ud406 with MIT License | 5 votes |
public static String decrypt(String encrypted) { try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); if (Gdx.app.getType() == ApplicationType.Android){ throw new Exception("This demo works only with the desktop backend"); } byte[] encryptedBytes = Base64.decodeBase64(encrypted); return new String(cipher.doFinal(encryptedBytes)); } catch (Exception e) { Gdx.app.error(TAG, "Couldn't decrypt message: " + encrypted, e); } return "Failed"; }
Example #18
Source File: FileLoading.java From ud406 with MIT License | 5 votes |
public static String encrypt(String message) { try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedBytes = cipher.doFinal(message.getBytes()); if (Gdx.app.getType() == ApplicationType.Android){ throw new Exception("This demo works only with the desktop backend"); } return Base64.encodeBase64String(encryptedBytes); } catch (Exception e) { Gdx.app.error(TAG, "Couldn't encrypt message: " + message, e); } return "Failed"; }
Example #19
Source File: SpaceGame.java From libgdx-2d-tutorial with MIT License | 5 votes |
@Override public void create () { batch = new SpriteBatch(); cam = new GameCamera(WIDTH, HEIGHT); if (Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS) IS_MOBILE = true; IS_MOBILE = true; this.scrollingBackground = new ScrollingBackground(); this.setScreen(new MainMenuScreen(this)); }
Example #20
Source File: GLTFBinaryExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static void savePNG(FileHandle file, Pixmap pixmap){ if(Gdx.app.getType() == ApplicationType.WebGL){ throw new GdxRuntimeException("saving pixmap not supported for WebGL"); }else{ // call PixmapIO.writePNG(file, pixmap); via reflection to // avoid compilation error with GWT. try { Class pixmapIO = ClassReflection.forName("com.badlogic.gdx.graphics.PixmapIO"); Method pixmapIO_writePNG = ClassReflection.getMethod(pixmapIO, "writePNG", FileHandle.class, Pixmap.class); pixmapIO_writePNG.invoke(null, file, pixmap); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } } }
Example #21
Source File: PixmapBinaryLoaderHack.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static Pixmap load(byte [] encodedData, int offset, int len){ if(Gdx.app.getType() == ApplicationType.WebGL){ throw new GdxRuntimeException("load pixmap from bytes not supported for WebGL"); }else{ // call new Pixmap(encodedData, offset, len); via reflection to // avoid compilation error with GWT. try { return (Pixmap)ClassReflection.getConstructor(Pixmap.class, byte[].class, int.class, int.class).newInstance(encodedData, offset, len); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } } }
Example #22
Source File: IOSMini2DxGraphics.java From mini2Dx with Apache License 2.0 | 4 votes |
@Override public void draw (GLKView view, CGRect rect) { makeCurrent(); // massive hack, GLKView resets the viewport on each draw call, so IOSGLES20 // stores the last known viewport and we reset it here... gl20.glViewport(IOSGLES20.x, IOSGLES20.y, IOSGLES20.width, IOSGLES20.height); if (!created) { gl20.glViewport(0, 0, width, height); String versionString = gl20.glGetString(GL20.GL_VERSION); String vendorString = gl20.glGetString(GL20.GL_VENDOR); String rendererString = gl20.glGetString(GL20.GL_RENDERER); glVersion = new GLVersion(ApplicationType.iOS, versionString, vendorString, rendererString); app.listener.create(); app.listener.resize(width, height); created = true; } if (appPaused) { return; } long time = System.nanoTime(); deltaTime = (time - lastFrameTime) / 1000000000.0f; lastFrameTime = time; frames++; if (time - framesStart >= 1000000000l) { framesStart = time; fps = frames; frames = 0; } Mdx.platformUtils.markFrame(); float delta = deltaTime; if (delta > maximumDelta) { delta = maximumDelta; } accumulator += delta; while (accumulator >= targetTimestep) { Mdx.platformUtils.markUpdateBegin(); input.processEvents(); app.listener.update(targetTimestep); Mdx.platformUtils.markUpdateEnd(); accumulator -= targetTimestep; } app.listener.interpolate(accumulator / targetTimestep); frameId++; Mdx.platformUtils.markRenderBegin(); app.listener.render(); Mdx.platformUtils.markRenderEnd(); if(config.errorOnFrameDrop) { if(Mdx.platformUtils.getUpdatesPerSecond() < config.targetFPS) { if(lastFrameDropWarning != Mdx.platformUtils.getUpdatesPerSecond()) { lastFrameDropWarning = Mdx.platformUtils.getUpdatesPerSecond(); Mdx.log.error("mini2Dx", "WARN: " + (config.targetFPS - Mdx.platformUtils.getUpdatesPerSecond()) + " frames dropped."); } } else { lastFrameDropWarning = -1; } } }
Example #23
Source File: Compatibility.java From Cubes with MIT License | 4 votes |
public final ApplicationType getApplicationType() { return applicationType; }
Example #24
Source File: Compatibility.java From Cubes with MIT License | 4 votes |
protected Compatibility(Launcher launcher, Application.ApplicationType applicationType) { if (compatibility != null) throw new IllegalStateException(); this.launcher = launcher; this.applicationType = applicationType; }
Example #25
Source File: GameScreen.java From ashley-superjumper with Apache License 2.0 | 4 votes |
private void updateRunning (float deltaTime) { if (Gdx.input.justTouched()) { guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0)); if (pauseBounds.contains(touchPoint.x, touchPoint.y)) { Assets.playSound(Assets.clickSound); state = GAME_PAUSED; pauseSystems(); return; } } ApplicationType appType = Gdx.app.getType(); // should work also with Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) float accelX = 0.0f; if (appType == ApplicationType.Android || appType == ApplicationType.iOS) { accelX = Gdx.input.getAccelerometerX(); } else { if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) accelX = 5f; if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) accelX = -5f; } engine.getSystem(BobSystem.class).setAccelX(accelX); if (world.score != lastScore) { lastScore = world.score; scoreString = "SCORE: " + lastScore; } if (world.state == World.WORLD_STATE_NEXT_LEVEL) { game.setScreen(new WinScreen(game)); } if (world.state == World.WORLD_STATE_GAME_OVER) { state = GAME_OVER; if (lastScore >= Settings.highscores[4]) scoreString = "NEW HIGHSCORE: " + lastScore; else scoreString = "SCORE: " + lastScore; pauseSystems(); Settings.addScore(lastScore); Settings.save(); } }
Example #26
Source File: EngineAssetManager.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
public FileHandle getUserFolder() { FileHandle file = null; if (Gdx.app.getType() == ApplicationType.Desktop && desktopUserFolder != null) { StringBuilder sb = new StringBuilder(); if (System.getProperty("os.name").toLowerCase().contains("mac") && System.getenv("HOME").contains("Containers")) { file = Gdx.files.absolute(System.getenv("HOME") + "/" + sb.append(desktopUserFolder).toString()); } else { file = Gdx.files.external(sb.append(desktopUserFolder).toString()); } } else { file = Gdx.files.local(NOT_DESKTOP_PREFS_DIR); } return file; }
Example #27
Source File: OsUtils.java From vis-ui with Apache License 2.0 | 4 votes |
/** @return {@code true} if the current OS is Android */ public static boolean isAndroid () { return Gdx.app.getType() == ApplicationType.Android; }
Example #28
Source File: OsUtils.java From vis-ui with Apache License 2.0 | 4 votes |
/** @return {@code true} if the current OS is iOS */ public static boolean isIos () { return Gdx.app.getType() == ApplicationType.iOS; }
Example #29
Source File: MainMenu.java From libgdx-demo-pax-britannica with MIT License | 4 votes |
@Override public boolean keyDown(int keycode) { if(keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) { boolean exit = true; if(p1.picked) { p1.reset(); exit = false; } if(p2.picked) { p2.reset(); exit = false; } if(p3.picked) { p3.reset(); exit = false; } if(p4.picked) { p4.reset(); exit = false; } if(exit) { if(!(Gdx.app.getType() == ApplicationType.Applet)) { Gdx.app.exit(); } } } if(keycode == Input.Keys.A) { if (!p1.picked) { p1.picked = true; } else { p1.playerSelect = true; p1.cpuSelect = false; } } if(keycode == Input.Keys.F) { if (!p2.picked) { p2.picked = true; } else { p2.playerSelect = true; p2.cpuSelect = false; } } if(keycode == Input.Keys.H) { if (!p3.picked) { p3.picked = true; } else { p3.playerSelect = true; p3.cpuSelect = false; } } if(keycode == Input.Keys.L) { if (!p4.picked) { p4.picked = true; } else { p4.playerSelect = true; p4.cpuSelect = false; } } if(keycode == Input.Keys.M) { if (cnt >= 1) return false; Preferences prefs = Gdx.app.getPreferences("paxbritannica"); prefs.putBoolean("music", !prefs.getBoolean("music")); prefs.flush(); if(prefs.getBoolean("music")) { if(Resources.getInstance().music == null) Resources.getInstance().reInit(); if(!Resources.getInstance().music.isPlaying()) { Resources.getInstance().music.play(); Resources.getInstance().music.setLooping(true); } musicOnOff.setColor(1,1,1,0.5f); } else { Resources.getInstance().music.stop(); musicOnOff.setColor(1,1,1,0.1f); } } if(keycode == Input.Keys.F1) { if (cnt >= 1) return false; countdown.finished = true; changeToScreen = 0; } if(keycode == Input.Keys.S) { if (cnt >= 1) return false; countdown.finished = true; changeToScreen = 1; } return false; }
Example #30
Source File: GameplayScreen.java From ud406 with MIT License | 4 votes |
private boolean onMobile() { return Gdx.app.getType() == ApplicationType.Android || Gdx.app.getType() == ApplicationType.iOS; }