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

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

Introduction

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

Prototype

public void draw(Batch batch) 

Source Link

Usage

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

License:Open Source License

@Override
public void render(float delta) {

    // clear the screen
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // simulate world
    update(delta);//from w  ww. j av a  2  s  .  com

    shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Filled);
    shapeRenderer.setColor(0, 0, 0.7f, 1); // dark blue background color
    //        shapeRenderer.rect(0, spriteSkyline.getY(), WINDOW_WIDTH, WINDOW_HEIGHT - spriteSkyline.getY());
    shapeRenderer.rect(0, spriteSkyline.getY(), WINDOW_WIDTH, WINDOW_HEIGHT - spriteSkyline.getY());
    shapeRenderer.end();

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    for (Sprite star : spritesStars) {
        star.draw(batch);
    }

    spriteSkyline.draw(batch);

    if (!state.equals(MenuState.ShowHighscores) && showLicenseYOffset == 0) {
        batch.draw(spriteTitle, spriteTitle.getX(), spriteTitle.getY(), 0, 0, spriteTitle.getWidth(),
                spriteTitle.getHeight(), Utils.oscilliate(elapsedTime, 0.9f, 1f, 3f),
                Utils.oscilliate(elapsedTime, 0.9f, 1f, -3f), Utils.oscilliate(elapsedTime, -2f, 2f, 3f));
    }
    batch.end();

    shapeRenderer.setProjectionMatrix(camera.combined);
    shapeRenderer.begin(ShapeType.Filled);
    shapeRenderer.setColor(Color.BLACK);
    shapeRenderer.rect(0, 0, WINDOW_WIDTH,
            state.equals(MenuState.ShowHighscores) ? WINDOW_HEIGHT - 70 : spriteSkyline.getY());

    //        if (state.equals(MenuState.ShowPromo)) {
    //            shapeRenderer.end();
    //            batch.begin();
    //            batch.draw(spriteBadge, 0, 0, (int) (646 / 2.1), (int) (250 / 2.1));
    //            font.setColor(Color.WHITE);
    //            font.draw(batch, Config.EMAIL, 300, 45);
    //            batch.draw(spriteTheRefactory, 310, 70, 180, 14);
    //            batch.end();
    //        } else {
    // buttons
    if (state.equals(MenuState.ShowAbout) || state.equals(MenuState.ShowHighscores)
            || state.equals(MenuState.ShowSettings)) {
        buttonExitToMainMenu.renderShape(shapeRenderer);
        switch (getState()) {
        case ShowHighscores:
            buttonUpdateHighscores.renderShape(shapeRenderer);
            break;
        case ShowSettings:
            buttonToggleSound.renderShape(shapeRenderer);
            buttonToggleMusic.renderShape(shapeRenderer);
            buttonChangePlayername.renderShape(shapeRenderer);
            buttonChangeLanguage.renderShape(shapeRenderer);
            buttonResetHighscore.renderShape(shapeRenderer);
            break;
        case ShowAbout:
            buttonShowLicense.renderShape(shapeRenderer);
            buttonSoundtrack.renderShape(shapeRenderer);
            buttonRate.renderShape(shapeRenderer);
            break;
        }
    } else {
        buttonStartSinglePlayerGame.renderShape(shapeRenderer);
        buttonShowHighscores.renderShape(shapeRenderer);
        buttonShowSettings.renderShape(shapeRenderer);
        buttonShowAbout.renderShape(shapeRenderer);
    }
    shapeRenderer.end();

    batch.begin();
    if (state.equals(MenuState.ShowAbout) || state.equals(MenuState.ShowHighscores)
            || state.equals(MenuState.ShowSettings)) {
        buttonExitToMainMenu.renderCaption(batch);
    }
    switch (getState()) {
    case ShowHighscores:
        buttonUpdateHighscores.setCaption(bundle.get(UPDATE));
        buttonUpdateHighscores.renderCaption(batch);
        if (fetchingHighscores) {
            font.setColor(Color.WHITE);
            font.draw(batch, bundle.get(FETCHING) + "...", 15, 205);
        } else {
            if (highscores != null) {

                // lines of highscores
                for (int i = 0; i < highscores.length; i++) {
                    font.setColor(i == getMyRank() ? Color.GREEN : Color.WHITE);
                    float yOfHighscoreLine = (205 - i * HIGHSCORES_LINE_HEIGHT + inputHandler.getDeltaY());
                    if (yOfHighscoreLine < spriteSkyline.getY() // lines disappear when above spriteSkyline sprite
                            && yOfHighscoreLine > 0) { // lines disappear when outside of the viewport
                        font.draw(batch, highscores[i], 15, yOfHighscoreLine);
                    }
                }

                // scrollbar
                if (highscores.length > 0) {
                    font.draw(batch, "^", WINDOW_WIDTH - 20, INITIAL_SCROLLBAR_POSITION_Y + 5);
                    font.draw(batch, "#", WINDOW_WIDTH - 20,
                            Math.min(INITIAL_SCROLLBAR_POSITION_Y, scrollbarPositionY));
                    font.getData().setScale(1, -1);
                    font.draw(batch, "^", WINDOW_WIDTH - 20, 10);
                    font.getData().setScale(1, 1);
                }
            }
        }
        break;
    case ShowSettings:
        // playername
        buttonChangePlayername.setCaption(
                prefs.getString(PrefsKeys.PLAYER_NAME).trim().length() == 0 ? "<" + bundle.get(PLAYERNAME) + ">"
                        : bundle.get(PLAYERNAME) + ": " + prefs.getString(PrefsKeys.PLAYER_NAME));
        buttonChangePlayername.renderCaption(batch);
        font.setColor(Color.WHITE);

        // sound
        buttonToggleSound.setCaption(bundle.get(SOUND) + " " + bundle.get(IS) + " "
                + (prefs.getBoolean(PrefsKeys.ENABLE_SOUND) ? bundle.get(ON) : bundle.get(OFF)));
        buttonToggleSound.renderCaption(batch);

        // music
        buttonToggleMusic.setCaption(bundle.get(MUSIC) + " " + bundle.get(IS) + " "
                + (prefs.getBoolean(PrefsKeys.ENABLE_MUSIC) ? bundle.get(ON) : bundle.get(OFF)));
        buttonToggleMusic.renderCaption(batch);

        // language
        buttonChangeLanguage.renderCaption(batch);

        // reset highscore
        buttonResetHighscore.setCaption(bundle.get(RESET_HIGHSCORE));
        buttonResetHighscore.renderCaption(batch);
        break;
    case ShowAbout:
        font.setColor(Color.WHITE);
        font.draw(batch, aboutText, 15, 100 + showLicenseYOffset);
        if (showLicenseYOffset > 0) {
            font.draw(batch, bundle.get(LICENSE_TEXT), 15, showLicenseYOffset + 2);
        }
        batch.draw(spriteThere, 145, showLicenseYOffset + 19, spriteThere.getWidth() / 3,
                spriteThere.getHeight() / 3);
        batch.draw(spriteFactory, 200, showLicenseYOffset + 19, spriteFactory.getWidth() / 3,
                spriteFactory.getHeight() / 3);
        buttonShowLicense.setCaption(bundle.get(LICENSE));
        buttonShowLicense.renderCaption(batch);
        buttonSoundtrack.setCaption(bundle.get(SOUNDTRACK));
        buttonSoundtrack.renderCaption(batch);
        buttonRate.setCaption(bundle.get(RATE));
        buttonRate.renderCaption(batch);
        Utils.oscilliate(batch, spriteDownload, buttonSoundtrack.getX() + buttonSoundtrack.getWidth() - 20,
                buttonSoundtrack.getY() - 10, spriteDownload.getWidth() / 2f, spriteDownload.getHeight() / 2f,
                elapsedTime);
        Utils.oscilliate(batch, spriteStar, buttonRate.getX() + buttonRate.getWidth() - 20,
                buttonRate.getY() - 10, spriteStar.getWidth() / 2f, spriteStar.getHeight() / 2f, elapsedTime);
        break;
    default:
        // buttons' icons
        spritePlayer.draw(batch);
        spriteRedPlayer.draw(batch);
        spriteBluePlayer.draw(batch);
        spritePearl.draw(batch);
        spriteSoldier.draw(batch);
        spriteSettings.draw(batch);

        // buttons themselves
        buttonStartSinglePlayerGame.setCaption(bundle.get(SINGLEPLAYER));
        buttonShowHighscores.setCaption(bundle.get(HIGHSCORES));
        buttonShowSettings.setCaption(bundle.get(SETTINGS));
        buttonShowAbout.setCaption(bundle.get(ABOUT));
        buttonStartSinglePlayerGame.renderCaption(batch);
        buttonShowHighscores.renderCaption(batch);
        buttonShowSettings.renderCaption(batch);
        buttonShowAbout.renderCaption(batch);
        break;
    }
    batch.end();
    //        }
}

