Example usage for com.badlogic.gdx.graphics.g2d Sprite getOriginY

List of usage examples for com.badlogic.gdx.graphics.g2d Sprite getOriginY

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d Sprite getOriginY.

Prototype

public float getOriginY() 

Source Link

Document

The origin influences #setPosition(float,float) , #setRotation(float) and the expansion direction of scaling #setScale(float,float)

Usage

From source file:aurelienribon.texturepackergui.Canvas.java

License:Apache License

@Override
public void render() {
    if (previousPageRequested) {
        previousPageRequested = false;//from   www  .  j  a  v  a  2s.com
        index = index - 1 < 0 ? sprites.size() - 1 : index - 1;
    }

    if (nextPageRequested) {
        nextPageRequested = false;
        index = index + 1 >= sprites.size() ? 0 : index + 1;
    }

    if (packReloadRequested) {
        packReloadRequested = false;
        index = 0;
        camera.position.set(0, 0, 0);
        camera.update();

        sprites.clear();
        if (atlas != null)
            atlas.dispose();

        if (packFile != null && packFile.exists()) {
            try {
                atlas = new TextureAtlas(packFile);
                List<Texture> textures = new ArrayList<Texture>();

                for (AtlasRegion region : atlas.getRegions()) {
                    if (!textures.contains(region.getTexture()))
                        textures.add(region.getTexture());
                }

                for (Texture tex : textures) {
                    Sprite sp = new Sprite(tex);
                    sp.setOrigin(sp.getWidth() / 2, sp.getHeight() / 2);
                    sp.setPosition(-sp.getOriginX(), -sp.getOriginY());
                    sprites.add(sp);
                }
            } catch (GdxRuntimeException ex) {
                atlas = null;
                sprites.clear();
                callback.atlasError();
            }
        }
    }

    // Render

    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    float tw = bgTex.getWidth();
    float th = bgTex.getHeight();

    batch.getProjectionMatrix().setToOrtho2D(0, 0, w, h);
    batch.begin();
    batch.disableBlending();
    batch.draw(bgTex, 0f, 0f, w, h, 0f, 0f, w / tw, h / th);
    batch.enableBlending();
    batch.end();

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    if (!sprites.isEmpty())
        sprites.get(index).draw(batch);
    batch.end();

    batch.getProjectionMatrix().setToOrtho2D(0, 0, w, h);
    batch.begin();
    font.setColor(Color.WHITE);
    lblNextPage.draw(batch);
    lblPreviousPage.draw(batch);
    infoLabel.draw(batch);
    if (sprites.isEmpty())
        font.draw(batch, "No page to show", 10, 65);
    else
        font.draw(batch, "Page " + (index + 1) + " / " + sprites.size(), 10, 65);
    font.draw(batch, String.format(Locale.US, "Zoom: %.0f %%", 100f / camera.zoom), 10, 45);
    font.draw(batch, "Fps: " + Gdx.graphics.getFramesPerSecond(), 10, 25);
    batch.end();
}

From source file:com.blindtigergames.werescrewed.graphics.particle.ParticleEmitter.java

License:Apache License

public void setSprite(Sprite sprite) {
    this.sprite = sprite;
    if (sprite == null)
        return;/*w  ww. j a va2 s.c  om*/
    float originX = sprite.getOriginX();
    float originY = sprite.getOriginY();
    Texture texture = sprite.getTexture();
    for (int i = 0, n = particles.length; i < n; i++) {
        Particle particle = particles[i];
        if (particle == null)
            break;
        particle.setTexture(texture);
        particle.setOrigin(originX, originY);
    }
}

From source file:seventh.client.gfx.PlayerSprite.java

License:Open Source License

public static void debugRenderSprite(Canvas canvas, Sprite sprite, int color) {
    //        canvas.drawSprite(sprite, sprite.getX(), sprite.getY(), 0x5f00aa00);                
    //        canvas.drawRect( (int)sprite.getX(), (int)sprite.getY(), sprite.getRegionWidth(), sprite.getRegionHeight(), 0x5fff0000);
    boolean drawDebug = false;
    if (drawDebug) {
        canvas.drawSprite(sprite, sprite.getX(), sprite.getY(), Colors.setAlpha(color, 0x5f));
        canvas.drawRect((int) sprite.getX(), (int) sprite.getY(), sprite.getRegionWidth(),
                sprite.getRegionHeight(), Colors.setAlpha(color, 0x5f));
        canvas.fillRect((int) (sprite.getX() + sprite.getOriginX()),
                (int) (sprite.getY() + sprite.getOriginY()), 5, 5, Colors.setAlpha(color, 0x5f));//0xff0000ff);
    }//from   ww w  .j a  va  2  s .c  om
}