Java Code Examples for com.badlogic.gdx.graphics.g2d.SpriteBatch#setBlendFunction()

The following examples show how to use com.badlogic.gdx.graphics.g2d.SpriteBatch#setBlendFunction() . 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: GLTFBinaryExporter.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
public void export(GLTFImage image, Texture texture, String baseName) {
	String fileName = baseName + ".png";
	image.uri = fileName;
	FileHandle file = folder.child(fileName);
	FrameBuffer fbo = new FrameBuffer(texture.getTextureData().getFormat(), texture.getWidth(), texture.getHeight(), false);
	fbo.begin();
	Gdx.gl.glClearColor(0, 0, 0, 0);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	SpriteBatch batch = new SpriteBatch();
	batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);
	batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
	batch.begin();
	batch.draw(texture, 0, 0, 1, 1, 0, 0, 1, 1);
	batch.end();
	Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight());
	fbo.end();
	batch.dispose();
	fbo.dispose();
	savePNG(file, pixmap);
	pixmap.dispose();
}
 
Example 2
Source File: ScalingLaserEffect.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
@Override
public void render(SpriteBatch sb) {
    sb.setBlendFunction(770, 1);
    sb.setColor(this.color);
    sb.draw(img,
            this.sourceX,
            (this.sourceY - (float) img.packedHeight / 2.0F + 10.0F) - (Settings.scale * (beamThickness / 2)),
            0.0F,
            (float) img.packedHeight / 2.0F,
            this.distance,
            50.0F + (Settings.scale * beamThickness),
            this.scale + MathUtils.random(-0.01F, 0.01F),
            this.scale,
            this.rotation);
    sb.setColor(this.color2);
    sb.draw(img,
            this.sourceX,
            this.sourceY - (float) img.packedHeight / 2.0F - (Settings.scale * beamThickness / 4),
            0.0F,
            (float) img.packedHeight / 2.0F,
            this.distance,
            MathUtils.random(50.0F, 90.0F) + (Settings.scale * beamThickness / 2),
            this.scale + MathUtils.random(-0.02F, 0.02F),
            this.scale,
            this.rotation);
    sb.setBlendFunction(770, 771);
}
 
Example 3
Source File: ArcaneWeaponEffect.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
@Override
public void render(SpriteBatch sb) {
    sb.setBlendFunction(770, 1);
    sb.setColor(color);
    rotation = ((duration - startingDuration) * 180.0F) / startingDuration + 22.5F;
    sb.draw(img,
            targetX - MathUtils.sinDeg(rotation) * img.packedHeight / 2.0F,
            targetY + MathUtils.cosDeg(rotation) * img.packedHeight / 2.0F,
            0.0F,
            (float) img.packedHeight / 2.0F,
            img.packedWidth,
            img.packedHeight,
            scale,
            scale,
            rotation);
    sb.setColor(1.0F, 0.3F, 0.25F, 0.7F);
    sb.draw(img,
            targetX - MathUtils.sinDeg(rotation) * img.packedHeight / 1.25F / 2.0F,
            targetY + MathUtils.cosDeg(rotation) * img.packedHeight / 1.25F / 2.0F,
            0.0F,
            (float) img.packedHeight / 2.0F,
            img.packedWidth / 0.75F,
            img.packedHeight / 0.75F,
            scale,
            scale,
            rotation);
}
 
Example 4
Source File: RenderTempHPOutline.java    From StSLib with MIT License 5 votes vote down vote up
private static void renderTempHPOutline(AbstractCreature creature, SpriteBatch sb, float x, float y)
{
    sb.setColor(Settings.GOLD_COLOR);
    sb.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);

    sb.draw(ImageMaster.BLOCK_BAR_L, x - HEALTH_BAR_HEIGHT, y + HEALTH_BAR_OFFSET_Y, HEALTH_BAR_HEIGHT, HEALTH_BAR_HEIGHT);

    sb.draw(ImageMaster.BLOCK_BAR_B, x, y + HEALTH_BAR_OFFSET_Y, creature.hb.width, HEALTH_BAR_HEIGHT);

    sb.draw(ImageMaster.BLOCK_BAR_R, x + creature.hb.width, y + HEALTH_BAR_OFFSET_Y, HEALTH_BAR_HEIGHT, HEALTH_BAR_HEIGHT);
    sb.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
}
 
Example 5
Source File: DefaultOrb.java    From StS-DefaultModBase with MIT License 5 votes vote down vote up
@Override
public void render(SpriteBatch sb) {
    sb.setColor(new Color(1.0f, 1.0f, 1.0f, c.a / 2.0f));
    sb.draw(img, cX - 48.0f, cY - 48.0f + bobEffect.y, 48.0f, 48.0f, 96.0f, 96.0f, scale + MathUtils.sin(angle / PI_4) * ORB_WAVY_DIST * Settings.scale, scale, angle, 0, 0, 96, 96, false, false);
    sb.setColor(new Color(1.0f, 1.0f, 1.0f, this.c.a / 2.0f));
    sb.setBlendFunction(770, 1);
    sb.draw(img, cX - 48.0f, cY - 48.0f + bobEffect.y, 48.0f, 48.0f, 96.0f, 96.0f, scale, scale + MathUtils.sin(angle / PI_4) * ORB_WAVY_DIST * Settings.scale, -angle, 0, 0, 96, 96, false, false);
    sb.setBlendFunction(770, 771);
    renderText(sb);
    hb.render(sb);
}
 
Example 6
Source File: GameMap.java    From Unlucky with MIT License 5 votes vote down vote up
public void render(float dt, SpriteBatch batch, OrthographicCamera cam) {
    tileMap.renderBottomLayer(batch, cam);

    player.render(batch);

    tileMap.render(batch, cam);
    tileMap.renderTopLayer(batch, cam);

    // render particles
    if (weather != WeatherType.NORMAL) particleFactory.render(batch);

    if (weather == WeatherType.THUNDERSTORM) {
        // render flash of white lightning
        if (lightningTime >= 7) {
            durationTime += dt;
            if (durationTime < 0.2f) {
                if (isDark) renderLight = false;
                if (!player.settings.muteSfx && !sfxPlayed) {
                    rm.thunder.play(player.settings.sfxVolume);
                    sfxPlayed = true;
                }
                batch.draw(rm.lightning, player.getPosition().x - 182, player.getPosition().y - 102);
            }
            if (durationTime > 0.2f) {
                lightningTime = 0;
                durationTime = 0;
                sfxPlayed = false;
                if (isDark) renderLight = true;
            }
        }
    }

    if (renderLight) {
        batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA);
        batch.draw(rm.darkness, player.getPosition().x - 182, player.getPosition().y - 102);
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
}
 
Example 7
Source File: SnapTurnCounterEffect.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
public void render(SpriteBatch sb) {
    sb.setBlendFunction(770, 1);
    sb.setColor(this.color);
    sb.draw(this.img, this.x, this.y, (float)this.img.packedWidth / 2.0F, (float)this.img.packedHeight / 2.0F, (float)this.img.packedWidth, (float)this.img.packedHeight, this.scale, this.scale, this.rotation);
    sb.setBlendFunction(770, 771);
}