Search in sources :

Example 6 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 7 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 8 with Sprite

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

the class SpriteDrawable method tint.

/** Creates a new drawable that renders the same as this drawable tinted the specified color. */
public SpriteDrawable tint(Color tint) {
    Sprite newSprite;
    if (sprite instanceof AtlasSprite)
        newSprite = new AtlasSprite((AtlasSprite) sprite);
    else
        newSprite = new Sprite(sprite);
    newSprite.setColor(tint);
    newSprite.setSize(getMinWidth(), getMinHeight());
    SpriteDrawable drawable = new SpriteDrawable(newSprite);
    drawable.setLeftWidth(getLeftWidth());
    drawable.setRightWidth(getRightWidth());
    drawable.setTopHeight(getTopHeight());
    drawable.setBottomHeight(getBottomHeight());
    return drawable;
}
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)

Example 9 with Sprite

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

the class TextureRegionDrawable method tint.

/** Creates a new drawable that renders the same as this drawable tinted the specified color. */
public Drawable tint(Color tint) {
    Sprite sprite;
    if (region instanceof AtlasRegion)
        sprite = new AtlasSprite((AtlasRegion) region);
    else
        sprite = new Sprite(region);
    sprite.setColor(tint);
    sprite.setSize(getMinWidth(), getMinHeight());
    SpriteDrawable drawable = new SpriteDrawable(sprite);
    drawable.setLeftWidth(getLeftWidth());
    drawable.setRightWidth(getRightWidth());
    drawable.setTopHeight(getTopHeight());
    drawable.setBottomHeight(getBottomHeight());
    return drawable;
}
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)

Example 10 with Sprite

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

the class Skin method getDrawable.

/** Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the
	 * appropriate drawable is created and stored in the skin. */
public Drawable getDrawable(String name) {
    Drawable drawable = optional(name, Drawable.class);
    if (drawable != null)
        return drawable;
    // Use texture or texture region. If it has splits, use ninepatch. If it has rotation or whitespace stripping, use sprite.
    try {
        TextureRegion textureRegion = getRegion(name);
        if (textureRegion instanceof AtlasRegion) {
            AtlasRegion region = (AtlasRegion) textureRegion;
            if (region.splits != null)
                drawable = new NinePatchDrawable(getPatch(name));
            else if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
                drawable = new SpriteDrawable(getSprite(name));
        }
        if (drawable == null)
            drawable = new TextureRegionDrawable(textureRegion);
    } catch (GdxRuntimeException ignored) {
    }
    // Check for explicit registration of ninepatch, sprite, or tiled drawable.
    if (drawable == null) {
        NinePatch patch = optional(name, NinePatch.class);
        if (patch != null)
            drawable = new NinePatchDrawable(patch);
        else {
            Sprite sprite = optional(name, Sprite.class);
            if (sprite != null)
                drawable = new SpriteDrawable(sprite);
            else
                throw new GdxRuntimeException("No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: " + name);
        }
    }
    if (drawable instanceof BaseDrawable)
        ((BaseDrawable) drawable).setName(name);
    add(name, drawable, Drawable.class);
    return drawable;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

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