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

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

Introduction

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

Prototype

public void draw(TextureRegion region, float x, float y, float width, float height);

Source Link

Document

Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.

Usage

From source file:MyGdxGame.java

License:Apache License

private void renderKoala(float deltaTime) {
    // based on the koala state, get the animation frame
    TextureRegion frame = null;/*from   w ww .ja v  a 2 s. co  m*/
    switch (koala.state) {
    case Standing:
        frame = stand.getKeyFrame(koala.stateTime);
        break;
    case Walking:
        frame = walk.getKeyFrame(koala.stateTime);
        break;
    case Jumping:
        frame = jump.getKeyFrame(koala.stateTime);
        break;
    }

    // draw the koala, depending on the current velocity
    // on the x-axis, draw the koala facing either right
    // or left
    Batch batch = renderer.getBatch();
    batch.begin();
    if (koala.facesRight) {
        batch.draw(frame, koala.position.x, koala.position.y, Koala.WIDTH, Koala.HEIGHT);
    } else {
        batch.draw(frame, koala.position.x + Koala.WIDTH, koala.position.y, -Koala.WIDTH, Koala.HEIGHT);
    }
    batch.end();
}

From source file:CB_Locator.Map.TileGL_Bmp.java

License:Open Source License

@Override
public void draw(Batch batch, float x, float y, float width, float height,
        CB_List<TileGL_RotateDrawables> rotateList) {
    if (texture != null)
        batch.draw(texture, x, y, width, height);
}

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  a  v a 2  s .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.graphics.Images.BitmapDrawable.java

License:Open Source License

public void draw(Batch batch, float x, float y, float width, float height) {
    if (Atlas == null)
        return;/*from ww  w.  j  a va 2s  .  c  o  m*/
    if (sprite == null) {
        createSprite();
    }
    if (sprite != null)
        batch.draw(sprite, x, y, width, height);
}

From source file:CB_UI_Base.graphics.Images.VectorDrawable.java

License:Open Source License

private void drawFbo(Batch batch, float x, float y, final float width, final float height,
        final Matrix4 oriMatrix, Matrix4 thisDrawMatrix) {
    final int fboScalerWidth = (int) (this.DEFAULT_WIDTH * FBO_SCALER);
    final int fboScalerHeight = (int) (this.DEFAULT_HEIGHT * FBO_SCALER);
    if (!RunOnGlSetted && m_fboEnabled && m_fboRegion == null) {
        RunOnGlSetted = true;/*  ww  w  .  ja v a  2  s . c o m*/

        GL.that.RunOnGL(new IRenderFBO() {

            @Override
            public void run() {
                synchronized (isDisposed) {

                    if (isDisposed.get()) {
                        return;
                    }

                    try {
                        Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);

                        long start = System.currentTimeMillis();

                        m_fbo = new FrameBuffer(Format.RGBA8888, fboScalerWidth, fboScalerHeight, false);
                        m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
                        m_fboRegion.flip(flipX, flipY);

                        m_fbo.begin();

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

                        GL.batch.setColor(new Color(Color.WHITE));

                        GL.batch.begin();

                        Matrix4 matrix = new Matrix4().setToOrtho2D(0, 0, width, height);
                        matrix.scale(FBO_SCALER, FBO_SCALER, 1);
                        GL.batch.setProjectionMatrix(matrix);

                        // draw Background
                        GL.batch.disableBlending();
                        background.draw(GL.batch, 0, 0, fboScalerWidth, fboScalerHeight);
                        GL.batch.enableBlending();
                        int count = 0;

                        for (int i = 0, n = drawableList.size(); i < n; i++) {
                            MatrixDrawable drw = drawableList.get(i);
                            if (count++ > 2500) {
                                GL.batch.flush();
                                count = 0;
                            }
                            matrix = new Matrix4().setToOrtho2D(0, 0, width, height);
                            if (drw.matrix != null) {

                                matrix.mul(drw.matrix.getMatrix4());
                            }

                            GL.batch.setProjectionMatrix(matrix);
                            drw.drawable.draw(GL.batch, 0, 0, width, height, 0);
                        }

                        if (m_fbo != null) {
                            GL.batch.end();
                            m_fbo.end();
                            m_fboEnabled = false;
                        }

                        FBOisDrawed = true;
                        FBO_DrawingTime = System.currentTimeMillis() - start;
                        Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
                        GL.batch.setProjectionMatrix(oriMatrix);

                        m_fboEnabled = false;
                    } catch (Exception e) {
                        e.printStackTrace();

                    }
                }
            }

        });

    }

    if (m_fboRegion != null) {

        // TODO clear and release the drawables that drawed on m_fboRegion
        // if first drawing of m_fboRegion

        batch.draw(m_fboRegion, x, y, width, height);
    } else {

        int count = 0;

        for (int i = 0, n = drawableList.size(); i < n; i++) {
            MatrixDrawable drw = drawableList.get(i);
            if (!drw.reaelDraw)
                continue;
            if (count++ > 2500) {
                GL.batch.flush();
                count = 0;
            }
            Matrix4 matrix = thisDrawMatrix.cpy();
            if (drw.matrix != null)
                matrix.mul(drw.matrix.getMatrix4());

            GL.batch.setProjectionMatrix(matrix);

            drw.drawable.draw(GL.batch, 0, 0, width, height, 0);
        }

    }
}

