Refine search
@Override public void create () { camera = new OrthographicCamera(); batch = new SpriteBatch(); long start = System.currentTimeMillis(); int glyphCount = createFonts(); long time = System.currentTimeMillis() - start; text = glyphCount + " glyphs packed in " + regions.size + " page(s) in " + time + " ms"; }
@Override public void render () { Gdx.gl.glClearColor(1, 0, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); cam.update(); batch.setProjectionMatrix(cam.combined); batch.begin(); batch.draw(tex, 1, 1); batch.end(); } }
public void create () { // create a SpriteBatch with which to render the sprite batch = new SpriteBatch(); // load the sprite's texture. note: usually you have more than // one sprite in a texture, see {@see TextureAtlas} and {@see TextureRegion}. texture = new Texture(Gdx.files.internal("data/bobargb8888-32x32.png")); // create an {@link OrthographicCamera} which is used to transform // touch coordinates to world coordinates. camera = new OrthographicCamera(); // we want the camera to setup a viewport with pixels as units, with the // y-axis pointing upwards. The origin will be in the lower left corner // of the screen. camera.setToOrtho(false); }
@Override public void resize (int width, int height) { Gdx.gl.glViewport(0, 0, width, height); if (pixelsPerMeter.getValue() <= 0) { pixelsPerMeter.setValue(1); } worldCamera.setToOrtho(false, width / pixelsPerMeter.getValue(), height / pixelsPerMeter.getValue()); worldCamera.update(); textCamera.setToOrtho(true, width, height); textCamera.update(); effect.setPosition(worldCamera.viewportWidth / 2, worldCamera.viewportHeight / 2); }
@Override public boolean touchDragged (int x, int y, int pointer) { if (!canDrag) return false; camera.unproject(curr.set(x, y, 0)); if (!(last.x == -1 && last.y == -1 && last.z == -1)) { camera.unproject(delta.set(last.x, last.y, 0)); delta.sub(curr); camera.position.add(delta.x, delta.y, 0); } last.set(x, y, 0); camera.update(); return false; }
@Override public void create () { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(); camera.setToOrtho(false, (w / h) * 10, 10); camera.update(); cameraController = new OrthoCamController(camera); Gdx.input.setInputProcessor(cameraController); font = new BitmapFont(); batch = new SpriteBatch(); map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f); }
@Override public void render () { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.setProjectionMatrix(camera.combined); batch.begin(); float x = 10; float y = Gdx.graphics.getHeight() - 10; int renderCalls = 0; // NOTE: Before production release on mobile, you should cache the array from values() // inside the Enum in order to reduce allocations in the render loop. for (FontStyle style : FontStyle.values()) { for (FontSize size : FontSize.values()) { BitmapFont fnt = getFont(style, size); fnt.draw(batch, style.name() + " " + size.size + "pt: The quick brown fox jumps over the lazy dog", x, y); y -= fnt.getLineHeight() + 10; } y -= 20; } BitmapFont font = getFont(FontStyle.Regular, FontSize.Medium); font.draw(batch, text, 10, font.getCapHeight() + 10); // draw all glyphs in background batch.setColor(1f, 1f, 1f, 0.15f); batch.draw(regions.first(), 0, 0); batch.setColor(1f, 1f, 1f, 1f); batch.end(); }
public void render () { // set the clear color and clear the screen. Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // draw the sprite batch.begin(); batch.draw(texture, spritePosition.x, spritePosition.y); batch.end(); // if a finger is down, set the sprite's x/y coordinate. if (Gdx.input.isTouched()) { // the unproject method takes a Vector3 in window coordinates (origin in // upper left corner, y-axis pointing down) and transforms it to world // coordinates. camera.unproject(spritePosition.set(Gdx.input.getX(), Gdx.input.getY(), 0)); } } }
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); cam.position.set(player.getPosition().x, player.getPosition().y, 0); cam.update(); renderer.render(world, cam.combined); cam.project(point.set(pos.x, pos.y, 0)); batch.begin(); font.draw(batch, "friction: " + playerPhysicsFixture.getFriction() + "\ngrounded: " + grounded, point.x + 20, point.y); batch.end();
/** Creates a new viewport using a new {@link OrthographicCamera} and a maximum world size. * @see ExtendViewport#ExtendViewport(float, float, float, float, Camera) */ public ExtendViewport (float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight) { this(minWorldWidth, minWorldHeight, maxWorldWidth, maxWorldHeight, new OrthographicCamera()); }
@Override public void resize (int width, int height) { super.resize(width, height); camera.setToOrtho(true, width, height); spriteBatch.setTransformMatrix(camera.view); spriteBatch.setProjectionMatrix(camera.projection); }
@Override public void create () { // load the koala frames, split them, and assign them to Animations koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png"); TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0]; stand = new Animation(0, regions[0]); jump = new Animation(0, regions[1]); walk = new Animation(0.15f, regions[2], regions[3], regions[4]); walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG); // figure out the width and height of the koala for collision // detection and rendering by converting a koala frames pixel // size into world units (1 unit == 16 pixels) Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth(); Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight(); // load the map, set the unit scale to 1/16 (1 unit == 16 pixels) map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f); // create an orthographic camera, shows us 30x20 units of the world camera = new OrthographicCamera(); camera.setToOrtho(false, 30, 20); camera.update(); // create the Koala we want to move around the world koala = new Koala(); koala.position.set(20, 20); debugRenderer = new ShapeRenderer(); }
@Override public void resize (int width, int height) { camera.viewportWidth = width; camera.viewportHeight = height; camera.update(); }
@Override public boolean touchDragged (int x, int y, int pointer) { camera.unproject(curr.set(x, y, 0)); if (!(last.x == -1 && last.y == -1 && last.z == -1)) { camera.unproject(delta.set(last.x, last.y, 0)); delta.sub(curr); camera.position.add(delta.x, delta.y, 0); } last.set(x, y, 0); return false; }
@Override public void create () { float aspect = Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight(); camera = new OrthographicCamera(15 * aspect, 15); camera.update(); renderer = new ShapeRenderer(); renderer.setProjectionMatrix(camera.combined); bones = new Bone[] {new Bone("bone0", 0, 0, 0), new Bone("bone1", 0, 2, 2), new Bone("bone2", 0, 4, 2), new Bone("bone3", 0, 6, 2), new Bone("end", 0, 8, 2)}; globalCoords.set(bones[0].position); }
@Override public void resize (int width, int height) { // handling resizing is simple, just set the camera to ortho again camera.setToOrtho(true, width, height); }
/** * Cleans up all translations, scaling and rotation */ private void undoTransformations() { if (rotation != 0f) { camera.rotateAround(new Vector3(rotationX, rotationY, 0), new Vector3(0, 0, 1), rotation); } camera.update(); if (translationX != 0f || translationY != 0f) { camera.translate(-translationX, -translationY); } camera.update(); }
/** Moves the camera by the given amount on each axis. * @param x the displacement on the x-axis * @param y the displacement on the y-axis */ public void translate (float x, float y) { translate(x, y, 0); }