@Override public void setPosition (float x, float y) { super.setPosition(x + region.offsetX, y + region.offsetY); }
@Override public void setPosition (float x, float y) { super.setPosition(x + region.offsetX, y + region.offsetY); }
/** Sets the position where the sprite will be drawn, relative to its current origin. */ public void setOriginBasedPosition (float x, float y) { setPosition(x - this.originX, y - this.originY); }
/** Sets the position where the sprite will be drawn, relative to its current origin. */ public void setOriginBasedPosition (float x, float y) { setPosition(x - this.originX, y - this.originY); }
public void updateImageBackgroundPosSize (float x, float y, float width, float height) { if (bgImage != null) { bgImage.setPosition(x, y); bgImage.setSize(width, height); } } }
public void updateImageBackgroundPosSize (float x, float y, float width, float height) { if (bgImage != null) { bgImage.setPosition(x, y); bgImage.setSize(width, height); } } }
private void touch (int x, int y) { t = paths.get(currentPath).locate(tmpV.set(x, Gdx.graphics.getHeight() - y)); paths.get(currentPath).valueAt(tmpV, t); obj.setPosition(tmpV.x, tmpV.y); wait = 0.2f; }
badlogic.setPosition(50, 50); badlogicSmall.setPosition(10, 10); star.setPosition(10, 70);
@Override public void create () { batch = new SpriteBatch(); font = new BitmapFont(); stage = new Stage(new ScalingViewport(Scaling.fit, 24, 12)); regions = new TextureRegion[8 * 8]; sprites = new Sprite[24 * 12]; texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { regions[x + y * 8] = new TextureRegion(texture, x * 32, y * 32, 32, 32); } } Random rand = new Random(); for (int y = 0, i = 0; y < 12; y++) { for (int x = 0; x < 24; x++) { Image img = new Image(regions[rand.nextInt(8 * 8)]); img.setBounds(x, y, 1, 1); stage.addActor(img); sprites[i] = new Sprite(regions[rand.nextInt(8 * 8)]); sprites[i].setPosition(x, y); sprites[i].setSize(1, 1); i++; } } }
@Override public void create () { batch = new SpriteBatch(); sprites = new ArrayList<Sprite>(); Gdx2DPixmap[] pixmaps = testPixmaps(); Gdx2DPixmap composite = new Gdx2DPixmap(512, 256, Gdx2DPixmap.GDX2D_FORMAT_RGBA8888); composite.clear(0); composite.setBlend(Gdx2DPixmap.GDX2D_BLEND_NONE); for (int i = 0; i < pixmaps.length; i++) { composite.setScale(Gdx2DPixmap.GDX2D_SCALE_NEAREST); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 0, 64, 64); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 64, 16, 16); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 0, 64, 64); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 64, 16, 16); composite.setScale(Gdx2DPixmap.GDX2D_SCALE_LINEAR); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 100, 64, 64); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 164, 16, 16); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 100, 64, 64); composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 164, 16, 16); Sprite sprite = new Sprite(textureFromPixmap(pixmaps[i])); sprite.setPosition(10 + i * 32, 10); sprites.add(sprite); } Sprite sprite = new Sprite(textureFromPixmap(composite)); sprite.setPosition(10, 50); sprites.add(sprite); }
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); } }
else sprites3[i] = new Sprite(texture, 32, 32); sprites3[i].setPosition(x, y); sprites3[i].setOrigin(16, 16);
else sprites3[i] = new Sprite(texture, 32, 32); sprites3[i].setPosition(x, y); sprites3[i].setOrigin(16, 16);
obj.setPosition(tmpV.x, tmpV.y); obj2.setPosition(tmpV4.x, tmpV4.y);
@Override public void render () { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); texture.bind(0); shader.begin(); shader.setUniformMatrix("u_projView", matrix); shader.setUniformi("u_texture", 0); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); batch.begin(); batch.draw(atlas.findRegion("font"), 0, 100); sprite.rotate(Gdx.graphics.getDeltaTime() * 45); for (Vector2 position : positions) { sprite.setPosition(position.x, position.y); sprite.draw(batch); } font.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond() + ", delta: " + Gdx.graphics.getDeltaTime() + ", #sprites: " + numSprites, 0, 30); cache.setPosition(200, 200); cache.draw(batch); batch.end(); }
@Override public void create () { // a bitmap font to draw some text, note that we // pass true to the constructor, which flips glyphs on y font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true); // a texture region, note the flipping on y again region = new TextureRegion(new Texture("data/badlogic.jpg")); region.flip(false, true); // a texture atlas, note the boolean atlas = new TextureAtlas(Gdx.files.internal("data/pack"), true); // a sprite, created from a region in the atlas sprite = atlas.createSprite("badlogicsmall"); sprite.setPosition(0, 0); // a sprite batch with which we want to render batch = new SpriteBatch(); // a camera, note the setToOrtho call, which will set the y-axis // to point downwards camera = new OrthographicCamera(); camera.setToOrtho(true); // a stage which uses our y-down camera and a simple actor (see MyActor below), // which uses the flipped region. The key here is to // set our y-down camera on the stage, the rest is just for demo purposes. stage = new Stage(); stage.getViewport().setCamera(camera); image = new MyActor(region); image.setPosition(100, 100); stage.addActor(image); // finally we write up the stage as the input process and call it a day. Gdx.input.setInputProcessor(stage); }
@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); }
@Override public void render(SpriteBatch sb, Vector2 pos) { sprite.setPosition(pos.x, pos.y); sprite.draw(sb); }
@Override public void render(SpriteBatch sb, float x, float y) { sprite.setPosition(x, y); sprite.draw(sb); }
@Override public void addPos(float x, float y) { super.addPos(x, y); sprite.setPosition(sprite.getX() + x, sprite.getY() + y); }