From source file:br.cefetmg.games.minigames.CollectItens.java

@Override
public void onDrawGame() {

    this.fundo.draw(this.screen.batch);

    for (int i = 0; i < characters.size; i++) {
        Sprite sprite = characters.get(i);
        sprite.draw(this.screen.batch);
    }//w w w.  j av a  2  s .co m
    boca.draw(this.screen.batch);
}

From source file:br.cefetmg.games.minigames.EscoveOsDentes.java

@Override
public void onDrawGame() {
    fundo2.draw(this.screen.batch);
    for (int i = 0; i < Tooths.size; i++) {
        Sprite sprite = Tooths.get(i);
        sprite.draw(this.screen.batch);
    }//from w  w  w.  ja v  a  2  s. co m
    escova.draw(this.screen.batch);
}

From source file:br.cefetmg.games.minigames.Gallows.java

@Override
public void onDrawGame() {
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    //desenha dente
    super.screen.batch.draw(gallowFrame.getKeyFrame(tentativas), 10.0f, 300.0f);

    //Desenha letras
    for (int i = 0; i < letters.size; i++) {
        Sprite sprite = letters.get(i).getSprite();
        sprite.draw(this.screen.batch);
    }// w  w w  . ja v a  2  s .  c o m
    //Desenha letras acertadas
    for (int i = 0; i < letrasCertas.size; i++) {
        Sprite sprite = letrasCertas.get(i);
        sprite.draw(this.screen.batch);
    }

    //desenha traos
    for (int i = 0; i < word.length(); i++) {
        if (word.charAt(i) == ' ') {
            tracoBranco.setPosition(190 + i * 100, 300.0f);
            tracoBranco.draw(super.screen.batch);
        } else {
            traco.setPosition(190 + i * 100, 300.0f);
            traco.draw(super.screen.batch);
        }
    }

    //desenha mouse
    mousePointer.draw(super.screen.batch);
}

