Search in sources :

Example 66 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class TiledMapModifiedExternalTilesetTest 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.position.set(10.0f, 2.5f, 0.0f);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    // These two maps should appear identical -- a ring of grass with water inside and out.
    // The original is correct, without the bug fix to TiledMapTileSets.java that acompanies
    // this test, the latter appears as all grass.
    //		map = new TmxMapLoader().load("data/maps/tiled/external-tilesets/test_original.tmx");
    map = new TmxMapLoader().load("data/maps/tiled/external-tilesets/test_extended.tmx");
    renderer = new IsometricTiledMapRenderer(map, 1f / 32f);
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) IsometricTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.IsometricTiledMapRenderer) 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)

Example 67 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class TiledMapObjectLoadingTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 100, 100);
    camera.zoom = 2;
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    map = new TmxMapLoader().load("data/maps/tiled-objects/test-load-mapobjects.tmx");
    MapProperties properties = map.getProperties();
    shapeRenderer = new ShapeRenderer();
}
Also used : TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) MapProperties(com.badlogic.gdx.maps.MapProperties) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 68 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class StagePerformanceTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    font = new BitmapFont();
    stage = new Stage(new ScalingViewport(Scaling.fit, 24, 12));
    regions = new TextureRegion[8 * 8];
    sprites = new Sprite[24 * 12];
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 8; x++) {
            regions[x + y * 8] = new TextureRegion(texture, x * 32, y * 32, 32, 32);
        }
    }
    Random rand = new Random();
    for (int y = 0, i = 0; y < 12; y++) {
        for (int x = 0; x < 24; x++) {
            Image img = new Image(regions[rand.nextInt(8 * 8)]);
            img.setBounds(x, y, 1, 1);
            stage.addActor(img);
            sprites[i] = new Sprite(regions[rand.nextInt(8 * 8)]);
            sprites[i].setPosition(x, y);
            sprites[i].setSize(1, 1);
            i++;
        }
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Random(java.util.Random) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Stage(com.badlogic.gdx.scenes.scene2d.Stage) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Example 69 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class SimpleAnimationTest method create.

@Override
public void create() {
    Gdx.input.setInputProcessor(this);
    texture = new Texture(Gdx.files.internal("data/animation.png"));
    TextureRegion[][] regions = TextureRegion.split(texture, 32, 48);
    TextureRegion[] downWalkReg = regions[0];
    TextureRegion[] leftWalkReg = regions[1];
    TextureRegion[] rightWalkReg = regions[2];
    TextureRegion[] upWalkReg = regions[3];
    downWalk = new Animation<TextureRegion>(ANIMATION_SPEED, downWalkReg);
    leftWalk = new Animation<TextureRegion>(ANIMATION_SPEED, leftWalkReg);
    rightWalk = new Animation<TextureRegion>(ANIMATION_SPEED, rightWalkReg);
    upWalk = new Animation<TextureRegion>(ANIMATION_SPEED, upWalkReg);
    currentWalk = leftWalk;
    currentFrameTime = 0.0f;
    spriteBatch = new SpriteBatch();
    position = new Vector2();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Vector2(com.badlogic.gdx.math.Vector2) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 70 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch in project libgdx by libgdx.

the class SoftKeyboardTest method create.

@Override
public void create() {
    // we want to render the input, so we need
    // a sprite batch and a font
    batch = new SpriteBatch();
    font = new BitmapFont();
    textBuffer = new SimpleCharSequence();
    // we register an InputAdapter to listen for the keyboard
    // input. The on-screen keyboard might only generate
    // "key typed" events, depending on the backend.
    Gdx.input.setInputProcessor(new InputAdapter() {

        @Override
        public boolean keyTyped(char character) {
            // convert \r to \n
            if (character == '\r')
                character = '\n';
            // if we get \b, we remove the last inserted character
            if (character == '\b' && textBuffer.length() > 0) {
                textBuffer.delete();
            }
            // else we just insert the character
            textBuffer.add(character);
            return true;
        }
    });
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)121 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)64 Texture (com.badlogic.gdx.graphics.Texture)59 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)32 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)22 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)16 Pixmap (com.badlogic.gdx.graphics.Pixmap)15 AssetManager (com.badlogic.gdx.assets.AssetManager)13 Stage (com.badlogic.gdx.scenes.scene2d.Stage)13 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)11 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)10 InputAdapter (com.badlogic.gdx.InputAdapter)9 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)8 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)7 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)7 Vector2 (com.badlogic.gdx.math.Vector2)7