List of usage examples for com.badlogic.gdx Gdx app
Application app
To view the source code for com.badlogic.gdx Gdx app.
Click Source Link
From source file:airfoil.Main.java
License:Open Source License
@Override public void create() { Gdx.input.setInputProcessor(this); ShaderProgram.pedantic = false;//from w w w. j ava2s . c o m this.bodyShader = new ShaderProgram(Gdx.files.internal("data/shaders/body.vert.glsl").readString(), Gdx.files.internal("data/shaders/body.frag.glsl").readString()); this.alive = this.bodyShader.isCompiled(); if (!this.alive) { Gdx.app.error(Main.Title, "Error compiling body shader " + this.bodyShader.getLog()); Gdx.app.exit(); } else { this.axesShader = new ShaderProgram(Gdx.files.internal("data/shaders/axes.vert.glsl").readString(), Gdx.files.internal("data/shaders/axes.frag.glsl").readString()); this.alive = this.axesShader.isCompiled(); if (!this.alive) { Gdx.app.error(Main.Title, "Error compiling axes shader " + this.axesShader.getLog()); Gdx.app.exit(); } } }
From source file:app.badlogicgames.superjumper.GameScreen.java
License:Apache License
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;//from w w w . j a v a 2 s . c om return; } } ApplicationType appType = Gdx.app.getType(); // should work also with Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) if (appType == ApplicationType.Android || appType == ApplicationType.iOS) { world.update(deltaTime, Gdx.input.getAccelerometerX()); } else { float accel = 0; if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) accel = 5f; if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) accel = -5f; world.update(deltaTime, accel); } if (world.score != lastScore) { lastScore = world.score; scoreString = "SCORE: " + lastScore; } if (world.state == World.WORLD_STATE_NEXT_LEVEL) { state = GAME_LEVEL_END; } if (world.state == World.WORLD_STATE_GAME_OVER) { state = GAME_OVER; if (lastScore >= Settings.highscores[4]) scoreString = "NEW HIGHSCORE: " + lastScore; else scoreString = "SCORE: " + lastScore; Settings.addScore(lastScore); Settings.save(); } }
From source file:app.badlogicgames.superjumper.MainMenuScreen.java
License:Apache License
public void draw() { GLCommon gl = Gdx.gl;//from w w w . j av a 2 s. co m gl.glClearColor(1, 0, 0, 1); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); guiCam.update(); batcher.setProjectionMatrix(guiCam.combined); batcher.disableBlending(); batcher.begin(); batcher.draw(Assets.backgroundRegion, 0, 0, 320, 480); batcher.end(); batcher.enableBlending(); batcher.begin(); batcher.draw(Assets.logo, 160 - 274 / 2, 480 - 10 - 142, 274, 142); batcher.draw(Assets.mainMenu, 10, 200 - 110 / 2, 300, 110); batcher.draw(Assets.multiplayer, 160 - 64, 100, 128, 32); batcher.draw(Settings.soundEnabled ? Assets.soundOn : Assets.soundOff, 0, 0, 64, 64); batcher.end(); if (System.nanoTime() - last > 2000000000) { Gdx.app.log("SuperJumper", "version: " + Gdx.app.getVersion() + ", memory: " + Gdx.app.getJavaHeap() + ", " + Gdx.app.getNativeHeap() + ", native orientation:" + Gdx.input.getNativeOrientation() + ", orientation: " + Gdx.input.getRotation() + ", accel: " + (int) Gdx.input.getAccelerometerX() + ", " + (int) Gdx.input.getAccelerometerY() + ", " + (int) Gdx.input.getAccelerometerZ() + ", apr: " + (int) Gdx.input.getAzimuth() + ", " + (int) Gdx.input.getPitch() + ", " + (int) Gdx.input.getRoll()); last = System.nanoTime(); } }
From source file:app.badlogicgames.superjumper.multiplayer.MultiplayerGameScreen.java
License:Apache License
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; game.setScreen(new MainMenuScreen(game)); handleLeaveGame();//from www. j a v a 2s .c om return; } } ApplicationType appType = Gdx.app.getType(); // should work also with Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) if (appType == ApplicationType.Android || appType == ApplicationType.iOS) { world.update(deltaTime, Gdx.input.getAccelerometerX()); } else { float accel = 0; if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) accel = 5f; if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) accel = -5f; world.update(deltaTime, accel); } if (world.score != lastScore) { lastScore = world.score; scoreString = "SCORE: " + lastScore; } if (world.state == World.WORLD_STATE_NEXT_LEVEL) { state = GAME_LEVEL_END; } if (world.state == World.WORLD_STATE_GAME_OVER) { state = GAME_OVER; if (lastScore >= Settings.highscores[4]) scoreString = "NEW HIGHSCORE: " + lastScore; else scoreString = "SCORE: " + lastScore; Settings.addScore(lastScore); Settings.save(); } }
From source file:app.badlogicgames.superjumper.multiplayer.StartMultiplayerScreen.java
License:Apache License
@Override public void onGameStarted(String message) { Gdx.app.postRunnable(new Runnable() { @Override//from www. j a va 2 s . c om public void run() { game.setScreen(new MultiplayerGameScreen(game, StartMultiplayerScreen.this)); } }); }
From source file:app.badlogicgames.superjumper.RegisterScreen.java
License:Apache License
private static void readPref() { Preferences prefs = Gdx.app.getPreferences("my-preferences"); Util.NAME = prefs.getString("name"); Util.EMAIL = prefs.getString("email"); Util.PASSWORD = prefs.getString("password"); }
From source file:app.badlogicgames.superjumper.RegisterScreen.java
License:Apache License
private void savePref() { Preferences prefs = Gdx.app.getPreferences("my-preferences"); if (Util.NAME.length() > 0 && Util.EMAIL.length() > 0 && Util.PASSWORD.length() > 0) { prefs.putString("name", Util.NAME); prefs.putString("email", Util.EMAIL); prefs.putString("password", Util.PASSWORD); prefs.flush();/*w ww .j ava 2 s .c om*/ notification = "Saved Successfully"; game.setScreen(new MainMenuScreen(game)); } else { notification = "All Fields are mandatory"; } }
From source file:app.badlogicgames.superjumper.RegisterScreen.java
License:Apache License
public void draw() { GLCommon gl = Gdx.gl;/*from www.ja v a2s . c o m*/ gl.glClearColor(1, 0, 0, 1); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); guiCam.update(); batcher.setProjectionMatrix(guiCam.combined); batcher.disableBlending(); batcher.begin(); batcher.draw(Assets.backgroundRegion, 0, 0, 320, 480); batcher.end(); batcher.enableBlending(); batcher.begin(); batcher.draw(Assets.enterName, 10, 400, 128, 32); Assets.font.draw(batcher, ": " + Util.NAME, 140, 400 + Assets.font.getLineHeight()); batcher.draw(Assets.enterEmail, 10, 350, 128, 32); Assets.font.draw(batcher, ": " + Util.EMAIL, 140, 350 + Assets.font.getLineHeight()); batcher.draw(Assets.enterPass, 10, 300, 128, 32); Assets.font.draw(batcher, ": " + Util.PASSWORD, 140, 300 + Assets.font.getLineHeight()); batcher.draw(Assets.submit, 160 - 64, 100, 128, 32); Assets.font.draw(batcher, notification, 10, 50); batcher.end(); if (System.nanoTime() - last > 2000000000) { Gdx.app.log("SuperJumper", "version: " + Gdx.app.getVersion() + ", memory: " + Gdx.app.getJavaHeap() + ", " + Gdx.app.getNativeHeap() + ", native orientation:" + Gdx.input.getNativeOrientation() + ", orientation: " + Gdx.input.getRotation() + ", accel: " + (int) Gdx.input.getAccelerometerX() + ", " + (int) Gdx.input.getAccelerometerY() + ", " + (int) Gdx.input.getAccelerometerZ() + ", apr: " + (int) Gdx.input.getAzimuth() + ", " + (int) Gdx.input.getPitch() + ", " + (int) Gdx.input.getRoll()); last = System.nanoTime(); } }
From source file:application.concretion.GameScreenController.java
License:Open Source License
@Override public void create() { // If application is launch in html5 put your specific DAO. if (Gdx.app.getType() == ApplicationType.WebGL) { SettingManager.DAO = DataAccesObjectCSV.getInstance(); }//from w ww .ja v a2s. c om // Initialized common resources and loading screen. Gdx.input.setInputProcessor(InputGame.getInputMultiplexer()); ResourcesCommos.initResources(); currentScreen = new LoadingScreen(false); }
From source file:at.hid.tabletopsimulator.screens.About.java
License:Apache License
@Override public void show() { TableTopSimulator.debug(this.getClass().toString(), "creating About screen"); stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); Gdx.input.setInputProcessor(stage);//from w ww . java 2 s.c om // creating skin TableTopSimulator.debug(this.getClass().toString(), "creating skin"); skin = TableTopSimulator.assets.get("ui/gui.json", Skin.class); table = new Table(skin); // table.setFillParent(true); // table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // creating heading TableTopSimulator.debug(this.getClass().toString(), "creating heading"); Label lblHeading = new Label(TableTopSimulator.getLangBundle().format("About.lblHeading.text"), skin); final Label lblContent = new Label("http://libgdx.badlogicgames.com/\r\n" + "\r\n" + "libGDX is licensed under the Apache 2 License,\r\n" + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n" + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!", skin, "content"); // creating list final List<String> listAbout = new List<String>(skin, "content"); ArrayList<String> newItems = new ArrayList<String>(); newItems.add("libgdx"); newItems.add("libgdx-utils"); newItems.add("flare gameart"); String[] data = new String[newItems.size()]; listAbout.setItems(newItems.toArray(data)); listAbout.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (listAbout.getSelected().equals("libgdx")) { lblContent.clear(); lblContent.setText("http://libgdx.badlogicgames.com/\r\n" + "\r\n" + "libGDX is licensed under the Apache 2 License,\r\n" + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n" + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!"); } else if (listAbout.getSelected().equals("libgdx-utils")) { lblContent.clear(); lblContent.setText("https://bitbucket.org/dermetfan/libgdx-utils/wiki/Home\r\n" + "\r\n" + "/* Copyright (c) 2014 PixelScientists\r\n" + "*\r\n" + "* The MIT License (MIT)\r\n" + "*\r\n" + "* Permission is hereby granted, free of charge, to any person obtaining a copy of\r\n" + "* this software and associated documentation files (the \"Software\"), to deal in\r\n" + "* the Software without restriction, including without limitation the rights to\r\n" + "* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\n" + "* the Software, and to permit persons to whom the Software is furnished to do so,\r\n" + "* subject to the following conditions:\r\n" + "*\r\n" + "* The above copyright notice and this permission notice shall be included in all\r\n" + "* copies or substantial portions of the Software.\r\n" + "*\r\n" + "* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n" + "* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n" + "* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\n" + "* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\n" + "* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\n" + "* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n" + "*/"); } else if (listAbout.getSelected().equals("flare gameart")) { lblContent.clear(); lblContent.setText("https://github.com/clintbellanger/flare-game\r\n" + "\r\n" + "Flare (the game) is Copyright 2010-2013 Clint Bellanger. Contributors retain copyrights to their original contributions.\r\n" + "\r\n" + "The Flare Engine is released under GPL version 3 or later.\r\n" + "\r\n" + "All of Flare's art and data files are released under CC-BY-SA 3.0. Later versions are permitted.\r\n" + "\r\n" + "The Liberation Sans fonts version 2 are released under the SIL Open Font License, Version 1.1.\r\n" + "\r\n" + "The GNU Unifont font is released under GPL v2, with the exception that embedding the font in a document does not in itself bind that document to the terms of the GPL."); } } }); // creating buttons TableTopSimulator.debug(this.getClass().toString(), "creating buttons"); TextButton btnBack = new TextButton(TableTopSimulator.getLangBundle().format("About.btnBack.text"), skin); btnBack.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { TableTopSimulator.debug(this.getClass().toString(), "switching to Options screen"); ((Game) Gdx.app.getApplicationListener()).setScreen(new Options()); dispose(); } }); btnBack.pad(10); ScrollPane spAboutList = new ScrollPane(null, skin); ScrollPane spAboutContent = new ScrollPane(null, skin); SplitPane splitAbout = new SplitPane(spAboutList, spAboutContent, false, skin); splitAbout.setSplitAmount(0.2f); spAboutList.setWidget(listAbout); spAboutContent.setWidget(lblContent); // building ui TableTopSimulator.debug(this.getClass().toString(), "building ui"); table.add(lblHeading).spaceBottom(100).row(); table.add(splitAbout).spaceBottom(15).width(1200).row(); table.add(btnBack).spaceBottom(15).row(); if (TableTopSimulator.DEBUG) { table.debug(); // draw debug lines splitAbout.debug(); // draw debug lines } stage.addActor(table); }