Java Code Examples for com.badlogic.gdx.graphics.g2d.Batch#draw()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Batch#draw() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimationSubView.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    if (regions.size <= 0)
        return;
    GdxHelper.setBatchColor(batch, getColor(), parentAlpha);
    TextureRegion region = animation.getKeyFrame(stateTime);
    float rotation = getRotation();
    if (rotation != 0) {
        batch.draw(
            region,
            getX(),
            getY(),
            getOriginX(),
            getOriginY(),
            region.getRegionWidth(),
            region.getRegionHeight(),
            1,
            1,
            rotation
        );
    } else {
        batch.draw(region, getX(), getY(), region.getRegionWidth(), region.getRegionHeight());
    }
}
 
Example 2
Source File: RepeatTextureDrawable.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float originX, float originY,
                 float width, float height, float scaleX, float scaleY, float rotation) {
    batch.draw(texture,
            x, y,
            originX, originY,
            width, height,
            scaleX, scaleY,
            rotation,
            shiftX, shiftY,
            (int)width, (int)height,
            false, false);
}
 
Example 3
Source File: RadialDrawable.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public void draw(final Batch batch, final float x, final float y, float width, float height, final float angle) {
    if (width < 0) { scaleX = -1f; width = -width; }
    if (height < 0) { scaleY = -1f; height = -height; }
    calculate(x, y, width, height, angle, u1, v1, u2, v2);

    // Update color
    float batchColor = batch.getPackedColor();
    for (int i = 0; i < 12; i++) {
        verts[i * 5 + 2] = batchColor;
    }

    batch.draw(texture, verts, 0, 20*draw);
}
 
Example 4
Source File: AnimationDrawable.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float originX, float originY, float width, float height,
		float scaleX, float scaleY, float rotation) {

	if (tint != null)
		batch.setColor(tint);

	batch.draw(anim.getKeyFrame(stateTime), x, y, originX, originY, width, height, scaleX, scaleY, rotation);

	if (tint != null)
		batch.setColor(Color.WHITE);
}
 
Example 5
Source File: AnimationDrawable.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float width, float height) {
	if (tint != null)
		batch.setColor(tint);

	batch.draw(anim.getKeyFrame(stateTime), x, y, width, height);

	if (tint != null)
		batch.setColor(Color.WHITE);
}
 
Example 6
Source File: RotatingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;

	float scalefactor;

	switch (scaling) {
	case IN:
		scalefactor = percent;
		break;
	case OUT:
		scalefactor = 1.0f - percent;
		break;
	case NONE:
	default:
		scalefactor = 1.0f;
		break;
	}

	float rotation = 1;
	if (interpolation != null) rotation = interpolation.apply(percent);

	batch.begin();
	batch.draw(currentScreenTexture, 0, 0, width / 2, height / 2, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false,
		true);
	batch.draw(nextScreenTexture, 0, 0, width / 2, height / 2, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(),
		scalefactor, scalefactor, rotation * angle, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false,
		true);
	batch.end();

}
 
Example 7
Source File: Background.java    From martianrun with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    batch.draw(textureRegion, textureRegionBounds1.x, textureRegionBounds1.y, Constants.APP_WIDTH,
            Constants.APP_HEIGHT);
    batch.draw(textureRegion, textureRegionBounds2.x, textureRegionBounds2.y, Constants.APP_WIDTH,
            Constants.APP_HEIGHT);
}
 
Example 8
Source File: TeamLeader.java    From Norii with Apache License 2.0 5 votes vote down vote up
public void renderUnits(final Batch batch) {
	for (final Entity entity : team) {
		if (entity.isInBattle()) {
			batch.draw(entity.getFrame(), entity.getCurrentPosition().getTileX(), entity.getCurrentPosition().getTileY(), 1f, 1f);
		}
	}
}
 
Example 9
Source File: Tutorial.java    From martianrun with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    batch.draw(textureRegion, bounds.x, bounds.y, bounds.width, bounds.height);
    font.drawWrapped(batch, text, bounds.x, bounds.y, bounds.width,
            BitmapFont.HAlignment.CENTER);
}
 