From source file:br.cefetmg.games.minigames.OrientacaoSnake.java

@Override
public void onDrawGame() {
    fundo.draw(this.screen.batch);
    setaTop.draw(this.screen.batch);
    setaLeft.draw(this.screen.batch);
    setaRight.draw(this.screen.batch);
    setaDown.draw(this.screen.batch);
    for (int i = 0; i < enemies.size; i++) {
        Sprite sprite = enemies.get(i);
        sprite.draw(this.screen.batch);
    }/*  w  w w  .ja v a 2  s.c om*/
    snake.draw(this.screen.batch);
}

From source file:CB_Locator.Map.MapViewBase.java

License:Open Source License

protected void renderPositionMarker(Batch batch) {
    PointD point = Descriptor.ToWorld(
            Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, Locator.getLongitude()),
            Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, Locator.getLatitude()),
            MapTileLoader.MAX_MAP_ZOOM, MapTileLoader.MAX_MAP_ZOOM);

    Vector2 vPoint = new Vector2((float) point.X, -(float) point.Y);

    myPointOnScreen = worldToScreen(vPoint);

    myPointOnScreen.y -= ySpeedVersatz;/*w w  w.j a  va  2 s  .  c o m*/

    if (showAccuracyCircle) {

        if (accuracyDrawable == null) {
            accuracyDrawable = new AccuracyDrawable(this.mapIntWidth, this.mapIntWidth);
        }

        float radius = (pixelsPerMeter * Locator.getCoordinate().getAccuracy());

        if (radius > GL_UISizes.PosMarkerSize / 2) {
            accuracyDrawable.draw(batch, myPointOnScreen.x, myPointOnScreen.y, radius);
        }
    }

    boolean lastUsedCompass = Locator.UseMagneticCompass();
    boolean Transparency = LocatorSettings.PositionMarkerTransparent.getValue();

    int arrowId = 0;
    if (lastUsedCompass) {
        arrowId = Transparency ? 1 : 0;
    } else {
        arrowId = Transparency ? 3 : 2;
    }

    if (CarMode)
        arrowId = 15;

    Sprite arrow = Sprites.Arrows.get(arrowId);
    arrow.setRotation(-arrowHeading);
    arrow.setBounds(myPointOnScreen.x - GL_UISizes.halfPosMarkerSize,
            myPointOnScreen.y - GL_UISizes.halfPosMarkerSize, GL_UISizes.PosMarkerSize,
            GL_UISizes.PosMarkerSize);
    arrow.setOrigin(GL_UISizes.halfPosMarkerSize, GL_UISizes.halfPosMarkerSize);
    arrow.draw(batch);

}

