Example usage for com.badlogic.gdx.graphics.g2d ParticleEffectPool obtain

List of usage examples for com.badlogic.gdx.graphics.g2d ParticleEffectPool obtain

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d ParticleEffectPool obtain.

Prototype

public PooledEffect obtain() 

Source Link

Usage

From source file:com.quadbits.gdxhelper.scenemodel.handlers.ParticleEffectActorModelHandler.java

License:Apache License

@Override
public Object create(BaseModel model, String id, boolean forceCreation) {
    // Safeguard against duplicate calls
    if (!forceCreation && model.created) {
        return null;
    }/*from   w ww . j a  v  a 2s. c om*/
    model.created = true;

    // Id
    if (id == null) {
        id = model.id;
    }

    ParticleEffectActorModel actorModel = (ParticleEffectActorModel) model;
    HashMap<String, Actor> allActors = sceneModelManager.getAllActors();
    ArrayList<Actor> resizeableActorsAbsolute = sceneModelManager.getResizeableActorsAbsolute();
    HashMap<String, Controller> allControllers = sceneModelManager.getAllControllers();
    HashMap<String, ParticleEffectPool> particleEffectPools = sceneModelManager.getParticleEffectPools();

    // Get parent
    Group parent = null;
    if (actorModel.parent != null && actorModel.addToParent) {
        parent = (Group) allActors.get(actorModel.parent);
    }

    // Create particle effect actor
    ParticleEffectActor actor = particleEffectActorPool.obtain();
    actor.setName(id);
    if (parent != null) {
        parent.addActor(actor);
    }
    allActors.put(id, actor);
    resizeableActorsAbsolute.add(actor);

    // Get pooled effect from pool, create pool if it does not exist
    ParticleEffectPool effectPool = particleEffectPools.get(actorModel.effectFile);
    if (effectPool == null) {
        ParticleEffect prototype = new ParticleEffect();
        if (actorModel.atlasPrefix == null) {
            prototype.load(Gdx.files.internal(actorModel.effectFile), textureAtlasProxy.get());
        } else {
            prototype.load(Gdx.files.internal(actorModel.effectFile), textureAtlasProxy.get(),
                    actorModel.atlasPrefix);
        }
        effectPool = new ParticleEffectPool(prototype, 1, 70);
        particleEffectPools.put(actorModel.effectFile, effectPool);
        //            prototype.dispose();
    }
    ParticleEffectPool.PooledEffect effect = effectPool.obtain();
    effect.start();
    actor.setEffect(effect);

    // Process controllers
    if (actorModel.controllers != null) {
        for (String controllerId : actorModel.controllers) {
            Controller controller = allControllers.get(controllerId);
            if (controller != null) {
                actor.addController(controller);
            }
        }
    }

    return actor;
}

From source file:com.vlaaad.dice.game.world.view.visualizers.actions.RangedDamageVisualizer.java

License:Open Source License

@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();/*from ww  w .  j av  a  2 s  . co m*/
        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;
}