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

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

Introduction

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

Prototype

public float getHeight() 

Source Link

Usage

From source file:at.juggle.games.counting.CountingGameModel.java

License:Apache License

public InputResult handleTouch(Vector3 p) {
    Vector2 t = new Vector2(p.x, p.y);
    layout.setText(buttonFont, Integer.toString(numberOfSprites));

    if (goodBallons.length < 1)
        return InputResult.Change;
    if (t.y < posButtonsY + layout.height && !answerIsGiven) { // it's a button press
        // check for the answers:
        for (int i = 0; i < answers.length; i++) {
            String answer = Integer.toString(answers[i]);
            layout.setText(buttonFont, answer);
            float posX = CountingGame.GAME_WIDTH / 4 * (i + 1) - layout.width / 2;
            if (Math.abs(posX - t.x) < layout.width) { // got it!
                if (answers[i] == numberOfSprites)
                    answerIsGiven = true;
            }//  www  .ja  v a  2 s  .  c o  m
        }
        return answerIsGiven ? InputResult.Button : InputResult.Nothing;
    } else if (answerIsGiven) { // check for the balloons ...
        int toRemove = -1;
        float dist = Float.MAX_VALUE;
        for (int i = 0; i < goodBallons.length; i++) {
            Sprite sp = goodBallons[i];
            Vector2 s = new Vector2(sp.getX() + sp.getWidth() / 2, sp.getY() + sp.getHeight() / 2);

            // take the nearest one to remove ...
            if (t.dst(s) < Math.min(goodBallons[i].getWidth(), dist)) { // it's a collision
                toRemove = i;
                dist = t.dst(s);
            }
        }
        if (toRemove > -1) {
            Balloon[] temp = new Balloon[goodBallons.length - 1];
            int count = 0;
            for (int i = 0; i < goodBallons.length; i++) {
                if (i != toRemove)
                    temp[count++] = goodBallons[i];
            }
            goodBallons = temp;
            dirty = true;
            return InputResult.Pop;
        }
    } else {
        return InputResult.Nothing;
    }
    return InputResult.Nothing;
}

From source file:at.juggle.games.counting.SortingGameModel.java

License:Apache License

public InputResult handleTouch(Vector3 p) {
    Vector2 t = new Vector2(p.x, p.y);
    layout.setText(buttonFont, Integer.toString(numberOfSprites));

    if (goodBallons.length < 1)
        return InputResult.Change;
    if (true) { // check for the balloons ...
        int toRemove = -1;
        float dist = Float.MAX_VALUE;
        for (int i = 0; i < goodBallons.length; i++) {
            Sprite sp = goodBallons[i];
            Vector2 s = new Vector2(sp.getX() + sp.getWidth() / 2, sp.getY() + sp.getHeight() / 2);

            // take the nearest one to remove ...
            if (t.dst(s) < Math.min(goodBallons[i].getWidth(), dist)) { // it's a collision
                if (currentAnswer == goodBallons[i].getNumber()) {
                    toRemove = i;// w  w w.  j a va  2s.c o m
                    dist = t.dst(s);
                    currentAnswer++;
                }
            }
        }
        if (toRemove > -1) {
            Balloon[] temp = new Balloon[goodBallons.length - 1];
            int count = 0;
            for (int i = 0; i < goodBallons.length; i++) {
                if (i != toRemove)
                    temp[count++] = goodBallons[i];
            }
            goodBallons = temp;
            dirty = true;
            return InputResult.Pop;
        }
    } else {
        return InputResult.Nothing;
    }
    return InputResult.Nothing;
}

From source file:at.therefactory.jewelthief.Game.java

License:Open Source License

/**
 * Checks and rectifies the positions of enemies if they are outside of the enemy field.
 *//*from  w w  w  .j  a v a 2  s .com*/