From source file:CB_UI.GL_UI.Controls.ArrowView.java

License:Open Source License

@Override
public void render(Batch batch) {

    Sprite arrow = Sprites.Arrows.get(0);
    arrow.setRotation(0);//  ww  w . j a  va2  s .  c om
    arrow.setBounds(-(getWidth() / 2), 0, getWidth(), getHeight());
    arrow.setOrigin(this.getCenterPosX(), this.getCenterPosY());
    arrow.draw(batch);

}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

private void RenderTargetArrow(Batch batch) {

    if (GlobalCore.getSelectedCache() == null)
        return;//from  ww  w. j  ava2 s  .  co  m

    Coordinate coord = (GlobalCore.getSelectedWaypoint() != null) ? GlobalCore.getSelectedWaypoint().Pos
            : GlobalCore.getSelectedCache().Pos;

    if (coord == null) {
        return;
    }
    float x = (float) (256.0 * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, coord.getLongitude()));
    float y = (float) (-256.0 * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, coord.getLatitude()));

    float halfHeight = (mapIntHeight / 2) - ySpeedVersatz;
    float halfWidth = mapIntWidth / 2;

    // create ScreenRec
    try {
        if (TargetArrowScreenRec == null) {
            TargetArrowScreenRec = new CB_RectF(0, 0, mapIntWidth, mapIntHeight);
            if (Mode != MapMode.Compass) {
                TargetArrowScreenRec.ScaleCenter(0.9f);

                if (Mode == MapMode.Normal) {
                    TargetArrowScreenRec.setHeight(TargetArrowScreenRec.getHeight()
                            - (TargetArrowScreenRec.getHeight() - info.getY()) - zoomBtn.getHeight());
                    TargetArrowScreenRec.setY(zoomBtn.getMaxY());
                }
            }
        }

        Vector2 ScreenCenter = new Vector2(halfWidth, halfHeight);

        Vector2 screen = worldToScreen(new Vector2(x, y));
        Vector2 target = new Vector2(screen.x, screen.y);

        Vector2 newTarget = TargetArrowScreenRec.getIntersection(ScreenCenter, target);

        // Rotation berechnen
        if (newTarget != null) {

            float direction = get_angle(ScreenCenter.x, ScreenCenter.y, newTarget.x, newTarget.y);
            direction = 180 - direction;

            // draw sprite
            Sprite arrow = Sprites.Arrows.get(4);
            arrow.setRotation(direction);

            float boundsX = newTarget.x - GL_UISizes.TargetArrow.halfWidth;
            float boundsY = newTarget.y - GL_UISizes.TargetArrow.height;

            arrow.setBounds(boundsX, boundsY, GL_UISizes.TargetArrow.width, GL_UISizes.TargetArrow.height);

            arrow.setOrigin(GL_UISizes.TargetArrow.halfWidth, GL_UISizes.TargetArrow.height);
            arrow.draw(batch);

            // get real bounding box of TargetArrow
            float t[] = arrow.getVertices();
            float maxX = Math.max(Math.max(t[0], t[5]), Math.max(t[10], t[15]));
            float minX = Math.min(Math.min(t[0], t[5]), Math.min(t[10], t[15]));
            float maxY = Math.max(Math.max(t[1], t[6]), Math.max(t[11], t[16]));
            float minY = Math.min(Math.min(t[1], t[6]), Math.min(t[11], t[16]));
            TargetArrow.set(minX, minY, maxX - minX, maxY - minY);
        } else {
            TargetArrow.set(0, 0, 0, 0);
        }
    } catch (Exception e) {
        TargetArrow.set(0, 0, 0, 0);
    }
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

