Java Code Examples for com.badlogic.gdx.graphics.g2d.SpriteBatch#setColor()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.SpriteBatch#setColor() .
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: ConsoleTargeting.java From jorbs-spire-mod with MIT License | 6 votes |
public void renderTargetingUi(SpriteBatch sb) { float x = InputHelper.mX; float y = InputHelper.mY; this.controlPoint = new Vector2(AbstractDungeon.player.animX - (x - AbstractDungeon.player.animX) / 4.0F, AbstractDungeon.player.animY + (y - AbstractDungeon.player.animY - 40.0F * Settings.scale) / 2.0F); if (this.hoveredCreature == null) { this.arrowScale = Settings.scale; this.arrowScaleTimer = 0.0F; sb.setColor(new Color(1.0F, 1.0F, 1.0F, 1.0F)); } else { this.arrowScaleTimer += com.badlogic.gdx.Gdx.graphics.getDeltaTime(); if (this.arrowScaleTimer > 1.0F) { this.arrowScaleTimer = 1.0F; } this.arrowScale = com.badlogic.gdx.math.Interpolation.elasticOut.apply(Settings.scale, Settings.scale * 1.2F, this.arrowScaleTimer); sb.setColor(new Color(1.0F, 0.2F, 0.3F, 1.0F)); } Vector2 tmp = new Vector2(this.controlPoint.x - x, this.controlPoint.y - y); tmp.nor(); drawCurvedLine(sb, new Vector2(AbstractDungeon.player.dialogX, AbstractDungeon.player.dialogY - 40.0F * Settings.scale), new Vector2(x, y), this.controlPoint); sb.draw(ImageMaster.TARGET_UI_ARROW, x - 128.0F, y - 128.0F, 128.0F, 128.0F, 256.0F, 256.0F, this.arrowScale, this.arrowScale, tmp.angle() + 90.0F, 0, 0, 256, 256, false, false); }
Example 2
Source File: AtlasRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { float dx = getAlignDx(getWidth(), orgAlign); float dy = getAlignDy(getHeight(), orgAlign); if (tex == null) { RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY, Color.RED); return; } x = x + tex.offsetX + dx; y = y + tex.offsetY + dy; if (tint != null) batch.setColor(tint); batch.draw(tex, x, y, -dx - tex.offsetX, -dy - tex.offsetY, tex.packedWidth, tex.packedHeight, flipX ? -scaleX : scaleX, scaleY, rotation); if (tint != null) batch.setColor(Color.WHITE); }
Example 3
Source File: ImageRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { float dx = getAlignDx(getWidth(), orgAlign); float dy = getAlignDy(getHeight(), orgAlign); ImageCacheEntry source = (ImageCacheEntry) currentSource; if (source == null || source.tex == null) { RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY, Color.RED); return; } if (tint != null) batch.setColor(tint); x = x + dx; y = y + dy; batch.draw(source.tex, x, y, -dx, -dy, getWidth(), getHeight(), scaleX, scaleY, rotation, 0, 0, source.tex.getWidth(), source.tex.getHeight(), flipX, false); if (tint != null) batch.setColor(Color.WHITE); }
Example 4
Source File: TargettingArrowUi.java From jorbs-spire-mod with MIT License | 6 votes |
public void renderTargetingUi(SpriteBatch sb) { if (atValidTarget) { this.arrowScale = Settings.scale; this.arrowScaleTimer = 0.0F; sb.setColor(new Color(1.0F, 1.0F, 1.0F, 1.0F)); } else { this.arrowScaleTimer += com.badlogic.gdx.Gdx.graphics.getDeltaTime(); if (this.arrowScaleTimer > 1.0F) { this.arrowScaleTimer = 1.0F; } this.arrowScale = com.badlogic.gdx.math.Interpolation.elasticOut.apply(Settings.scale, Settings.scale * 1.2F, this.arrowScaleTimer); sb.setColor(new Color(1.0F, 0.2F, 0.3F, 1.0F)); } Vector2 tmp = new Vector2(this.from.x - to.x, this.from.y - to.y); tmp.nor(); drawCurvedLine(sb, new Vector2(AbstractDungeon.player.dialogX, AbstractDungeon.player.dialogY - 40.0F * Settings.scale), new Vector2(to.x, to.y), this.from); sb.draw(ImageMaster.TARGET_UI_ARROW, to.x - 128.0F, to.y - 128.0F, 128.0F, 128.0F, 256.0F, 256.0F, this.arrowScale, this.arrowScale, tmp.angle() + 90.0F, 0, 0, 256, 256, false, false); }
Example 5
Source File: RenderHealthBar.java From StSLib with MIT License | 6 votes |
private static void renderTempHPIconAndValue(AbstractCreature creature, SpriteBatch sb, float x, float y) { sb.setColor(Settings.GOLD_COLOR); sb.draw(StSLib.TEMP_HP_ICON, x + getPrivate(AbstractCreature.class, "BLOCK_ICON_X", Float.class) - 16.0f + creature.hb.width, y + getPrivate(AbstractCreature.class, "BLOCK_ICON_Y", Float.class) - 32.0f, 32.0f, 32.0f, 64.0f, 64.0f, Settings.scale, Settings.scale, 0.0f, 0, 0, 64, 64, false, false); FontHelper.renderFontCentered(sb, FontHelper.blockInfoFont, Integer.toString(TempHPField.tempHp.get(creature)), x + getPrivate(AbstractCreature.class, "BLOCK_ICON_X", Float.class) + 16.0f + creature.hb.width, y - 16.0f * Settings.scale, Settings.CREAM_COLOR, 1.0f); }
Example 6
Source File: RenderTempHPOutline.java From StSLib with MIT License | 5 votes |
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 7
Source File: LivingEntity.java From TerraLegion with MIT License | 5 votes |
@Override public void render(SpriteBatch sb, double lightValue) { float value = (float) (lightValue < LightUtils.MIN_LIGHT_VALUE ? LightUtils.MIN_LIGHT_VALUE : lightValue); sb.setColor(value, value, value, 1); sb.draw(drawable.getTextureRegion(), x, y, drawable.getTextureRegion().getRegionWidth(), drawable.getTextureRegion().getRegionHeight()); sb.setColor(Color.WHITE); if (Timer.getGameTimeElapsed() - lastDamageReceived <= 5f) { renderHealthBar(sb); } }
Example 8
Source File: SceneList.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
private TextureRegion createBgIcon(String atlas, String region) { TextureAtlas a = new TextureAtlas( Gdx.files.absolute(Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/1/" + atlas + ".atlas")); AtlasRegion r = a.findRegion(region); if (r == null) { a.dispose(); return null; } GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(200, (int) (r.getRegionHeight() * 200f / r.getRegionWidth())); frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE); FrameBuffer fbo = frameBufferBuilder.build(); SpriteBatch fboBatch = new SpriteBatch(); fboBatch.setColor(Color.WHITE); OrthographicCamera camera = new OrthographicCamera(); camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight()); fboBatch.setProjectionMatrix(camera.combined); Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); fbo.begin(); fboBatch.begin(); fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight()); fboBatch.end(); TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight()); // tex.flip(false, true); fbo.end(); Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); fbo.dispose(); a.dispose(); fboBatch.dispose(); return tex; }
Example 9
Source File: CommonKeywordIconsPatches.java From StSLib with MIT License | 5 votes |
private static void DrawOnCardCentered(SpriteBatch sb, AbstractCard card, Color color, Texture img, float drawX, float drawY, float width, float height, float scaleModifier) { final float scale = card.drawScale * Settings.scale * scaleModifier; sb.setColor(color); sb.draw(img, drawX - (width / 2f), drawY - (height / 2f), width / 2f, height / 2f, width, height, scale, scale, card.angle, 0, 0, img.getWidth(), img.getHeight(), false, false); }
Example 10
Source File: Block.java From TerraLegion with MIT License | 5 votes |
/** * @param camera Should be switched to OrthoCamera */ public void render(OrthographicCamera camera, SpriteBatch sb, float x, float y, float lightValue) { float value = lightValue < LightUtils.MIN_LIGHT_VALUE ? LightUtils.MIN_LIGHT_VALUE : lightValue; sb.setColor(value, value, value, 1); drawable.render(sb, x, y); sb.setColor(Color.WHITE); }
Example 11
Source File: ParticleRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { float finalScaleX = EngineAssetManager.getInstance().getScale() * scaleX; float finalScaleY = EngineAssetManager.getInstance().getScale() * scaleY; if (effect.getEmitters().size > 0) { Matrix4 tm = batch.getTransformMatrix(); tmp.set(tm); if (tmpPosX != x / finalScaleX || tmpPosY != y / finalScaleY) { tmpPosX = x / finalScaleX; tmpPosY = y / finalScaleY; effect.setPosition(tmpPosX, tmpPosY); } tm.rotate(0, 0, 1, rotation).scale(finalScaleX, finalScaleY, 1); batch.setTransformMatrix(tm); if (tint != null) batch.setColor(tint); effect.draw(batch); if (tint != null) batch.setColor(Color.WHITE); batch.setTransformMatrix(tmp); } else { x = x - getWidth() / 2 * finalScaleX; RectangleRenderer.draw(batch, x, y, getWidth() * finalScaleX, getHeight() * finalScaleY, Color.RED); } }
Example 12
Source File: CampfireThirstEffect.java From jorbs-spire-mod with MIT License | 5 votes |
public void render(SpriteBatch sb) { sb.setColor(this.screenColor); sb.draw(ImageMaster.WHITE_SQUARE_IMG, 0.0F, 0.0F, (float) Settings.WIDTH, (float)Settings.HEIGHT); if (AbstractDungeon.screen == AbstractDungeon.CurrentScreen.GRID) { AbstractDungeon.gridSelectScreen.render(sb); } }
Example 13
Source File: ScalingLaserEffect.java From jorbs-spire-mod with MIT License | 5 votes |
@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 14
Source File: HealthBarRenderPowerPatch.java From StSLib with MIT License | 4 votes |
@SpireInsertPatch( locator=Locator.class, localvars={"x", "y", "targetHealthBarWidth", "HEALTH_BAR_HEIGHT", "HEALTH_BAR_OFFSET_Y"} ) public static void Insert(AbstractCreature __instance, SpriteBatch sb, float x, float y, float targetHealthBarWidth, float HEALTH_BAR_HEIGHT, float HEALTH_BAR_OFFSET_Y) { int poisonAmt = 0; if (__instance.hasPower(PoisonPower.POWER_ID)) { poisonAmt = __instance.getPower(PoisonPower.POWER_ID).amount; if (poisonAmt > 0 && __instance.hasPower(IntangiblePower.POWER_ID)) { poisonAmt = 1; } } int prevPowerAmtSum = poisonAmt; for (AbstractPower power : __instance.powers) { if (power instanceof HealthBarRenderPower) { sb.setColor(((HealthBarRenderPower) power).getColor()); int amt = ((HealthBarRenderPower) power).getHealthBarAmount(); if (amt > 0 && __instance.hasPower(IntangiblePower.POWER_ID)) { amt = 1; } if (__instance.currentHealth > prevPowerAmtSum) { float w = 1.0f - (__instance.currentHealth - prevPowerAmtSum) / (float) __instance.currentHealth; w *= targetHealthBarWidth; if (__instance.currentHealth > 0) { sb.draw(ImageMaster.HEALTH_BAR_L, x - HEALTH_BAR_HEIGHT, y + HEALTH_BAR_OFFSET_Y, HEALTH_BAR_HEIGHT, HEALTH_BAR_HEIGHT); } sb.draw(ImageMaster.HEALTH_BAR_B, x, y + HEALTH_BAR_OFFSET_Y, targetHealthBarWidth - w, HEALTH_BAR_HEIGHT); sb.draw(ImageMaster.HEALTH_BAR_R, x + targetHealthBarWidth - w, y + HEALTH_BAR_OFFSET_Y, HEALTH_BAR_HEIGHT, HEALTH_BAR_HEIGHT); } prevPowerAmtSum += amt; } } allAmtSum = prevPowerAmtSum; prevPowerAmtSum -= poisonAmt; nonPoisonWidthSum = 1.0f - (__instance.currentHealth - prevPowerAmtSum) / (float) __instance.currentHealth; nonPoisonWidthSum *= targetHealthBarWidth; }
Example 15
Source File: Sprite3DRenderer.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { x = x - getWidth() / 2 * scaleX; if (USE_FBO) { if (tint != null) batch.setColor(tint); batch.draw(tex, x, y, 0, 0, width, height, scaleX, scaleY, 0); if (tint != null) batch.setColor(Color.WHITE); } else { float p0x, p0y, pfx, pfy; updateViewport(); // get screen coords for x and y tmp.set(x, y, 0); tmp.mul(batch.getTransformMatrix()); tmp.prj(batch.getProjectionMatrix()); p0x = VIEWPORT.width * (tmp.x + 1) / 2; p0y = VIEWPORT.height * (tmp.y + 1) / 2; tmp.set(x + width * scaleX, y + height * scaleY, 0); tmp.mul(batch.getTransformMatrix()); tmp.prj(batch.getProjectionMatrix()); pfx = VIEWPORT.width * (tmp.x + 1) / 2; pfy = VIEWPORT.height * (tmp.y + 1) / 2; batch.end(); Gdx.gl20.glViewport((int) (p0x + VIEWPORT.x), (int) (p0y + VIEWPORT.y), (int) (pfx - p0x), (int) (pfy - p0y)); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0)); drawModel(); Gdx.gl20.glViewport((int) VIEWPORT.x, (int) VIEWPORT.y, (int) VIEWPORT.width, (int) VIEWPORT.height); batch.begin(); } }
Example 16
Source File: TexturedEntity.java From TerraLegion with MIT License | 4 votes |
public void render(SpriteBatch sb, double lightValue) { float value = (float) (lightValue < LightUtils.MIN_LIGHT_VALUE ? LightUtils.MIN_LIGHT_VALUE : lightValue); sb.setColor(value, value, value, 1); drawable.render(sb, x, y); sb.setColor(Color.WHITE); }
Example 17
Source File: ModsScreen.java From ModTheSpire with MIT License | 4 votes |
private void renderModInfo(SpriteBatch sb) { // Draw bg rectangle sb.setColor(new Color(0, 0, 0, 0.8f)); float screenPadding = 50 * Settings.scale; float x = 600 * Settings.scale; float y = 110 * Settings.scale; sb.draw(ImageMaster.WHITE_SQUARE_IMG, x, screenPadding, Settings.WIDTH - x - screenPadding, Settings.HEIGHT - y - screenPadding); sb.setColor(Color.WHITE); float padding = 20 * Settings.scale; if (selectedMod >= 0) { ModInfo info = Loader.MODINFOS[selectedMod]; String text = info.Name; text += " NL ModVersion: " + (info.ModVersion != null ? info.ModVersion : "<MISSING>"); text += " NL Mod ID: " + (info.ID != null ? info.ID : "<MISSING>"); text += " NL Author" + (info.Authors.length > 1 ? "s" : "") + ": " + StringUtils.join(info.Authors, ", "); if (info.Credits != null && !info.Credits.isEmpty()) { text += " NL Credits: " + newlineToNL(info.Credits); } text += " NL NL " + newlineToNL(info.Description); FontHelper.renderSmartText(sb, FontHelper.buttonLabelFont, text, x + padding, Settings.HEIGHT - y - padding, Settings.WIDTH - x - screenPadding, 26 * Settings.scale, Settings.CREAM_COLOR); if (baseModBadges != null) { configHb.move(x - padding - 50 * Settings.scale, button.hb.y + (button.hb.height / 2.0f)); if (baseModBadges.get(Loader.MODINFOS[selectedMod].jarURL) != null) { configHb.render(sb); Color c = Settings.CREAM_COLOR; if (configHb.hovered) { c = Settings.GOLD_COLOR; } FontHelper.renderFontCentered(sb, FontHelper.buttonLabelFont, "Config", configHb.cX, configHb.cY, c); } } } }
Example 18
Source File: DebugHelper.java From uracer-kotd with Apache License 2.0 | 4 votes |
private void batchColorEnd (SpriteBatch batch) { batch.end(); batch.flush(); batch.setColor(1, 1, 1, 1); batch.begin(); }
Example 19
Source File: FadingTexture.java From TerraLegion with MIT License | 4 votes |
public void render(SpriteBatch sb) { Color color = sb.getColor(); sb.setColor(color.r, color.g, color.b, alpha); sb.draw(texture, x, y); sb.setColor(color); }
Example 20
Source File: DebugMusicVolumes.java From uracer-kotd with Apache License 2.0 | 4 votes |
@Override public void renderBatch (SpriteBatch batch) { if (isActive() && meters.size > 0) { Matrix4 prev = batch.getTransformMatrix(); batch.setTransformMatrix(idt); batch.enableBlending(); float prevHeight = 0; int index = 0; int drawx = 275; int drawy = 0; int maxMusicIndex = tensiveMusic.getCurrentMusicIndexLimit(); SpriteBatchUtils.drawString(batch, "music tracks max=" + maxMusicIndex, drawx, drawy); SpriteBatchUtils.drawString(batch, "==================", drawx, drawy + Art.DebugFontHeight); String text; for (DebugMeter m : meters) { int x = drawx, y = drawy + Art.DebugFontHeight * 2; // offset by index y += index * (prevHeight + 1); // compute color float alpha = index > maxMusicIndex ? 0.5f : 1; Color c = ColorUtils.paletteRYG(1.5f - m.getValue() * 1.5f, alpha); { // render track number text = "T" + (index + 1); batch.setColor(1, 1, 1, alpha); SpriteBatchUtils.drawString(batch, text, x, y); batch.setColor(1, 1, 1, 1); // render meter after text int meter_x = x + (text.length() * Art.DebugFontWidth) + 2; m.color.set(c); m.setPosition(meter_x, y); m.render(batch); // render volume numerical value text = String.format("%.02f", m.getValue()); batch.setColor(1, 1, 1, alpha); SpriteBatchUtils.drawString(batch, text, meter_x + m.getWidth() + 2, y); batch.setColor(1, 1, 1, 1); } index++; prevHeight = m.getHeight(); } SpriteBatchUtils.drawString(batch, "total volume = " + String.format("%.02f", totalVolume), drawx, Art.DebugFontHeight * (meters.size + 3)); batch.setTransformMatrix(prev); batch.disableBlending(); } }