From source file:com.adidesi95.nodechess.model.pieces.Piece.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    batch.draw(this.textureRegion, this.getX(), this.getY(), 1, 1);
}

From source file:com.agateau.pixelwheels.bonus.Missile.java

License:Open Source License

private void drawTarget(Batch batch) {
    if (mTarget == null) {
        return;/*from   w  ww  .j  av a  2 s .  c  om*/
    }
    batch.setColor(mStatus == Status.LOCKED ? LOCKED_COLOR : TARGETED_COLOR);
    TextureRegion region = mAssets.target;
    float w = Constants.UNIT_FOR_PIXEL * region.getRegionWidth();
    float h = Constants.UNIT_FOR_PIXEL * region.getRegionHeight();
    batch.draw(region, mTarget.getX() - w / 2, mTarget.getY() - h / 2, w, h);
    batch.setColor(Color.WHITE);
}

From source file:com.agateau.pixelwheels.gameobjet.AnimationObject.java

License:Open Source License

@Override
public void draw(Batch batch, ZLevel zLevel) {
    if (mTime < 0) {
        return;/*from   w ww .j a va 2  s . c  o m*/
    }
    if (zLevel == ZLevel.OBSTACLES) {
        TextureRegion region = mAnimation.getKeyFrame(mTime);
        float w = Constants.UNIT_FOR_PIXEL * region.getRegionWidth();
        float h = Constants.UNIT_FOR_PIXEL * region.getRegionHeight();
        batch.draw(region, mPosX - w / 2, mPosY - h / 2, w, h);
    }
}

From source file:com.agateau.pixelwheels.racescreen.HudButton.java

License:Open Source License

@Override
public void draw(Batch batch, float alpha) {
    Color color = batch.getColor();
    float oldA = color.a;
    color.a = alpha * (mEnabled ? HudButton.BUTTON_OPACITY : HudButton.DISABLED_BUTTON_OPACITY);
    batch.setColor(color);/*from w  w w.  j  a v  a2s  . co m*/

    batch.draw(mRegions[isPressed() ? 1 : 0], MathUtils.round(getX()), MathUtils.round(getY()), getWidth(),
            getHeight());

    color.a = oldA;
    batch.setColor(color);
}

From source file:com.amerticum.chosenchess.model.Cazz.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    if (this.estActif) {
        batch.draw(this.textureCazzActif, this.getX(), this.getY(), 1, 1);
    } else {/*  w w w  .  ja va 2 s .  c o  m*/
        batch.draw(this.textureCazzPassif, this.getX(), this.getY(), 1, 1);
    }
}