public void renderWPI(Batch batch, SizeF WpUnderlay, SizeF WpSize, WaypointRenderInfo wpi) {
    Vector2 screen = worldToScreen(new Vector2(wpi.MapX, wpi.MapY));

    screen.y -= ySpeedVersatz;/*from w  w w. j ava 2s . c  o m*/
    // FIXME create a LineDrawable class for create one times and set the Coordinates with calculated Triangles
    if (myPointOnScreen != null && showDirectLine && (wpi.Selected)
            && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) {
        // FIXME render only if visible on screen (intersect the screen rec)
        Quadrangle line = new Quadrangle(myPointOnScreen.x, myPointOnScreen.y, screen.x, screen.y,
                3 * UI_Size_Base.that.getScale());
        if (paint == null) {
            paint = new GL_Paint();
            paint.setGLColor(Color.RED);
        }
        PolygonDrawable po = new PolygonDrawable(line.getVertices(), line.getTriangles(), paint,
                this.mapIntWidth, this.mapIntHeight);
        po.draw(batch, 0, 0, this.mapIntWidth, this.mapIntHeight, 0);
        po.dispose();
    }
    // Don't render if outside of screen !!
    if ((screen.x < 0 - WpSize.width || screen.x > this.getWidth() + WpSize.height)
            || (screen.y < 0 - WpSize.height || screen.y > this.getHeight() + WpSize.height)) {
        if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) {
            // check if wp selected
            if (wpi.Waypoint != null && wpi.Waypoint.equals(infoBubble.getWaypoint())
                    || wpi.Waypoint == null && infoBubble.getWaypoint() == null)
                infoBubble.setInvisible();
        }
        return;
    }

    float NameYMovement = 0;

    if ((aktZoom >= zoomCross) && (wpi.Selected) && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) {
        // Draw Cross and move screen vector
        Sprite cross = Sprites.MapOverlay.get(3);
        cross.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight, WpUnderlay.width,
                WpUnderlay.height);
        cross.draw(batch);

        screen.add(-WpUnderlay.width, WpUnderlay.height);
        NameYMovement = WpUnderlay.height;
    }

    if (wpi.UnderlayIcon != null) {
        wpi.UnderlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight,
                WpUnderlay.width, WpUnderlay.height);
        wpi.UnderlayIcon.draw(batch);
    }
    if (wpi.Icon != null) {
        wpi.Icon.setBounds(screen.x - WpSize.halfWidth, screen.y - WpSize.halfHeight, WpSize.width,
                WpSize.height);
        wpi.Icon.draw(batch);
    }

    // draw Favorite symbol
    if (wpi.Cache != null && wpi.Cache.isFavorite()) {
        batch.draw(Sprites.getSprite(IconName.favorit.name()), screen.x + (WpSize.halfWidth / 2),
                screen.y + (WpSize.halfHeight / 2), WpSize.width, WpSize.height);
    }

    if (wpi.OverlayIcon != null) {
        wpi.OverlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight,
                WpUnderlay.width, WpUnderlay.height);
        wpi.OverlayIcon.draw(batch);
    }

    boolean drawAsWaypoint = wpi.Waypoint != null;

    // Rating des Caches darstellen
    if (wpi.Cache != null && showRating && (!drawAsWaypoint) && (wpi.Cache.Rating > 0) && (aktZoom >= 15)) {
        Sprite rating = Sprites.MapStars.get((int) Math.min(wpi.Cache.Rating * 2, 5 * 2));
        rating.setBounds(screen.x - WpUnderlay.halfWidth,
                screen.y - WpUnderlay.halfHeight - WpUnderlay.Height4_8, WpUnderlay.width,
                WpUnderlay.Height4_8);
        rating.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        rating.setRotation(0);
        rating.draw(batch);
        NameYMovement += WpUnderlay.Height4_8;
    }

    // Beschriftung
    if (wpi.Cache != null && showTitles && (aktZoom >= 15)) {
        try {
            String Name = drawAsWaypoint ? wpi.Waypoint.getTitle() : wpi.Cache.getName();

            if (layout == null)
                layout = new GlyphLayout(Fonts.getNormal(), Name);
            else
                layout.setText(Fonts.getNormal(), Name);

            float halfWidth = layout.width / 2;
            Fonts.getNormal().draw(batch, layout, screen.x - halfWidth,
                    screen.y - WpUnderlay.halfHeight - NameYMovement);
        } catch (Exception e) {
        }
    }

    // Show D/T-Rating
    if (wpi.Cache != null && showDT && (!drawAsWaypoint) && (aktZoom >= 15)) {
        Sprite difficulty = Sprites.MapStars.get((int) Math.min(wpi.Cache.getDifficulty() * 2, 5 * 2));
        difficulty.setBounds(screen.x - WpUnderlay.width - GL_UISizes.infoShadowHeight,
                screen.y - (WpUnderlay.Height4_8 / 2), WpUnderlay.width, WpUnderlay.Height4_8);
        difficulty.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        difficulty.setRotation(90);
        difficulty.draw(batch);

        Sprite terrain = Sprites.MapStars.get((int) Math.min(wpi.Cache.getTerrain() * 2, 5 * 2));
        terrain.setBounds(screen.x + GL_UISizes.infoShadowHeight, screen.y - (WpUnderlay.Height4_8 / 2),
                WpUnderlay.width, WpUnderlay.Height4_8);
        terrain.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        terrain.setRotation(90);
        terrain.draw(batch);

    }

    if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) {
        if (infoBubble.getWaypoint() == wpi.Waypoint) {
            Vector2 pos = new Vector2(screen.x - infoBubble.getHalfWidth(), screen.y);
            infoBubble.setPos(pos);
        }
    }
}

From source file:CB_UI_Base.GL_UI.Controls.GestureHelp.java

License:Open Source License

@Override
protected void render(Batch batch) {

    Sprite sprite = Sprites.Bubble.get(UseLastBtnBackground ? 4 : 3);
    sprite.setPosition(0, 0);//from   w  w  w  .j a va2s  .co m
    sprite.setSize(getWidth(), getHeight());
    sprite.draw(batch);
    super.render(batch);
}