List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch setBlendFunction
@Override
public void setBlendFunction(int srcFunc, int dstFunc)
From source file:at.therefactory.jewelthief.ui.Particles.java
License:Open Source License
/** * if particle effect includes additive or pre-multiplied particle emitters * you can turn off blend function clean-up to save a lot of draw calls * but remember to switch the Batch back to GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA * before drawing "regular" sprites or your Stage. * * @param batch/*from w ww .j av a 2s.co m*/ */ private void resetBlendFunction(SpriteBatch batch) { batch.setBlendFunction(-1, -1); Gdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_DST_ALPHA); }
From source file:com.bmnb.fly_dragonfly.graphics.GameParticleEmitter.java
License:Apache License
public void draw(SpriteBatch spriteBatch) { if (additive) spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE); Particle[] particles = this.particles; boolean[] active = this.active; int activeCount = this.activeCount; for (int i = 0, n = active.length; i < n; i++) if (active[i]) particles[i].draw(spriteBatch); this.activeCount = activeCount; if (additive) spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); }
From source file:com.bmnb.fly_dragonfly.graphics.GameParticleEmitter.java
License:Apache License
/** Updates and draws the particles. This is slightly more efficient than calling {@link #update(float)} and * {@link #draw(SpriteBatch)} separately. */ public void draw(SpriteBatch spriteBatch, float delta) { accumulator += Math.min(delta * 1000, 250); if (accumulator < 1) { draw(spriteBatch);/*ww w .ja va 2 s.co m*/ return; } // com.badlogic.gdx.graphics.g2d.ParticleEmitter int deltaMillis = (int) accumulator; accumulator -= deltaMillis; if (additive) spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); Particle[] particles = this.particles; boolean[] active = this.active; int activeCount = this.activeCount; for (int i = 0, n = active.length; i < n; i++) { if (active[i]) { Particle particle = particles[i]; if (updateParticle(particle, delta, deltaMillis) && !particle.isDead()) particle.draw(spriteBatch); else { particle.kill(); active[i] = false; activeCount--; } } } this.activeCount = activeCount; if (additive) spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); if (delayTimer < delay) { delayTimer += deltaMillis; return; } if (firstUpdate) { firstUpdate = false; addParticle(); } if (durationTimer < duration) durationTimer += deltaMillis; else { if (!continuous || allowCompletion) return; restart(); } emissionDelta += deltaMillis; float emissionTime = emission + emissionDiff * emissionValue.getScale(durationTimer / (float) duration); if (emissionTime > 0) { emissionTime = 1000 / emissionTime; if (emissionDelta >= emissionTime) { int emitCount = (int) (emissionDelta / emissionTime); emitCount = Math.min(emitCount, maxParticleCount - activeCount); emissionDelta -= emitCount * emissionTime; emissionDelta %= emissionTime; addParticles(emitCount); } } if (activeCount < minParticleCount) addParticles(minParticleCount - activeCount); }
From source file:net.bplaced.therefactory.nomoore.utils.Particles.java
License:Open Source License
private void resetBlendFunction(SpriteBatch batch) { batch.setBlendFunction(-1, -1); Gdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_DST_ALPHA);/* w w w. ja v a2 s.co m*/ }
From source file:org.bladecoder.bladeengine.model.Scene.java
License:Apache License
public void draw(SpriteBatch spriteBatch) { if (background != null) { spriteBatch.disableBlending();/*from w w w.ja va 2 s. c o m*/ float x = 0; for (Texture tile : background) { spriteBatch.draw(tile, x, 0f); x += tile.getWidth(); } spriteBatch.enableBlending(); } for (Actor a : orderedActors) { if (a instanceof SpriteActor) ((SpriteActor) a).draw(spriteBatch); } for (SpriteActor a : fgActors) { a.draw(spriteBatch); } // Draw the light map if (lightMap != null) { // Multiplicative blending for light maps spriteBatch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ZERO); float x = 0; for (Texture tile : lightMap) { spriteBatch.draw(tile, x, 0f); x += tile.getWidth(); } spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } if (overlay != null) { overlay.draw(spriteBatch); } if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) { StringBuilder sb = new StringBuilder(); for (Actor a : orderedActors) { Rectangle r = a.getBBox().getBoundingRectangle(); sb.setLength(0); sb.append(a.getId()); if (a.getState() != null) sb.append(".").append(a.getState()); // sb.append(" (").append((int) r.getX()).append(", "); // sb.append((int) r.getY()).append(", ").append((int) // r.getWidth()); // sb.append(", ").append((int) r.getHeight()).append(") "); EngineLogger.getDebugFont().draw(spriteBatch, sb.toString(), r.getX(), r.getY()); } } }