@Override public boolean scrolled(int amount) { camera.zoom += (amount * 0.1f); if (camera.zoom < 0.1f) { camera.zoom = 0.1f; } camera.update(); return true; }
private void processInput() { if (Gdx.input.isKeyPressed(Keys.LEFT) && (worldCamera.position.x - worldCamera.viewportWidth * .5f > 0)) worldCamera.position.sub(deltaDimen, 0, 0); else if (Gdx.input.isKeyPressed(Keys.RIGHT)) worldCamera.position.add(deltaDimen, 0, 0); else if (Gdx.input.isKeyPressed(Keys.DOWN)) worldCamera.position.sub(0, deltaDimen, 0); else if (Gdx.input.isKeyPressed(Keys.UP)) worldCamera.position.add(0, deltaDimen, 0); else if (Gdx.input.isKeyPressed(Keys.CONTROL_RIGHT)) worldCamera.zoom *= 1.1f; else if (Gdx.input.isKeyPressed(Keys.ALT_RIGHT)) worldCamera.zoom /= 1.1f; worldCamera.update(); batch.setProjectionMatrix(worldCamera.combined); }
public void getInput() { if ((stop || win) && Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { stop = win = false; create(); } if (Gdx.input.isKeyJustPressed(Input.Keys.A)) { camera.zoom += 1; } if (Gdx.input.isKeyJustPressed(Input.Keys.S)) { camera.zoom -= 1; } }
@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 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(); }
@Override public void create() { batch = new SpriteBatch(); hudBatch = new SpriteBatch(); Box2D.init(); world = new World(new Vector2(0, 0), true); ship = SpaceShip.createIn(world, 5, 5); box2dRenderer = new Box2DDebugRenderer(); camera = new OrthographicCamera(WINDOW_WIDTH, WINDOW_HEIGHT); camera.zoom = 0.10f; camera.update(); asteroids = new ArrayList<>(); MapInputProcessor inputProcessor = new MapInputProcessor(camera, ship); Gdx.input.setInputProcessor(inputProcessor); }
public void applyTo(OrthographicCamera camera) { camera.position.x = position.x; camera.position.y = position.y; camera.zoom = zoom; camera.update(); }
@Override public void create() { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); bitmapFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); Gdx.input.setInputProcessor(this); mCamPos = new Vector3(); mCurrentPos = new Vector3(); camera = new OrthographicCamera(100, 100 * h / w); camera.position.set(50, 50, 0); camera.zoom = 1.8f; camera.update(); textCam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); textCam.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0); textCam.zoom = 1; textCam.update(); loader = new RubeSceneLoader(); scene = loader.loadScene(Gdx.files.internal("data/palm.json")); debugRender = new Box2DDebugRenderer(); batch = new SpriteBatch(); polygonBatch = new PolygonSpriteBatch(); textureMap = new HashMap<String, Texture>(); textureRegionMap = new HashMap<Texture, TextureRegion>(); createSpatialsFromRubeImages(scene); createPolySpatialsFromRubeFixtures(scene); mWorld = scene.getWorld(); // configure simulation settings mVelocityIter = scene.velocityIterations; mPositionIter = scene.positionIterations; if (scene.stepsPerSecond != 0) { mSecondsPerStep = 1f / scene.stepsPerSecond; } mWorld.setContactListener(this); // // example of custom property handling // Array<Body> bodies = scene.getBodies(); if ((bodies != null) && (bodies.size > 0)) { for (int i = 0; i < bodies.size; i++) { Body body = bodies.get(i); String gameInfo = (String) scene.getCustom(body, "GameInfo", null); if (gameInfo != null) { System.out.println("GameInfo custom property: " + gameInfo); } } } // Example of accessing data based on name System.out.println("body0 count: " + scene.getNamed(Body.class, "body0").size); // Note: the scene has two fixture9 names defined, but these are in turn subdivided into // multiple fixtures and thus appear several times... System.out.println("fixture9 count: " + scene.getNamed(Fixture.class, "fixture9").size); scene.printStats(); // // validate the custom settings attached to world object.. // boolean testBool = (Boolean) scene.getCustom(mWorld, "testCustomBool", false); int testInt = (Integer) scene.getCustom(mWorld, "testCustomInt", 0); float testFloat = (Float) scene.getCustom(mWorld, "testCustomFloat", 0); Color color = (Color) scene.getCustom(mWorld, "testCustomColor", null); Vector2 vec = (Vector2) scene.getCustom(mWorld, "testCustomVec2", null); String string = (String) scene.getCustom(mWorld, "testCustomString", null); if (testBool == false) { throw new GdxRuntimeException( "testCustomBool not read correctly! Expected: " + true + " Actual: " + testBool); } if (testInt != 8675309) { throw new GdxRuntimeException( "testCustomInt not read correctly! Expected: " + 8675309 + " Actual: " + testInt); } if (testFloat != 1.25f) { throw new GdxRuntimeException( "testCustomFloat not read correctly! Expected: " + 1.25f + " Actual: " + testFloat); } if (color == null) { throw new GdxRuntimeException("testCustomColor is reporting null!"); } if ((color.r != 17f / 255) || (color.g != 29f / 255) || (color.b != 43f / 255) || (color.a != 61f / 255)) { throw new GdxRuntimeException( "testCustomColor not read correctly! Expected: " + new Color(17f / 255, 29f / 255, 43f / 255, 61f / 255) + " Actual: " + color); } if (vec == null) { throw new GdxRuntimeException("testCustomVec2 is reporting null!"); } if ((vec.x != 314159) || (vec.y != 21718)) { throw new GdxRuntimeException( "testCustomVec2 is not read correctly! Expected: " + new Vector2(314159, 21718) + " Actual: " + vec); } if (string == null) { throw new GdxRuntimeException("testCustomString is reporting null!"); } if (!string.equalsIgnoreCase("excelsior!")) { throw new GdxRuntimeException( "testCustomString is not read correctly! Expected: Excelsior! Actual: " + string); } scene.clear(); // no longer need any scene references }
@Override public void create() { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); Gdx.input.setInputProcessor(this); mB2Controllers = new Array<B2Controller>(); mCamPos = new Vector3(); mCurrentPos = new Vector3(); camera = new OrthographicCamera(100, 100 * h / w); camera.position.set(50, 50, 0); camera.zoom = 1.8f; camera.update(); loader = new RubeSceneLoader(); scene = loader.loadScene(Gdx.files.internal("data/palmcontrollers.json")); debugRender = new Box2DDebugRenderer(); batch = new SpriteBatch(); polygonBatch = new PolygonSpriteBatch(); textureMap = new HashMap<String, Texture>(); textureRegionMap = new HashMap<Texture, TextureRegion>(); createSpatialsFromRubeImages(scene); createPolySpatialsFromRubeFixtures(scene); mWorld = scene.getWorld(); // configure simulation settings mVelocityIter = scene.velocityIterations; mPositionIter = scene.positionIterations; if (scene.stepsPerSecond != 0) { mSecondsPerStep = 1f / scene.stepsPerSecond; } mWorld.setContactListener(this); // // example of custom property handling // Array<Body> bodies = scene.getBodies(); if ((bodies != null) && (bodies.size > 0)) { for (int i = 0; i < bodies.size; i++) { Body body = bodies.get(i); String gameInfo = (String) scene.getCustom(body, "GameInfo", null); if (gameInfo != null) { System.out.println("GameInfo custom property: " + gameInfo); } } } // Instantiate any controllers that are in the scene Array<Fixture> fixtures = scene.getFixtures(); if ((fixtures != null) && (fixtures.size > 0)) { for (int i = 0; i < fixtures.size; i++) { Fixture fixture = fixtures.get(i); int controllerType = (Integer) scene.getCustom(fixture, "ControllerType", 0); switch (controllerType) { case B2Controller.BUOYANCY_CONTROLLER: // only allow polygon buoyancy controllers for now.. if (fixture.getShape().getType() == Shape.Type.Polygon) { float bodyHeight = fixture.getBody().getPosition().y; // B2BuoyancyController b2c = new B2BuoyancyController(); // need to calculate the fluid surface height for the buoyancy controller PolygonShape shape = (PolygonShape) fixture.getShape(); shape.getVertex(0, mTmp); float maxHeight = mTmp.y + bodyHeight; // initialize the height, transforming to 'world' // coordinates // find the maxHeight for (int j = 1; j < shape.getVertexCount(); j++) { shape.getVertex(j, mTmp); maxHeight = Math.max(maxHeight, mTmp.y + bodyHeight); // transform to world coordinates } B2BuoyancyController b2c = new B2BuoyancyController( B2BuoyancyController.DEFAULT_SURFACE_NORMAL, // assume up (Vector2) scene.getCustom( fixture, "ControllerVelocity", B2BuoyancyController.DEFAULT_FLUID_VELOCITY), mWorld.getGravity(), maxHeight, fixture.getDensity(), (Float) scene.getCustom( fixture, "LinearDrag", B2BuoyancyController.DEFAULT_LINEAR_DRAG), (Float) scene.getCustom( fixture, "AngularDrag", B2BuoyancyController.DEFAULT_ANGULAR_DRAG)); fixture.setUserData(b2c); // reference back to the controller from the fixture (see // beginContact/endContact) mB2Controllers.add(b2c); // add it to the list so it can be stepped later } break; case B2Controller.GRAVITY_CONTROLLER: { B2GravityController b2c = new B2GravityController(); b2c = new B2GravityController( (Vector2) scene.getCustom( fixture, "ControllerVelocity", B2GravityController.DEFAULT_GRAVITY)); fixture.setUserData(b2c); mB2Controllers.add(b2c); } break; } } } scene.printStats(); scene.clear(); // no longer need any scene references }
public void zoom(OrthographicCamera cam, float amount) { zoom += amount; zoom = Math.min(Math.max(zoom, 0.1f), 10f); cam.zoom = zoom; }
public Mapa(com.juegospichurria.modelo.Mapa mapa, int filaActivo, int columnaActivo) { cantInactivos = 0; Cuadro.contActivos = 0; mapatemp = mapa; Juego.mapaid = mapa.numeroDeMapa; estado_botones = new Stage(new FitViewport(480, 800)); gana = new Image(new TextureRegionDrawable(Recursos.getRecursos().getImagenSubmenu("win"))); gana.setBounds( 80, (qbox.Pantalla.ALTO - Recursos.getRecursos().getImagenSubmenu("fail").getRegionHeight() * 2), Recursos.getRecursos().getImagenSubmenu("fail").getRegionWidth(), Recursos.getRecursos().getImagenSubmenu("win").getRegionHeight()); pierde = new Image(new TextureRegionDrawable(Recursos.getRecursos().getImagenSubmenu("fail"))); pierde.setBounds( 80, (qbox.Pantalla.ALTO - Recursos.getRecursos().getImagenSubmenu("fail").getRegionHeight() * 2), Recursos.getRecursos().getImagenSubmenu("fail").getRegionWidth(), Recursos.getRecursos().getImagenSubmenu("fail").getRegionHeight()); replay = new Button(new TextureRegionDrawable(Recursos.getRecursos().getImagenSubmenu("replay"))); replay.setTouchable(Touchable.enabled); replay.setBounds( qbox.Pantalla.ANCHO / 2, qbox.Pantalla.ALTO / 2, Recursos.getRecursos().getImagenSubmenu("replay").getRegionWidth(), Recursos.getRecursos().getImagenSubmenu("replay").getRegionHeight()); replay.addListener( new ActorGestureListener() { public void tap(InputEvent event, float x, float y, int count, int button) { System.out.println("me toco"); Cuadro.contActivos = 0; Juego.pierde = true; Juego.gana = false; } }); next = new Button(new TextureRegionDrawable(Recursos.getRecursos().getImagenSubmenu("next"))); next.setBounds( qbox.Pantalla.ANCHO / 2, (qbox.Pantalla.ALTO / 2) - 80, Recursos.getRecursos().getImagenSubmenu("reset").getRegionWidth(), Recursos.getRecursos().getImagenSubmenu("reset").getRegionHeight()); next.addListener( new ActorGestureListener() { public void tap(InputEvent event, float x, float y, int count, int button) { System.out.println("me toco next"); Cuadro.contActivos = 0; Juego.gana = true; Juego.pierde = false; } }); reset = new Button(new TextureRegionDrawable(Recursos.getRecursos().getImagenSubmenu("reset"))); reset.setBounds( 0, 800 - Recursos.getRecursos().getImagenSubmenu("reset").getRegionHeight(), Recursos.getRecursos().getImagenSubmenu("reset").getRegionWidth(), Recursos.getRecursos().getImagenSubmenu("reset").getRegionHeight()); reset.addListener( new ActorGestureListener() { public void tap(InputEvent event, float x, float y, int count, int button) { System.out.println("me toco"); Cuadro.contActivos = 0; time = 0; Juego.pierde = true; Juego.gana = false; } }); menu = new Button(new TextureRegionDrawable(Recursos.getRecursos().getImagenSubmenu("menu"))); menu.setBounds( (qbox.Pantalla.ANCHO / 2) - Recursos.getRecursos().getImagenSubmenu("menu").getRegionWidth(), (qbox.Pantalla.ALTO / 2) - 30, Recursos.getRecursos().getImagenSubmenu("menu").getRegionWidth(), Recursos.getRecursos().getImagenSubmenu("menu").getRegionHeight()); menu.addListener( new ActorGestureListener() { public void tap(InputEvent event, float x, float y, int count, int button) { System.out.println("me toco menu"); Juego.menu = true; } }); estado_botones.addActor(replay); estado_botones.addActor(menu); estado_botones.addActor(next); batch2 = new SpriteBatch(); camara2 = new OrthographicCamera(); camara2.setToOrtho(false, 320, 480); batch2.setProjectionMatrix(camara2.combined); camara2.zoom = 120; camara2.update(); filatemp = filaActivo; columnatemp = columnaActivo; estado_juego = ESTADO_NORMAL; Inicializar(mapatemp, filatemp, columnatemp); }
@Override public boolean scrolled(int amount) { camera.zoom -= -amount * Gdx.graphics.getDeltaTime() / 50; camera.update(); return true; }