@Override public void render() { // Update getInput(); b2dWorld.step(1f / 60f, 6, 2); camera.update(); cameraBak.update(); manager.update(); background.update(); // Draw Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); // Background batch.setProjectionMatrix(cameraBak.combined); batch.begin(); background.draw(batch); batch.end(); batch.setProjectionMatrix(camera.combined); debugMatrix = batch.getProjectionMatrix().cpy().scale(PPM, PPM, 0); // debugRenderer.render(b2dWorld, debugMatrix); batch.begin(); manager.draw(batch); batch.end(); // GUI batch.setProjectionMatrix(cameraBak.combined); batch.begin(); drawGUI(batch); batch.end(); }
public void resize(int width, int height) { camera.viewportWidth = (Constants.VIEWPORT_HEIGHT / height) * width; camera.update(); cameraGUI.viewportHeight = Constants.VIEWPORT_GUI_HEIGHT; cameraGUI.viewportWidth = Constants.VIEWPORT_GUI_HEIGHT / (float) height * (float) width; cameraGUI.position.set(cameraGUI.viewportWidth / 2, cameraGUI.viewportHeight / 2, 0); cameraGUI.update(); }
private void updateCamZoom(float newZoom) { OrthographicCamera c = cam.camera; c.unproject(zTmp1.set(cs.xy.x, cs.xy.y, 0)); c.zoom = newZoom; c.update(); c.unproject(zTmp2.set(cs.xy.x, cs.xy.y, 0)); c.translate(zTmp1.sub(zTmp2)); c.update(); }
/** Set's the ShapeRenderer's projection matrix depending on the mode of the demo camera. */ public void setCamera(ShapeRenderer renderer) { if (inCloseupMode) { closeupCamera.update(); renderer.setProjectionMatrix(closeupCamera.combined); } else { overviewCamera.update(); renderer.setProjectionMatrix(overviewCamera.combined); } }
private void init() { batch = new SpriteBatch(); camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH, Constants.VIEWPORT_HEIGHT); camera.position.set(0, 0, 0); camera.update(); cameraGUI = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT); cameraGUI.position.set(0, 0, 0); cameraGUI.setToOrtho(true); // flip y-axis cameraGUI.update(); }
@Override public void render() { delta = Gdx.graphics.getDeltaTime() * 60; Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); player.update(delta); if (player.atLimit()) backgroundPos -= 20 * delta; else backgroundPos -= 10 * delta; if (backgroundPos <= -background.getHeight()) backgroundPos = 0; spriteBatch.setProjectionMatrix(camera.combined); spriteBatch.begin(); spriteBatch.draw(background, -1080 / 2, +background.getHeight() / 2 + backgroundPos); spriteBatch.draw(background, -1080 / 2, -background.getHeight() / 2 + backgroundPos); player.draw(spriteBatch); enemies.update(spriteBatch, delta); tweenManager.update(delta / 60); spriteBatch.end(); rayHandler.setCombinedMatrix(camera.combined); rayHandler.updateAndRender(); controls.handleInput(camera); }
public void draw(float deltaTime) { renderer.render(); guiCam.update(); batcher.setProjectionMatrix(guiCam.combined); batcher.enableBlending(); batcher.begin(); drawUI(deltaTime); switch (state) { case GAME_READY: presentReady(); break; // case ROUND_START // case COUNT_DUCKS // case NEXT_ROUND case GAME_RUNNING: presentRunning(); break; case GAME_OVER_1: case GAME_OVER_2: presentGameOver(); break; } batcher.end(); }
@Override public void render(float delta) { camera.update(); maps.setView(camera); maps.render(); entities.update(delta); }
@Override public void render(float dt) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // compara si la aplicacion se ejecuta en escritorio o en android if (Gdx.app.getType() == ApplicationType.Desktop) { this.entradaEscritorio(dt); } else if (Gdx.app.getType() == ApplicationType.Android) { this.entradaAndroid(dt); } // actualizamos camara.update(); this.juegoGanado(); batch.setProjectionMatrix(camara.combined); manejadorDeSprite.update(dt, arcanoid, jugador); // renderiza el manejadorDeSprite, fondo de pantalla y fuente de jugador batch.begin(); batch.draw(fondoPantalla, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); jugador.draw(batch); batch.end(); manejadorDeSprite.render(); }
/** * Splash Screen Constructor. * * @param tappy */ public SplashScreen(Tappy tappy) { // Core Variable. this.tappy = tappy; // Get sprites. splashHeadphone = Assets.getSprite("splashHeadphone"); splashBackground = Assets.getSprite("splashBackground"); // Set normal camera. orthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); orthographicCamera.position.set( orthographicCamera.viewportWidth / 2f, orthographicCamera.viewportHeight / 2f, 0); orthographicCamera.update(); // Initialize TweenManager. tweenManager = new TweenManager(); Tween.registerAccessor(Sprite.class, new SpriteAccessor()); // Initialize splashScreen variable. splashNormalStage = new Stage(); // Trace player! HashMap<String, String> parameters = new HashMap<String, String>(); try { parameters.put( "signature", Helper.md5( (int) (Math.floor(((int) (System.currentTimeMillis() / 1000L) / 1000.0))) + "tHeJ3110pylnWzA-007!-+ei")); } catch (Exception e) { parameters.put("signature", "Error"); } parameters.put("function", "launch"); try { parameters.put("computerName", InetAddress.getLocalHost().getHostName()); } catch (Exception e) { parameters.put("computerName", "Unknown"); } try { parameters.put("javaVersion", System.getProperty("java.version")); } catch (Exception e) { parameters.put("javaVersion", "Unknown"); } parameters.put("isFirst", tappy.getPreferences().getBoolean("firstTime", true) ? "1" : "0"); HttpRequest httpPost = new HttpRequest(HttpMethods.POST); httpPost.setUrl("http://jellopy.in.th/tappy1eaTrace.php"); httpPost.setContent(HttpParametersUtils.convertHttpParameters(parameters)); Gdx.net.sendHttpRequest( httpPost, new HttpResponseListener() { @Override public void handleHttpResponse(HttpResponse httpResponse) {} @Override public void failed(Throwable error) {} @Override public void cancelled() {} }); }
public GameScreen(final IkeGame game) { this.game = game; // Creates the world manager with the specified map worldManager = new WorldManager("test_map.tmx"); // Creates the player at the specified coordinates worldManager.createPlayer(1.5f, 5.5f); // Sets this class's ike body instance to the world manager's for convenience ikeBody = worldManager.player; // Gets the ike instance from ike's body ike = (Ike) ikeBody.getUserData(); // Creates the camera camera = new OrthographicCamera(); // Makes the camera render 32 tiles wide and 18 tiles high camera.setToOrtho(false, 32, 18); // Updates the camera camera.update(); // Creates the shape renderer shapeRenderer = new ShapeRenderer(); // Sets the input listener Gdx.input.setInputProcessor(new ControlListener()); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0.39f, 0.58f, 0.92f, 1.0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Update deltaTime & animationTime deltaTime = Gdx.graphics.getDeltaTime(); animationTime += Gdx.graphics.getDeltaTime(); // Store Spritesheet to sprite sprite = new Sprite(animation.getKeyFrame(animationTime, true)); sprite.setPosition(xPosition, 0); sprite.setScale(1.8f); // Set camera to batch and undate camera batch.setProjectionMatrix(camera.combined); camera.update(); tiledMapRenderer.setView(camera); tiledMapRenderer.render(background); tiledMapRenderer.render(foreground); // Display on Screen batch.begin(); sprite.draw(batch); batch.end(); // update xPosition xPosition = xPosition + (speed * deltaTime); HUDBatch.begin(); font1.draw(HUDBatch, "SCORE:100", 100, 450); HUDBatch.end(); }
@Override public void render(float delta) { // TODO Auto-generated method stub if (Gdx.input.justTouched()) { guiCam.unproject(touch.set(Gdx.input.getX(), Gdx.input.getY(), 0)); if (startbutton.contains(touch)) { maingame.setScreen(maingame.mainscene); return; } } GL10 gl = Gdx.graphics.getGL10(); gl.glClearColor(0, 0, 0, 1); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); /* * Actualiza los parametros de la camara * y los enlaza al objeto de renderizado batcher * */ guiCam.update(); this.batcher.setProjectionMatrix(this.guiCam.combined); /* * Desactiva las trasnparencias * */ batcher.disableBlending(); batcher.begin(); batcher.draw(Assets.background, 0, 0, 10, 15); batcher.end(); batcher.enableBlending(); batcher.begin(); batcher.draw(Assets.title, 1, 6, 8, 8); batcher.draw(Assets.start, x, 3, 6, 3); x += c; batcher.end(); }
@Override public void present(float deltaTime) { GLCommon gl = Gdx.gl; gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); worldRender.render(deltaTime); if (isTreasure) { batcher.begin(); renderTreasure(treasureType); if (isTreasureSound) { Assets.playSound(Assets.treasureSound, game.soundState); isTreasureSound = false; } batcher.end(); } else if (isFinal) { batcher.begin(); renderFinal(); batcher.end(); } else { if (isPause && !isDialog) { batcher.begin(); renderGamePause(); batcher.end(); } } if ((isPause || !game.soundState) && bgMusic.isPlaying()) { bgMusic.pause(); } else if (!isPause && !bgMusic.isPlaying() && game.soundState) { Assets.playMusic(bgMusic, game.soundState); } }
@Override public void render(float delta) { Gdx.gl.glClearColor(Color.BLUE.r, Color.BLUE.g, Color.BLUE.b, Color.BLUE.a); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); game.batch.setProjectionMatrix(camera.combined); batch.begin(); font.draw(batch, "Loading Game", 32, 32); background.draw(batch); batch.end(); if (licenseVerified) { if (Gdx.input.isTouched()) { Logger.logMsg("transitioning to main menu screen"); game.setGameScreen(this, game.mainMenuScreen); dispose(); } } else { Dialog dialog = new Dialog("license key invalid", game.uiSkin) { protected void result(Object object) { Logger.logMsg("exiting"); Gdx.app.exit(); } }; dialog.text("Your license key is invalid, exiting..."); dialog.button("OK", true); dialog.show(stage); } }
private void drawWorld() { camera.update(); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(background, camera.position.x - background.getWidth() / 2, 0); for (Rock rock : rocks) { batch.draw(rock.image, rock.position.x, rock.position.y); } batch.draw(ground, groundOffsetX, 0); batch.draw(ground, groundOffsetX + ground.getRegionWidth(), 0); batch.draw(ceiling, groundOffsetX, 480 - ceiling.getRegionHeight()); batch.draw(ceiling, groundOffsetX + ceiling.getRegionWidth(), 480 - ceiling.getRegionHeight()); batch.draw(plane.getKeyFrame(planeStateTime), planePosition.x, planePosition.y); batch.end(); batch.setProjectionMatrix(uiCamera.combined); batch.begin(); if (gameState == GameState.Start) { batch.draw( ready, Gdx.graphics.getWidth() / 2 - ready.getRegionWidth() / 2, Gdx.graphics.getHeight() / 2 - ready.getRegionHeight() / 2); } if (gameState == GameState.GameOver) { batch.draw( gameOver, Gdx.graphics.getWidth() / 2 - gameOver.getRegionWidth() / 2, Gdx.graphics.getHeight() / 2 - gameOver.getRegionHeight() / 2); } if (gameState == GameState.GameOver || gameState == GameState.Running) { font.draw(batch, "" + score, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() - 60); } batch.end(); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); mainGame.spriteBatch.setProjectionMatrix(camera.combined); world.step(1 / 45f, 6, 2); // Renderable.update for (Renderable r : renderables) { r.update(); } if (Gdx.input.isTouched()) { Gdx.app.debug(TAG, "Fire"); } mainGame.spriteBatch.begin(); // Renderable.render for (Renderable r : renderables) { r.render(mainGame.spriteBatch); } mainGame.spriteBatch.end(); }
@Override public void draw(Player p) { cam.setToOrtho(true, HawkthorneGame.WIDTH, HawkthorneGame.HEIGHT); cam.zoom = 1f; cam.update(true); batch.setProjectionMatrix(cam.combined); batch.begin(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); batch.draw( this.background, cam.viewportWidth / 2 - this.background.getRegionWidth() / 2, cam.viewportHeight / 2 - this.background.getRegionHeight() / 2); batch.setColor(0, 0, 0, 1); BitmapFont font = Assets.getFont(); font.setScale(0.8f, -0.8f); font.draw(batch, "SERVER", 278, 151); font.draw(batch, "CLIENT", 278, 181); batch.setColor(1, 1, 1, 1); batch.draw(this.arrow, 236, 139 + 30 * this.option); String back = Keys.toString(KeyMapping.gameKeyToInt(GameKeys.START)) + ": EXIT GAME"; String howto = "<JUMP> OR " + Keys.toString(KeyMapping.gameKeyToInt(GameKeys.JUMP)) + ": SELECT ITEM"; font.draw(batch, back, 25, 25); font.draw(batch, howto, 25, 55); font.setColor(Color.RED); font.draw(batch, warning, 60, 305); font.setColor(Color.WHITE); batch.end(); }
private void initScreenMode() { switch (project.getScreenMode()) { case STRETCH: stage.setViewport(virtualWidth, virtualHeight, false); screenshotWidth = ScreenValues.SCREEN_WIDTH; screenshotHeight = ScreenValues.SCREEN_HEIGHT; screenshotX = 0; screenshotY = 0; break; case MAXIMIZE: stage.setViewport(virtualWidth, virtualHeight, true); screenshotWidth = maximizeViewPortWidth; screenshotHeight = maximizeViewPortHeight; screenshotX = maximizeViewPortX; screenshotY = maximizeViewPortY; break; default: break; } camera = (OrthographicCamera) stage.getCamera(); camera.position.set(0, 0, 0); camera.update(); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0.3f, 0.6f, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camara.update(); juego.spriteBatch.setProjectionMatrix(camara.combined); // Muestra un menú de inicio juego.spriteBatch.begin(); juego.fuente.draw(juego.spriteBatch, "Fin del juego!!!!", 100, 150); juego.fuente.draw( juego.spriteBatch, "Si quieres jugar otra partida pulsa la tecla 'N'", 100, 110); juego.fuente.draw(juego.spriteBatch, "Pulsa 'ESCAPE' para SALIR", 100, 90); juego.spriteBatch.end(); /* * Si el usuario toca la pantalla se inicia la partida */ if (Gdx.input.isKeyPressed(Keys.N)) { /* * Aquí habrá que reiniciar algunos aspectos del * juego de cara a empezar una nueva partida */ juego.setScreen(new GameScreen(juego)); } /* * El usuario pulsa la tecla ESCAPE, se sale del juego */ else if (Gdx.input.isKeyPressed(Keys.ESCAPE)) { dispose(); System.exit(0); } }
@Override public void render(float arg0) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { if (focused) { focused = false; } else { goBack(); } } if (focused) { shapeRenderer.begin(ShapeType.FilledRectangle); Color c = new Color(0.15f, 0.4f, 0.15f, 1f); shapeRenderer.setColor(c); shapeRenderer.filledRect(focusedBox.x, focusedBox.y, focusedBox.width, focusedBox.height); shapeRenderer.end(); } batch.begin(); ObjectMap.Entries<String, Rectangle> it = bindingButtons.entries(); // draw back button text font.draw(batch, "Back", backButton.x, backButton.y + backButton.height); // draw option texts while (it.hasNext()) { ObjectMap.Entry<String, Rectangle> entry = it.next(); Rectangle bounds = entry.value; font.draw(batch, entry.key, bounds.x, bounds.y + bounds.height); Binding binding = game.getBindings().get(entry.key); font.draw(batch, binding.character, bounds.x + 200.0f, bounds.y + bounds.height); } batch.end(); }
/** used because actors usually need to run the full constructor before adding things to them */ public GameRoot init() { /** * gameroot is 16 units wide and whatever units high, keeping aspect ratio. not too important.. */ this.setSize(16, (screenH / screenW) * 16); cam.setToOrtho(false, getWidth(), getHeight()); cam.update(); this.addListener( new EventListener() { @Override public boolean handle(Event event) { if (event instanceof MobRemoveEvent) { ((MobRemoveEvent) event).removeMob(); if (event instanceof MobTouchedEvent) { stats.pointUp(); screen.pointsChanged(stats.getPoints()); } else if (event instanceof MobExplodeEvent) { screen.mobExploded(stats.mobExploded()); if (stats.getStrikes() >= 5 && !gameOver) gameOver(); } } return false; } }); stats.reset(); gameOver = false; return this; }
public void draw(float deltaTime) { GLCommon gl = Gdx.gl; gl.glClear(GL10.GL_COLOR_BUFFER_BIT); renderer.render(); guiCam.update(); batcher.setProjectionMatrix(guiCam.combined); batcher.enableBlending(); batcher.begin(); switch (state) { case GAME_READY: presentReady(); break; case GAME_RUNNING: presentRunning(); break; case GAME_PAUSED: presentPaused(); break; case GAME_LEVEL_END: presentLevelEnd(); break; case GAME_OVER: presentGameOver(); break; } batcher.end(); }
@Override public void render() { // clear the screen with a dark blue color. The // arguments to glClearColor are the red, green // blue and alpha component in the range [0,1] // of the color to be used to clear the screen. Gdx.gl.glClearColor(0, 0, 0.2f, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // tell the camera to update its matrices. camera.update(); // tell the SpriteBatch to render in the // coordinate system specified by the camera. batch.setProjectionMatrix(camera.combined); // begin a new batch and draw the bucket and // all drops batch.begin(); batch.draw(bucketImage, bucket.x, bucket.y); for (Rectangle raindrop : raindrops) { batch.draw(dropImage, raindrop.x, raindrop.y); } batch.end(); // // process user input if (Gdx.input.isTouched()) { Vector3 touchPos = new Vector3(); touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(touchPos); bucket.x = touchPos.x - 48 / 2; } if (Gdx.input.isKeyPressed(Keys.LEFT)) bucket.x -= 200 * Gdx.graphics.getDeltaTime(); if (Gdx.input.isKeyPressed(Keys.RIGHT)) bucket.x += 200 * Gdx.graphics.getDeltaTime(); // make sure the bucket stays within the screen bounds if (bucket.x < 0) bucket.x = 0; if (bucket.x > 800 - 48) bucket.x = 800 - 48; // commit // check if we need to create a new raindrop if (TimeUtils.nanoTime() - lastDropTime > 1000000000) spawnRaindrop(); // move the raindrops, remove any that are beneath the bottom edge of // the screen or that hit the bucket. In the later case we play back // a sound effect as well. Iterator<Rectangle> iter = raindrops.iterator(); while (iter.hasNext()) { Rectangle raindrop = iter.next(); raindrop.y -= 200 * Gdx.graphics.getDeltaTime(); if (raindrop.y + 48 < 0) iter.remove(); if (raindrop.overlaps(bucket)) { dropSound.play(); iter.remove(); } } }
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { mCurrentPos.set(screenX, screenY, 0); camera.unproject(mCurrentPos); camera.position.sub(mCurrentPos.sub(mCamPos)); camera.update(); return true; }
// Constructor public PlayScreen(KingsValley game) { this.game = game; camera = new OrthographicCamera(); this.ratio = (float) Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight(); camera.setToOrtho(true, this.ratio * this.zoom, this.zoom); camera.position.set(544f / 2f, 480f / 2f, 0f); camera.update(); }
private void cameraUpdate(float delta) { Vector3 position = camera.position; position.x = player.getPosition().x * PPM; position.y = player.getPosition().y * PPM; camera.position.set(position); camera.update(); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); ui.draw(); }
public void resize(int width, int height) { game.WIDTH = width; game.HEIGHT = height; game.scaleWidth = (float) width / game.SCALE; camera.viewportWidth = width; camera.viewportHeight = height; camera.update(); }
@Override public void update() { orthoCam.update(); synchronized (world) { if (world == null) System.out.println("null"); world.step(dt, 6, 2); } }