public void rearrangeEnemies() {
    for (Enemy enemy : enemies) {
        Sprite sprite = enemy.getSprite();
        if (sprite.getBoundingRectangle().x < rectangleEnemyField.x) {
            enemy.setPosition(rectangleEnemyField.x + sprite.getWidth() / 2, enemy.getPosition().y);
        }
        if (sprite.getBoundingRectangle().x > rectangleEnemyField.x + rectangleEnemyField.width) {
            enemy.setPosition(rectangleEnemyField.x + rectangleEnemyField.width - sprite.getWidth() / 2,
                    enemy.getPosition().y);
        }
        if (sprite.getBoundingRectangle().y < rectangleEnemyField.y) {
            enemy.setPosition(enemy.getPosition().x, enemy.getPosition().y + sprite.getHeight() / 2);
        }
        if (sprite.getBoundingRectangle().y > rectangleEnemyField.y + rectangleEnemyField.height) {
            enemy.setPosition(enemy.getPosition().x,
                    rectangleEnemyField.y + rectangleEnemyField.height - sprite.getHeight() / 2);
        }
        enemy.update();
    }
}

From source file:at.therefactory.jewelthief.misc.Utils.java

License:Open Source License

/**
 * Returns true if the given vector is enclosed by the sprite's area.
 *
 * @param vec3/*from  www .  j a  va2  s .  c  o  m*/
 * @param sprite
 * @return
 */
public static boolean within(Vector3 vec3, Sprite sprite) {
    return within(vec3.x, sprite.getX(), sprite.getX() + sprite.getWidth())
            && within(vec3.y, sprite.getY(), sprite.getY() + sprite.getHeight());
}

From source file:at.therefactory.jewelthief.misc.Utils.java

License:Open Source License

public static void oscilliate(SpriteBatch batch, Sprite sprite, float elapsedTime) {
    oscilliate(batch, sprite, sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight(), elapsedTime);
}

From source file:at.therefactory.jewelthief.screens.MenuScreen.java

License:Open Source License

private void initStars() {
    spritesStars = new Sprite[MENU_SCREEN_NUM_STARS];
    starSpeeds = new float[MENU_SCREEN_NUM_STARS];
    for (int i = 0; i < MENU_SCREEN_NUM_STARS; i++) {
        Sprite star = JewelThief.getInstance().getTextureAtlas().createSprite("star");
        star.setPosition(//w  w  w  .  j a  va 2s  .  c o m
                Utils.randomWithin(borderSize + star.getWidth(), WINDOW_WIDTH - borderSize - star.getWidth()),
                Utils.randomWithin(borderSize, WINDOW_HEIGHT - star.getHeight()));
        spritesStars[i] = star;
        starSpeeds[i] = Utils.randomWithin(.01f, .2f);
    }
}

From source file:at.therefactory.jewelthief.screens.MenuScreen.java

License:Open Source License

private void update(float delta) {
    elapsedTime += delta;/*from  ww  w  . j  av  a 2  s  .  c o  m*/
    inputHandler.update(delta);

    // move spritesStars
    for (int i = 0; i < spritesStars.length; i++) {
        Sprite star = spritesStars[i];
        if (star.getY() < borderSize) {
            star.setY(WINDOW_HEIGHT - star.getHeight());
        } else {
            star.setY(star.getY() - starSpeeds[i]);
        }
    }
}

From source file:at.therefactory.jewelthief.screens.MenuScreen.java

License:Open Source License

public void handleTouchOnStars(Vector3 touchCoordinates) {
    if (touchCoordinates.y > spriteSkyline.getY()) {
        for (Sprite star : spritesStars) {
            if (Utils.within(touchCoordinates.x, star.getX(), star.getX() + star.getWidth())
                    && Utils.within(touchCoordinates.y, star.getY(), star.getY() + star.getHeight())) {
                JewelThief.getInstance().playCymbalSound();
                star.setPosition(star.getX(), WINDOW_HEIGHT + star.getHeight() * 3);
            }//from  w ww.  ja v a 2  s  . co  m
        }
    }
}

From source file:aurelienribon.texturepackergui.Canvas.java

License:Apache License

@Override
public void render() {
    if (previousPageRequested) {
        previousPageRequested = false;//from w  w w .  j  a  v a 2 s  . c o m
        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:CB_UI_Base.GL_UI.Controls.Animation.RotateAnimation.java

License:Open Source License

public void setSprite(Sprite sprite) {
    mSpriteWidth = sprite.getWidth();//from   w  ww  .  j  a v  a  2s  .  co  m
    mSpriteHeight = sprite.getHeight();
    mDrawable = sprite;// new SpriteDrawable(sprite);
}