Search in sources :

Example 11 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class TiledMapLayerOffsetTest method create.

@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.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    shapeRenderer = new ShapeRenderer();
    assetManager = new AssetManager();
    assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
    assetManager.load(MAP_ORTHO, TiledMap.class);
    assetManager.load(MAP_ISO, TiledMap.class);
    assetManager.load(MAP_ISO_STAG, TiledMap.class);
    assetManager.load(MAP_HEX_X, TiledMap.class);
    assetManager.load(MAP_HEX_Y, TiledMap.class);
    assetManager.finishLoading();
    map = assetManager.get(MAP_ORTHO);
    renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 12 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class TextureAtlasTest method create.

public void create() {
    batch = new SpriteBatch();
    renderer = new ShapeRenderer();
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
    jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
    jumpAnimation = new Animation(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));
    badlogic = atlas.createSprite("badlogicslice");
    badlogic.setPosition(50, 50);
    // badlogicSmall = atlas.createSprite("badlogicsmall");
    badlogicSmall = atlas.createSprite("badlogicsmall-rotated");
    badlogicSmall.setPosition(10, 10);
    AtlasRegion region = atlas.findRegion("badlogicsmall");
    System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);
    System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);
    star = atlas.createSprite("particle-star");
    star.setPosition(10, 70);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
    Gdx.gl.glClearColor(0, 1, 0, 1);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyUp(int keycode) {
            if (keycode == Keys.UP) {
                badlogicSmall.flip(false, true);
            } else if (keycode == Keys.RIGHT) {
                badlogicSmall.flip(true, false);
            } else if (keycode == Keys.LEFT) {
                badlogicSmall.setSize(512, 512);
            } else if (keycode == Keys.DOWN) {
                badlogicSmall.rotate90(true);
            }
            return super.keyUp(keycode);
        }
    });
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) Animation(com.badlogic.gdx.graphics.g2d.Animation) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 13 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class ConvexHullDistanceTest method create.

@Override
public void create() {
    super.create();
    final Model carModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(carModel);
    carModel.materials.get(0).clear();
    carModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE));
    world.addConstructor("car", new BulletConstructor(carModel, 5f, createConvexHullShape(carModel, true)));
    // Create the entities
    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    for (float y = 10f; y < 50f; y += 5f) world.add("car", -2f + (float) Math.random() * 4f, y, -2f + (float) Math.random() * 4f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    distance = new ConvexHullDistance();
    shapeRenderer = new ShapeRenderer();
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 14 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class TriangleRaycastTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap a triangle to ray cast\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
    shapeRenderer = new ShapeRenderer();
    model = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    model.materials.get(0).clear();
    model.materials.get(0).set(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE));
    // Only indexed BvhTriangleMeshShape can be used for triangle picking.
    btTriangleIndexVertexArray vertexArray = new btTriangleIndexVertexArray(model.meshParts);
    triangleShape = new btBvhTriangleMeshShape(vertexArray, true);
    triangleRaycastCallback = new MyTriangleRaycastCallback(Vector3.Zero, Vector3.Zero);
    // Ignore intersection with mesh backfaces.
    triangleRaycastCallback.setFlags(EFlags.kF_FilterBackfaces);
    world.addConstructor("scene", new BulletConstructor(model, 0, triangleShape));
    world.add("scene", 0, 0, 0);
    disposables.add(model);
    disposables.add(triangleRaycastCallback);
    disposables.add(triangleShape);
    disposables.add(vertexArray);
    disposables.add(shapeRenderer);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape(com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape) com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray(com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 15 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class FreeTypeIncrementalTest method create.

public void create() {
    batch = new SpriteBatch();
    shapes = new ShapeRenderer();
    shapes.setColor(Color.RED);
    FreeTypeFontGenerator.setMaxTextureSize(128);
    generator = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf"));
    FreeTypeFontParameter param = new FreeTypeFontParameter();
    param.incremental = true;
    param.size = 24;
    param.characters = "howdY";
    FreeTypeBitmapFontData data = new FreeTypeBitmapFontData() {

        public int getWrapIndex(Array<Glyph> glyphs, int start) {
            return SimplifiedChinese.getWrapIndex(glyphs, start);
        }
    };
    // By default latin chars are used for x and cap height, causing some fonts to display non-latin chars out of bounds.
    data.xChars = new char[] { '动' };
    data.capChars = new char[] { '动' };
    font = generator.generateFont(param, data);
}
Also used : Array(com.badlogic.gdx.utils.Array) FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) FreeTypeBitmapFontData(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Aggregations

ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)31 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)16 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)12 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)10 Texture (com.badlogic.gdx.graphics.Texture)8 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)7 Stage (com.badlogic.gdx.scenes.scene2d.Stage)5 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)5 InputAdapter (com.badlogic.gdx.InputAdapter)4 AssetManager (com.badlogic.gdx.assets.AssetManager)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)3 Animation (com.badlogic.gdx.graphics.g2d.Animation)2 BitmapFontCache (com.badlogic.gdx.graphics.g2d.BitmapFontCache)2 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)2 FreeTypeFontParameter (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter)2 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)2