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);
}
}
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"));
}
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;
}
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;
}
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;
}
Aggregations