/** Creates an uninitialized sprite. The sprite will need a texture region and bounds set before it can be drawn. */ public Sprite () { setColor(1, 1, 1, 1); }
/** Creates an uninitialized sprite. The sprite will need a texture region and bounds set before it can be drawn. */ public Sprite () { setColor(1, 1, 1, 1); }
/** Creates a sprite with width, height, and texture region equal to the specified size. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
/** Creates a sprite with width, height, and texture region equal to the specified size. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
/** Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture * region. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) { setRegion(region, srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
/** Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture * region. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) { setRegion(region, srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
public void draw (Batch batch, float x, float y, float width, float height) { Color spriteColor = sprite.getColor(); temp.set(spriteColor); sprite.setColor(spriteColor.mul(batch.getColor())); sprite.setRotation(0); sprite.setScale(1, 1); sprite.setBounds(x, y, width, height); sprite.draw(batch); sprite.setColor(temp); }
public void draw (Batch batch, float x, float y, float width, float height) { Color spriteColor = sprite.getColor(); temp.set(spriteColor); sprite.setColor(spriteColor.mul(batch.getColor())); sprite.setRotation(0); sprite.setScale(1, 1); sprite.setBounds(x, y, width, height); sprite.draw(batch); sprite.setColor(temp); }
public void draw (Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { Color spriteColor = sprite.getColor(); temp.set(spriteColor); sprite.setColor(spriteColor.mul(batch.getColor())); sprite.setOrigin(originX, originY); sprite.setRotation(rotation); sprite.setScale(scaleX, scaleY); sprite.setBounds(x, y, width, height); sprite.draw(batch); sprite.setColor(temp); }
public void draw (Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { Color spriteColor = sprite.getColor(); temp.set(spriteColor); sprite.setColor(spriteColor.mul(batch.getColor())); sprite.setOrigin(originX, originY); sprite.setRotation(rotation); sprite.setScale(scaleX, scaleY); sprite.setBounds(x, y, width, height); sprite.draw(batch); sprite.setColor(temp); }
/** Creates a sprite based on a specific TextureRegion, the new sprite's region is a copy of the parameter region - altering one * does not affect the other */ public Sprite (TextureRegion region) { setRegion(region); setColor(1, 1, 1, 1); setSize(region.getRegionWidth(), region.getRegionHeight()); setOrigin(width / 2, height / 2); }
/** Creates a sprite based on a specific TextureRegion, the new sprite's region is a copy of the parameter region - altering one * does not affect the other */ public Sprite (TextureRegion region) { setRegion(region); setColor(1, 1, 1, 1); setSize(region.getRegionWidth(), region.getRegionHeight()); setOrigin(width / 2, height / 2); }
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 6; return false; } }); spriteBatch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.setColor(1, 1, 1, 0.6f); logoSprite.setBounds(50, 100, 400, 100); font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle( "data/verdana39.png", FileType.Internal), false); cache = font.newFontCache(); layout = new GlyphLayout(); }
/** 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; } }
/** 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; } }
/** 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; } }
/** 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; } }
@Override public void render () { // clear the screen, update the camera and make the sprite batch // use its matrices. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); batch.setProjectionMatrix(camera.combined); // render all the things, we render in a y-down // cartesian coordinate system batch.begin(); // drawing a region, x and y will be the top left corner of the region, would be bottom left // with y-up. batch.draw(region, 20, 100); // drawing text, x and y will be the top left corner for text, same as with y-up font.draw(batch, "This is a test", 270, 100); // drawing regions from an atlas, x and y will be the top left corner. // you shouldn't call findRegion every frame, cache the result. batch.draw(atlas.findRegion("badlogicsmall"), 360, 100); // drawing a sprite created from an atlas, FIXME wut?! AtlasSprite#setPosition seems to be wrong sprite.setColor(Color.RED); sprite.draw(batch); // finally we draw our current touch/mouse coordinates font.draw(batch, Gdx.input.getX() + ", " + Gdx.input.getY(), 0, 0); batch.end(); // tell the stage to act and draw itself stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); }
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 4; return false; } }); spriteBatch = new SpriteBatch(); spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1)); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.flip(false, true); logoSprite.setPosition(0, 320 - 256); logoSprite.setColor(1, 1, 1, 0.5f); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), true); cache1 = font.newFontCache(); cache2 = font.newFontCache(); cache3 = font.newFontCache(); cache4 = font.newFontCache(); cache5 = font.newFontCache(); createCaches("cached", cache1, cache2, cache3, cache4, cache5); font.getData().setScale(1.33f); cacheScaled1 = font.newFontCache(); cacheScaled2 = font.newFontCache(); cacheScaled3 = font.newFontCache(); cacheScaled4 = font.newFontCache(); cacheScaled5 = font.newFontCache(); createCaches("cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5); }
/** Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture * region. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight) { setRegion(region, srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }