use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite 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;
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite 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;
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite in project libgdx by libgdx.
the class Skin method getSprite.
/** Returns a registered sprite. If no sprite is found but a region exists with the name, a sprite is created from the region
* and stored in the skin. If the region is an {@link AtlasRegion} then an {@link AtlasSprite} is used if the region has been
* whitespace stripped or packed rotated 90 degrees. */
public Sprite getSprite(String name) {
Sprite sprite = optional(name, Sprite.class);
if (sprite != null)
return sprite;
try {
TextureRegion textureRegion = getRegion(name);
if (textureRegion instanceof AtlasRegion) {
AtlasRegion region = (AtlasRegion) textureRegion;
if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
sprite = new AtlasSprite(region);
}
if (sprite == null)
sprite = new Sprite(textureRegion);
add(name, sprite, Sprite.class);
return sprite;
} catch (GdxRuntimeException ex) {
throw new GdxRuntimeException("No NinePatch, TextureRegion, or Texture registered with name: " + name);
}
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite in project gdx-skineditor by cobolfoo.
the class Skin method newDrawable.
/**
* Returns a tinted copy of a drawable found in the skin via
* {@link #getDrawable(String)}.
*/
public Drawable newDrawable(Drawable drawable, Color tint) {
if (drawable instanceof TextureRegionDrawable) {
TextureRegion region = ((TextureRegionDrawable) drawable).getRegion();
Sprite sprite;
if (region instanceof AtlasRegion)
sprite = new AtlasSprite((AtlasRegion) region);
else
sprite = new Sprite(region);
sprite.setColor(tint);
return new SpriteDrawable(sprite);
}
if (drawable instanceof NinePatchDrawable) {
NinePatchDrawable patchDrawable = new NinePatchDrawable((NinePatchDrawable) drawable);
patchDrawable.setPatch(new NinePatch(patchDrawable.getPatch(), tint));
return patchDrawable;
}
if (drawable instanceof SpriteDrawable) {
SpriteDrawable spriteDrawable = new SpriteDrawable((SpriteDrawable) drawable);
Sprite sprite = spriteDrawable.getSprite();
if (sprite instanceof AtlasSprite)
sprite = new AtlasSprite((AtlasSprite) sprite);
else
sprite = new Sprite(sprite);
sprite.setColor(tint);
spriteDrawable.setSprite(sprite);
return spriteDrawable;
}
throw new GdxRuntimeException("Unable to copy, unknown drawable type: " + drawable.getClass());
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite in project commons-gdx by gemserk.
the class AnimationFromTextureAtlasResourceBuilder method build.
@Override
public Animation build() {
TextureAtlas textureAtlas = resourceManager.getResourceValue(textureAtlasId);
if (sprites == null) {
try {
sprites = textureAtlas.createSprites(prefix);
} catch (GdxRuntimeException e) {
throw new RuntimeException("Failed to create animation from texture atlas " + textureAtlasId, e);
}
}
if (endFrame == -1)
endFrame = sprites.size - 1;
if (startFrame == -1)
startFrame = 0;
Sprite[] frames = new Sprite[endFrame - startFrame + 1];
int frameNumber = startFrame;
for (int i = 0; i < frames.length; i++) {
Sprite sprite = sprites.get(frameNumber);
if (sprite instanceof AtlasSprite)
frames[i] = new AtlasSprite(((AtlasSprite) sprite).getAtlasRegion());
else
frames[i] = new Sprite(sprite);
frameTransformation.transform(frames[i]);
frameNumber++;
}
int framesCount = frames.length;
float[] newTimes = new float[framesCount - 1];
int lastTime = time;
for (int i = 0; i < framesCount - 1; i++) {
if (i < times.length) {
newTimes[i] = ((float) times[i]) * 0.001f;
lastTime = times[i];
} else
newTimes[i] = ((float) lastTime) * 0.001f;
}
FrameAnimationImpl frameAnimation = new FrameAnimationImpl(0.001f * (float) time, newTimes);
frameAnimation.setLoop(loop);
return new Animation(frames, frameAnimation);
}
Aggregations