public GameState(String name, String tmx, StateManager manager) { this.tmx = tmx; setManager(manager); if(name!=null) this.name = name; else this.name = ""; sprites = new ObjectMap<String, Sprite>(); animations = new ObjectMap<String, Animation<String>>(); fonts = new ObjectMap<String, BitmapFont>(); //TODO: test load to avoid repeats particle_effects = new ObjectMap<String, ParticleEffectPool>(); pvalues = new Array<String>(); time_scale = 1f; shaders = new ObjectMap<String, ShaderProgram>(); svalues = new Array<String>(); }
private void loadParticleEffects(TiledMap data, String atlasname) { MapObjects objects = data.getLayers().get("preload").getObjects(); String ppcheck = "Particle"; for (MapObject o : objects) { String name = o.getName(); MapProperties properties = o.getProperties(); String type = properties.get("type", String.class); if (type != null && type.equals(ppcheck)) { String file = properties.get("particle_file", String.class); if (file != null) { game.loadParticleEffect(file, atlasname); game.getAssetManager().finishLoading(); if (!particle_effects.containsKey(name)) { ParticleEffect pe = game.getParticleEffect(file); pe.setEmittersCleanUpBlendFunction(false); pvalues.add(KyperBoxGame.PARTICLE_FOLDER + KyperBoxGame.FILE_SEPARATOR + file); particle_effects.put(name, new ParticleEffectPool(pe, 12, 48)); } } } } }
@Override public IFuture<Void> visualize(RangedDamageResult result) { final Future<Void> future = new Future<Void>(); SoundManager.instance.playSound("ability-firestorm"); if (Config.particles.exists("ability-" + result.ability.name + "-hit")) { ParticleEffectPool effectPool = Config.particles.get("ability-" + result.ability.name + "-hit"); ParticleActor actor = new ParticleActor(effectPool.obtain()); visualizer.viewController.effectLayer.addActor(actor); actor.freeOnComplete(); actor.setPosition( result.target.getX() * ViewController.CELL_SIZE + ViewController.CELL_SIZE / 2, result.target.getY() * ViewController.CELL_SIZE + ViewController.CELL_SIZE / 2 ); } if (result.success) { visualizer.viewController.visualize(new Death(result.creature, result.target)).addListener(future); } else { visualizer.viewController.visualize(new Defence(result.target, AttackType.weapon)).addListener(future); } return future; }
public ParticleEffectPools() { logger = new Logger(TAG, Env.debugLevel); logger.info("initialising"); pools = new ObjectMap<String, ParticleEffectPool>(); try { JsonReader reader = new JsonReader(); JsonValue root = reader.parse(Gdx.files.internal(PARTICLES_FILE)); JsonIterator particlesIt = root.iterator(); while (particlesIt.hasNext()) { JsonValue particleValue = particlesIt.next(); String effectName = particleValue.asString(); logger.info("loading " + effectName); ParticleEffect effect = new ParticleEffect(); effect.load(Gdx.files.internal(effectName), Gdx.files.internal(PARTICLES_FOLDER)); pools.put(effectName, new ParticleEffectPool(effect, Env.particlePoolInitialCapacity, Env.particlePoolMaxCapacity)); } } catch (Exception e) { logger.error("failed to list directory " + PARTICLES_FILE); } }
public PoisonDrop(final CDGame game) { super(game); x = MathUtils.random(0, game.GAME_WIDTH-64); y = game.GAME_HEIGHT; width = 64; height = 64; loseOnMiss = false; gainValue = 0; loseValue = 2; rectImg = new Texture("poison.png"); poisonTimer = 10; nowTimeInSeconds = TimeUtils.nanosToMillis(TimeUtils.nanoTime())/1000; lastTimeInSeconds = nowTimeInSeconds; fireEffect = new ParticleEffect(); fireEffect.load(Gdx.files.internal("fire.p"), Gdx.files.internal("")); fireEffectPool = new ParticleEffectPool(fireEffect, 1, 2); firePEffect = fireEffectPool.obtain(); }
public PoisonDrop(final CDGame game, float x, float y, BitmapFont timerFont) { super(game); this.x = x; this.y = y; width = 64; height = 64; loseOnMiss = false; gainValue = 0; loseValue = 2; rectImg = new Texture("poison.png"); poisonTimer = 10; nowTimeInSeconds = TimeUtils.nanosToMillis(TimeUtils.nanoTime())/1000; lastTimeInSeconds = nowTimeInSeconds; fireEffect = new ParticleEffect(); fireEffect.load(Gdx.files.internal("fire.p"), Gdx.files.internal("")); fireEffectPool = new ParticleEffectPool(fireEffect, 1, 2); firePEffect = fireEffectPool.obtain(); this.timerFont = timerFont; }
private void addEffect(String effectName, String imgName) { ParticleEffect reffect = new ParticleEffect(); TextureAtlas atlas = new TextureAtlas(); atlas.addRegion( imgName, new TextureRegion(new Texture(Gdx.files.internal("particles/" + imgName + ".png")))); reffect.load(Gdx.files.internal("particles/" + effectName + ".p"), atlas); EffectPool = new ParticleEffectPool(reffect, 1, 2); // Create effect PooledEffect effect = EffectPool.obtain(); effect.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2); effects.add(effect); }
/** * Add new (and activate) the effect just has been added. * @param key key of effect * @param particleEffectFilePath File path of effect file * @param dirPathOfImages path of folder that contains images for effect * @param isActiveEffect set Active Effect for effect just has been added. */ public void addParticleEffect(String key, String particleEffectFilePath, String dirPathOfImages){ if(collection.containsKey(key)) { throw new GdxRuntimeException("Key for the particle effect is existing!"); } ParticleEffect effect = new ParticleEffect(); effect.load(Gdx.files.internal(particleEffectFilePath),Gdx.files.internal(dirPathOfImages)); ParticleEffectPool pool = new ParticleEffectPool(effect, 1, 2); collection.put(key, pool); }
@Override public void init(MapProperties properties) { effects = new ArrayMap<GameObject, ParticleEffectPool.PooledEffect>(); pre_draws = new Array<ParticleEffectPool.PooledEffect>(); post_draws = new Array<ParticleEffectPool.PooledEffect>(); pos_check = new Vector2(); cam = getLayer().getCamera(); last_zoom = cam.getZoom(); pcomp = new ParticleComparator(); }
private void render(SpriteBatch batch, float delta, float x, float y, ParticleEffectPool.PooledEffect[] pooledEffect) { for (ParticleEffectPool.PooledEffect effect : pooledEffect) { effect.setPosition(x, y); effect.draw(batch, delta); if (effect.isComplete()) { resetFireworksEffect(effect); } } resetBlendFunction(batch); }
public Particles(TextureAtlas textureAtlas) { fireworkEffects = new ParticleEffectPool.PooledEffect[5]; startColors = new float[][]{ // new float[]{0, .58f, 1}, // blue new float[]{1, .984f, .267f}, // yellow new float[]{.969f, .11f, 1}, // pink new float[]{1, .02f, .082f}, // red new float[]{.816f, 0, 1}, // violet new float[]{0, 1, .098f}, // green }; ParticleEffect fireworksEffect = new ParticleEffect(); fireworksEffect.load(Gdx.files.internal("particles/fireworks.p"), textureAtlas); // 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. fireworksEffect.setEmittersCleanUpBlendFunction(false); fireworksEffectPool = new ParticleEffectPool(fireworksEffect, 1, 5); for (int i = 0; i < fireworkEffects.length; i++) { ParticleEffectPool.PooledEffect effect = fireworksEffectPool.obtain(); resetFireworksEffect(effect); fireworkEffects[i] = effect; } }
/** * Renders the fireworks effects on the given batch and resets each effect if it has reached its end. * * @param batch * @param delta */ public void renderFireworks(SpriteBatch batch, float delta) { for (ParticleEffectPool.PooledEffect effect : fireworkEffects) { effect.draw(batch, delta); if (effect.isComplete()) { resetFireworksEffect(effect); } } resetBlendFunction(batch); }
/** * Frees all allocated resources. */ public void dispose() { for (ParticleEffectPool.PooledEffect effect : fireworkEffects) { effect.free(); effect.dispose(); } fireworksEffectPool.clear(); }
public EscapyWeather(float scrW, float scrH, String[] pFile, String[] pImg, String[] names){ weatherArray = new EscapyNamedArray<>(ParticleEffectPool.class); batch = new SpriteBatch(); SCR_W = scrW; SCR_H = scrH; load(pFile, pImg, names); }
public EscapyWeather(float scrW, float scrH, String pFile, String pImg, String name){ weatherArray = new EscapyNamedArray<>(ParticleEffectPool.class); batch = new SpriteBatch(); SCR_W = scrW; SCR_H = scrH; load(pFile, pImg, name); }
public EscapyWeather setWeather(String name) { if (name != null) { if (actual != null) { Arrays.stream(actual).forEach(ParticleEffectPool.PooledEffect::free); } actual = new ParticleEffectPool.PooledEffect[3]; float[] ps = new float[]{ -SCR_W, 0, SCR_W }; for (int i = 0; i < actual.length; i++) { actual[i] = weatherArray.get(name).obtain(); actual[i].flipY(); actual[i].setPosition(ps[i] + startPoint[0], startPoint[1] - 50); } } return this; }
public EscapyWeather load(String[] pFile, String[] pImg, String[] names) { for (int i = 0; i < pFile.length; i++) { ParticleEffect tmp = new ParticleEffect(); tmp.load(new FileHandle(pFile[i]), new FileHandle(pImg[i])); tmp.setPosition(0, -50); weatherArray.addSource(new ParticleEffectPool(tmp, 0, 10), names[i]); } return this; }
@Override public void dispose() { logger.info("dispose"); for (ParticleEffectPool pool : pools.values()) { pool.clear(); } }
public ParticleRenderer() { singleEffects = new CopyOnWriteArrayList<PooledEffect>(); pools = new HashMap<String, ParticleEffectPool>(); effects = new HashMap<GameObject, PooledEffect>(); mapping = new HashMap<GameObject, String>(); offsets = new HashMap<GameObject, Vector2>(); objects = new HashMap<PooledEffect, GameObject>(); }
public PooledEffect getEffect(GameObject object) { PooledEffect effect = effects.get(object); if (effect != null) { return effect; } else if (mapping.containsKey(object)) { String id = mapping.get(object); ParticleEffectPool pool = pools.get(id); effect = pool.obtain(); effects.put(object, effect); return effect; } else { return null; } }
public void applyParticleEffect(String id, float x, float y) { ensurePool(id); ParticleEffectPool pool = pools.get(id); PooledEffect effect = pool.obtain(); effect.setPosition(x, y); singleEffects.add(effect); }
public boolean free(ManagedParticleEffect effect, boolean force) { if (force || effect.getEffect().isComplete()) { effect.getEffect().free(); ParticleEffectPool pool = pools.get(effect.getPath()); pool.free(effect.getEffect()); return true; } return false; }
@Override public void dispose() { for (ParticleEffectPool pool : pools.values()) { pool.clear(); } pools.clear(); }
@Override public void show() { batch = new SpriteBatch(); logo = new Texture("udacity_logo_white.png"); logoHeight = logo.getHeight() * LOGO_WIDTH / logo.getWidth(); ParticleEffect touchEffect = new ParticleEffect(); touchEffect.load(Gdx.files.internal("UdacityEmitter.p"), Gdx.files.internal("")); touchEffect.setEmittersCleanUpBlendFunction(false); touchEffectPool = new ParticleEffectPool(touchEffect, 1, 2); Gdx.input.setInputProcessor(this); }
public void loadTemplates () { for (int i = 0; i < ParticleType.values().length; i++) { ParticleEffect template = new ParticleEffect(); template.load(Gdx.files.internal(ROOT_DIR + ParticleType.values()[i].file), Gdx.files.internal(ROOT_DIR)); template.scaleEffect(0.02f); effectTemplates.add(template); ParticleEffectPool pool = new ParticleEffectPool(template, 4, 20); effectPools.add(pool); } }
@Override public void show() { batch = new SpriteBatch(); // TODO: Scavenger hunt! Where does this logo live? logo = new Texture("udacity_logo_white.png"); logoHeight = logo.getHeight() * LOGO_WIDTH / logo.getWidth(); ParticleEffect touchEffect = new ParticleEffect(); // TODO: Same question. Where does UdacityEmitter.p live? How are we loading it? touchEffect.load(Gdx.files.internal("UdacityEmitter.p"), Gdx.files.internal("")); touchEffect.setEmittersCleanUpBlendFunction(false); touchEffectPool = new ParticleEffectPool(touchEffect, 1, 2); Gdx.input.setInputProcessor(this); }
public PooledEffect obtain(String name) { ParticleEffectPool pool = pools.get(name); if (pool == null) { logger.error("pool not found " + name); return null; } return pool.obtain(); }
public void free(PooledEffect effect) { Values<ParticleEffectPool> values = pools.values(); while (values.hasNext) { values.next().free(effect); } }
public void clear() { Values<ParticleEffectPool> values = pools.values(); while (values.hasNext) { values.next().clear(); } }
@Override public void createEffect(int x, int y, Effect effectType) { if(effectType == Effect.COIN_EFFECT) { ParticleEffectPool.PooledEffect prt = particleManager.obtainEffect(ParticleManager.COIN_EFFECT); prt.setPosition(x, y); particleManager.addEffect(prt); // Play sound effect coinSound.play(); } else { throw new IllegalArgumentException("Unknown effectType"); } }
public ParticleManager() { ParticleEffect temp; // COIN_EFFECT = 0 temp = IsometricGame.assets.get("particles/coin.p", ParticleEffect.class); effectPools.add(new ParticleEffectPool(temp, 10, 100)); }
public void update(float dt) { for (int i = runningEffects.size - 1; i >= 0; i--) { ParticleEffectPool.PooledEffect effect = runningEffects.get(i); effect.update(dt); if (effect.isComplete()) { effect.free(); runningEffects.removeIndex(i); } } }
public void LoadPSPool(String particlepoolname, String filename, String imagename) { Image img = images.get(imagename); ParticleEffect pe = new ParticleEffect(); TextureAtlas atlas = new TextureAtlas(); atlas.addRegion(imagename, img); pe.load(Gdx.files.internal(filename), atlas); ParticleEffectPool pool = new ParticleEffectPool(pe, 1, 10); particlePools.put(particlepoolname, pool); }
/** * Resets the position, start color and duration of all firework effects to random values. */ public void resetFireworksEffects() { for (ParticleEffectPool.PooledEffect effect : fireworkEffects) { resetFireworksEffect(effect); } }
public EscapyWeather(float scrW, float scrH){ weatherArray = new EscapyNamedArray<>(ParticleEffectPool.class); batch = new SpriteBatch(); SCR_W = scrW; SCR_H = scrH; }
public EscapyWeather setFunc(Consumer<ParticleEffectPool.PooledEffect> cons) { if (actual != null) Arrays.stream(actual).forEach(cons); return this; }
public void setEffect(ParticleEffectPool.PooledEffect effect){ this.pooledEffect = effect; }
public Particles(ObjectMap<String, ParticleEffectPool> data) { this.data = data; }
public ParticleEffectPool get(String name) { if (!data.containsKey(name)) throw new IllegalArgumentException("there is no such particle: " + name); return data.get(name); }
public ParticleActor(ParticleEffectPool.PooledEffect effect) { this.effect = effect; }