Search in sources :

Example 6 with SpriteBatch

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

the class FilesTest method create.

@Override
public void create() {
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    batch = new SpriteBatch();
    if (Gdx.files.isExternalStorageAvailable()) {
        message += "External storage available\n";
        message += "External storage path: " + Gdx.files.getExternalStoragePath() + "\n";
        try {
            InputStream in = Gdx.files.internal("data/cube.obj").read();
            StreamUtils.closeQuietly(in);
            message += "Open internal success\n";
        } catch (Throwable e) {
            message += "Couldn't open internal data/cube.obj\n" + e.getMessage() + "\n";
        }
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external("test.txt").write(false)));
            out.write("test");
            message += "Write external success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open externalstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't write externalstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(out);
        }
        try {
            InputStream in = Gdx.files.external("test.txt").read();
            StreamUtils.closeQuietly(in);
            message += "Open external success\n";
        } catch (Throwable e) {
            message += "Couldn't open internal externalstorage/test.txt\n" + e.getMessage() + "\n";
        }
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(Gdx.files.external("test.txt").read()));
            if (!in.readLine().equals("test"))
                message += "Read result wrong\n";
            else
                message += "Read external success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open externalstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't read externalstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(in);
        }
        if (!Gdx.files.external("test.txt").delete())
            message += "Couldn't delete externalstorage/test.txt";
    } else {
        message += "External storage not available";
    }
    if (Gdx.files.isLocalStorageAvailable()) {
        message += "Local storage available\n";
        message += "Local storage path: " + Gdx.files.getLocalStoragePath() + "\n";
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(Gdx.files.local("test.txt").write(false)));
            out.write("test");
            message += "Write local success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open localstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't write localstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(out);
        }
        try {
            InputStream in = Gdx.files.local("test.txt").read();
            StreamUtils.closeQuietly(in);
            message += "Open local success\n";
        } catch (Throwable e) {
            message += "Couldn't open localstorage/test.txt\n" + e.getMessage() + "\n";
        }
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(Gdx.files.local("test.txt").read()));
            if (!in.readLine().equals("test"))
                message += "Read result wrong\n";
            else
                message += "Read local success\n";
        } catch (GdxRuntimeException ex) {
            message += "Couldn't open localstorage/test.txt\n";
        } catch (IOException e) {
            message += "Couldn't read localstorage/test.txt\n";
        } finally {
            StreamUtils.closeQuietly(in);
        }
        try {
            byte[] testBytes = Gdx.files.local("test.txt").readBytes();
            if (Arrays.equals("test".getBytes(), testBytes))
                message += "Read into byte array success\n";
            else
                fail();
        } catch (Throwable e) {
            message += "Couldn't read localstorage/test.txt\n" + e.getMessage() + "\n";
        }
        if (!Gdx.files.local("test.txt").delete())
            message += "Couldn't delete localstorage/test.txt";
    }
    try {
        testClasspath();
        testInternal();
        testExternal();
        testAbsolute();
        testLocal();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BufferedWriter(java.io.BufferedWriter)

Example 7 with SpriteBatch

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

the class FilterPerformanceTest method create.

public void create() {
    batch = new SpriteBatch();
    sceneMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    textMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    atlas = new TextureAtlas(Gdx.files.internal("data/issue_pack"), Gdx.files.internal("data/"));
    texture = new Texture(Gdx.files.internal("data/resource1.jpg"), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
    setTextureFilter(0);
    setModeString();
    sprite = atlas.createSprite("map");
    sprite2 = new Sprite(texture, 0, 0, 855, 480);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            mode++;
            if (mode == filters.length * 2)
                mode = 0;
            setTextureFilter(mode / 2);
            setModeString();
            return false;
        }
    });
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 8 with SpriteBatch

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

the class Box2DCharacterControllerTest method create.

@Override
public void create() {
    world = new World(new Vector2(0, -40), true);
    renderer = new Box2DDebugRenderer();
    cam = new OrthographicCamera(28, 20);
    createWorld();
    Gdx.input.setInputProcessor(this);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 9 with SpriteBatch

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

the class Box2DTest method create.

@Override
public void create() {
    // setup the camera. In Box2D we operate on a
    // meter scale, pixels won't do it. So we use
    // an orthographic camera with a viewport of
    // 48 meters in width and 32 meters in height.
    // We also position the camera so that it
    // looks at (0,16) (that's where the middle of the
    // screen will be located).
    camera = new OrthographicCamera(48, 32);
    camera.position.set(0, 16, 0);
    // next we setup the immediate mode renderer
    renderer = new ShapeRenderer();
    // next we create the box2d debug renderer
    debugRenderer = new Box2DDebugRenderer();
    // next we create a SpriteBatch and a font
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    font.setColor(Color.RED);
    textureRegion = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
    // next we create out physics world.
    createPhysicsWorld();
    // register ourselfs as an InputProcessor
    Gdx.input.setInputProcessor(this);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 10 with SpriteBatch

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

the class Bresenham2Test method create.

@Override
public void create() {
    Pixmap pixmap = new Pixmap(512, 512, Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    Bresenham2 bresenham = new Bresenham2();
    for (GridPoint2 point : bresenham.line(0, 0, 512, 512)) pixmap.drawPixel(point.x, point.y);
    for (GridPoint2 point : bresenham.line(512, 0, 0, 512)) pixmap.drawPixel(point.x, point.y);
    for (GridPoint2 point : bresenham.line(0, 0, 512, 256)) pixmap.drawPixel(point.x, point.y);
    for (GridPoint2 point : bresenham.line(512, 0, 0, 256)) pixmap.drawPixel(point.x, point.y);
    result = new Texture(pixmap);
    batch = new SpriteBatch();
}
Also used : Bresenham2(com.badlogic.gdx.math.Bresenham2) GridPoint2(com.badlogic.gdx.math.GridPoint2) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Pixmap(com.badlogic.gdx.graphics.Pixmap)

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