Search in sources :

Example 11 with Sprite

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

the class SpriteCacheOffsetTest method create.

public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    Sprite sprite = new Sprite(texture);
    sprite.setSize(tileSize, tileSize);
    cache = new SpriteCache(1000, false);
    for (int y = 0; y < tileMapHeight; y++) {
        cache.beginCache();
        for (int x = 0; x < tileMapWidth; x++) {
            sprite.setPosition(x * tileSize, y * tileSize);
            cache.add(sprite);
        }
        cache.endCache();
        sprite.rotate90(true);
    }
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache) Texture(com.badlogic.gdx.graphics.Texture)

Example 12 with Sprite

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

the class GwtTest method create.

@Override
public void create() {
    Preferences pref = Gdx.app.getPreferences("test");
    boolean resultb = pref.getBoolean("test");
    int resulti = pref.getInteger("test");
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
    if (!shader.isCompiled())
        throw new GdxRuntimeException(shader.getLog());
    mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
    texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    String params = Gdx.files.internal("data/gwttestparams.txt").readString();
    numSprites = Integer.parseInt(params);
    batch = new SpriteBatch();
    positions = new ArrayList<Vector2>();
    for (int i = 0; i < numSprites; i++) {
        positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
    }
    sprite = new Sprite(texture);
    sprite.setSize(64, 64);
    sprite.setOrigin(32, 32);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    cache = font.newFontCache();
    cache.setColor(Color.RED);
    cache.setText("This is a Test", 0, 0);
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Mesh(com.badlogic.gdx.graphics.Mesh) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Vector2(com.badlogic.gdx.math.Vector2) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Preferences(com.badlogic.gdx.Preferences) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 13 with Sprite

use of com.badlogic.gdx.graphics.g2d.Sprite in project commons-gdx by gemserk.

the class SpriteUtilsTest method shouldReturnNotAliasWhenAtlasRegionsAreNotEqual.

@Test
public void shouldReturnNotAliasWhenAtlasRegionsAreNotEqual() {
    Sprite sprite1 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 40, 40));
    Sprite sprite2 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 20, 40));
    assertFalse(SpriteUtils.isAliasSprite(sprite1, sprite2));
}
Also used : AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Test(org.junit.Test)

Example 14 with Sprite

use of com.badlogic.gdx.graphics.g2d.Sprite in project commons-gdx by gemserk.

the class SpriteUtilsTest method shouldReturnIsAliasWhenRegionEquals.

@Test
public void shouldReturnIsAliasWhenRegionEquals() {
    TextureRegion region1 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    TextureRegion region2 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    Sprite sprite1 = new Sprite(region1);
    Sprite sprite2 = new Sprite(region2);
    assertTrue(SpriteUtils.isAliasSprite(sprite1, sprite2));
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Test(org.junit.Test)

Example 15 with Sprite

use of com.badlogic.gdx.graphics.g2d.Sprite in project commons-gdx by gemserk.

the class SpriteUtilsTest method shouldReturnFalseIfSpriteNull.

@Test
public void shouldReturnFalseIfSpriteNull() {
    TextureRegion region1 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    Sprite sprite1 = new Sprite(region1);
    assertFalse(SpriteUtils.isAliasSprite(sprite1, null));
    assertFalse(SpriteUtils.isAliasSprite(null, sprite1));
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Test(org.junit.Test)

Aggregations

Sprite (com.badlogic.gdx.graphics.g2d.Sprite)40 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)19 Texture (com.badlogic.gdx.graphics.Texture)17 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)13 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)10 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)8 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)8 Test (org.junit.Test)8 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)7 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)6 Pixmap (com.badlogic.gdx.graphics.Pixmap)5 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)4 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)4 InputAdapter (com.badlogic.gdx.InputAdapter)3 Matrix4 (com.badlogic.gdx.math.Matrix4)3 Vector2 (com.badlogic.gdx.math.Vector2)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)3