Example 10
Source File: CCParticleActor.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
protected void drawParticles(Batch batch) {
        int srcFunc = batch.getBlendSrcFunc();
        int dstFunc = batch.getBlendDstFunc();
        batch.setBlendFunction(blendSrc, blendDst);
        //System.out.println("_particleCount:"+_particleCount);
        for (int i = 0; i < _particleCount; i++) {
            batch.draw(m_pTexture, vertices[i], 0, 20);
        }
        batch.setBlendFunction(srcFunc, dstFunc);
//        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
 
Example 11
Source File: SlidingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;
	if (interpolation != null) percent = interpolation.apply(percent);

	switch (direction) {
	case LEFT:
		x = -width * percent;
		if (!slideOut) x += width;
		break;
	case RIGHT:
		x = width * percent;
		if (!slideOut) x -= width;
		break;
	case UP:
		y = height * percent;
		if (!slideOut) y -= height;
		break;
	case DOWN:
		y = -height * percent;
		if (!slideOut) y += height;
		break;
	}
	Texture texBottom = slideOut ? nextScreenTexture : currentScreenTexture;
	Texture texTop = slideOut ? currentScreenTexture : nextScreenTexture;

	batch.begin();
	batch.draw(texBottom, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true);
	batch.draw(texTop, x, y, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0,
		nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);
	batch.end();

}
 
Example 12
Source File: AlphaFadingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float alpha) {
	alpha = Interpolation.fade.apply(alpha);
	batch.begin();
	batch.setColor(1, 1, 1, 1);
	batch.draw(currentScreenTexture, 0, 0, 0, 0, currentScreenTexture.getWidth(), currentScreenTexture.getHeight(), 1, 1, 0, 0,
		0, currentScreenTexture.getWidth(), currentScreenTexture.getHeight(), false, true);
	batch.setColor(1, 1, 1, alpha);
	batch.draw(nextScreenTexture, 0, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0,
		nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);
	batch.end();

}
 
Example 13
Source File: BlockingWindow.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    GdxHelper.setBatchColor(batch, getColor(), parentAlpha);
    batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), 0);
}
 
Example 14
Source File: HirelingPanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  batch.draw(NpcInv, getX(), getY());
  super.draw(batch, a);
}
 
Example 15
Source File: ControlPanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  batch.draw(background, getX(), getY());
  super.draw(batch, a);
}
 
Example 16
Source File: CubePanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  batch.draw(supertransmogrifier, getX(), getY());
  super.draw(batch, a);
}
 
Example 17
Source File: Cell.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
public static void draw(final Texture texture, final Color color, final Batch batch,
                        final float x, final float y, final float size) {
    batch.setColor(color);
    batch.draw(texture, x, y, size, size);
}
 
Example 18
Source File: ControlPanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  batch.draw(background, getX(), getY());
  super.draw(batch, a);
}
 
Example 19
Source File: VfxWidgetGroup.java    From gdx-vfx with Apache License 2.0 4 votes vote down vote up
@Override
    public void draw(Batch batch, float parentAlpha) {
        validate();

//        //TODO Check if there are any active effects before start capturing/processing.
//        if (!vfxManager.anyEnabledEffects()) {
//            this.drawChildren(batch, parentAlpha);
//            return;
//        }

        VfxFrameBuffer captureBuffer = vfxManager.getResultBuffer();

        batch.end();

        performPendingResize();

        vfxManager.cleanUpBuffers();

        captureBuffer.addRenderer(rendererAdapter);
        vfxManager.beginInputCapture();

        batch.begin();

        validate();
        drawChildren(batch, parentAlpha);

        batch.end();

        vfxManager.endInputCapture();
        captureBuffer.removeRenderer(rendererAdapter);

        vfxManager.applyEffects();

        batch.begin();

        // Render result to the screen.
        Color color = getColor();
        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
        batch.draw(vfxManager.getResultBuffer().getFbo().getColorBufferTexture(),
                getX(), getY(), getWidth(), getHeight(),
                0f, 0f, 1f, 1f);
    }
 
Example 20
Source File: AnimationDrawable.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float width, float height) {
    stateTime += Gdx.graphics.getDeltaTime();
    batch.draw(getKeyFrame(stateTime), x, y, width, height);
}