Search in sources :

Example 31 with Sprite

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

the class AnimationResourceBuilder method build.

@Override
public Animation build() {
    Texture spriteSheet = resourceManager.getResourceValue(spriteSheetId);
    Sprite[] frames = new Sprite[this.frames.size()];
    float[] times = new float[this.frames.size()];
    for (int i = 0; i < frames.length; i++) {
        Frame frame = this.frames.get(i);
        frames[i] = new Sprite(spriteSheet, frame.x, frame.y, frame.w, frame.h);
        // convert time from milliseconds to seconds
        times[i] = (float) frame.time * 0.001f;
    }
    return new Animation(frames, new FrameAnimationImpl(loop, times));
}
Also used : FrameAnimationImpl(com.gemserk.animation4j.FrameAnimationImpl) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Animation(com.gemserk.animation4j.gdx.Animation) Texture(com.badlogic.gdx.graphics.Texture)

Example 32 with Sprite

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

the class SpriteUtilsTest method shouldReturnIsAliasWhenSameRegion.

@Test
public void shouldReturnIsAliasWhenSameRegion() {
    TextureRegion region1 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    Sprite sprite1 = new Sprite(region1);
    Sprite sprite2 = new Sprite(region1);
    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 33 with Sprite

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

the class SpriteUtilsTest method shouldReturnIsAliasWhenSameSprite.

@Test
public void shouldReturnIsAliasWhenSameSprite() {
    TextureRegion region1 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    Sprite sprite1 = new Sprite(region1);
    assertTrue(SpriteUtils.isAliasSprite(sprite1, 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)

Example 34 with Sprite

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

the class SpriteUtilsTest method shouldReturnNotAliasWhenSpriteAndAtlasSprite.

@Test
public void shouldReturnNotAliasWhenSpriteAndAtlasSprite() {
    TextureRegion region1 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    Sprite sprite1 = new Sprite(region1);
    Sprite sprite2 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 40, 40));
    assertFalse(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) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Test(org.junit.Test)

Example 35 with Sprite

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

the class SpriteUtilsTest method shouldReturnNotAliasWhenRegionAreNotEqual.

@Test
public void shouldReturnNotAliasWhenRegionAreNotEqual() {
    TextureRegion region1 = new TextureRegion(texture512x512, 50, 30, 40f, 40f);
    TextureRegion region2 = new TextureRegion(texture512x512, 50, 30, 10f, 40f);
    Sprite sprite1 = new Sprite(region1);
    Sprite sprite2 = new Sprite(region2);
    assertFalse(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)

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