Example usage for com.badlogic.gdx.graphics.g2d ParticleEffect ParticleEffect

List of usage examples for com.badlogic.gdx.graphics.g2d ParticleEffect ParticleEffect

Introduction

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

Prototype

public ParticleEffect() 

Source Link

Usage

From source file:actors.BasicSkel.java

public BasicSkel(float hlth, float dmg, float x, float y, int lvl, int pth, Stage stg, PlayScreen scrn) {

    this.setName("skeleton");
    level = lvl;/*w  w  w  .  j  av a 2 s.co  m*/
    path = pth;
    stage = stg;
    screen = scrn;
    health = hlth;
    damage = dmg;
    slowTimer = -1;
    slowed = false;
    reset = false;
    poisoned = false;
    notmoving = false;
    if (damage < 220)
        texture = new Texture("skelsword1.png");
    if (damage < 240 && damage >= 220)
        texture = new Texture("skelsword2.png");
    if (damage >= 240)
        texture = new Texture("skelsword3.png");
    sprite = new Sprite(texture);
    sprite.setScale(0.65f);
    setBounds(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight());

    fireEffect = new ParticleEffect();
    fireEffect.load(Gdx.files.internal("fire"), Gdx.files.internal(""));
    fireEffect.getEmitters().first().setPosition(getX(), getY());
    fireballSound = Gdx.audio.newSound(Gdx.files.internal("fireball.wav"));

    iceEffect = new ParticleEffect();
    iceEffect.load(Gdx.files.internal("ice"), Gdx.files.internal(""));
    iceEffect.getEmitters().first().setPosition(getX(), getY());

    poisonEffect = new ParticleEffect();
    poisonEffect.load(Gdx.files.internal("poison"), Gdx.files.internal(""));
    poisonEffect.getEmitters().first().setPosition(getX(), getY());

    emptyHealthBar = new Sprite(new Texture("emptyBar.png"));
    fullHealthBar = new Sprite(new Texture("fullBar.png"));

    ColorAction red = new ColorAction();
    red.setEndColor(Color.RED);
    red.setDuration(1f);
    MoveToAction moveOff = new MoveToAction();
    moveOff.setPosition(-100, -100);
    kill = new SequenceAction(red, moveOff);

    this.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (health != 100000 && abs(screen.player.getX() - getX()) < screen.playerRange
                    && abs(screen.player.getY() - getY()) < screen.playerRange) {
                if (screen.playerSpell == 1) {
                    health -= screen.playerDamage;
                    stage.addActor(
                            new Fireball(screen.player.getX(), screen.player.getY(), getX() + 16, getY() + 16));
                    fireballSound.play(0.8f);
                    fireEffect.start();
                }
                if (screen.playerSpell == 2) {
                    health -= screen.playerDamage * 0.75;
                    stage.addActor(
                            new IceBolt(screen.player.getX(), screen.player.getY(), getX() + 16, getY() + 16));
                    fireballSound.play(0.8f);
                    iceEffect.start();
                    slowTimer = 3;
                    if (health >= 0)
                        slowed = true;
                }
                if (screen.playerSpell == 3) {
                    poisoned = true;
                    stage.addActor(
                            new IceBolt(screen.player.getX(), screen.player.getY(), getX() + 16, getY() + 16));
                    fireballSound.play(0.8f);
                    poisonEffect.start();
                }

            }
            if (health <= 0) {
                poisoned = false;
                setName("dead");
                health = 100000;
                clearActions();
                addAction(kill);
                screen.skeletonDeath.play(1.0f);
                screen.addGold(5);
            }
        }
    });

    velocity = 70;
    //Rectangle body = new Rectangle(getX(), getY(), getWidth(), getHeight());
    //ScaleByAction sba = new ScaleByAction();
    //sba.setAmount(0.25f);

    assignMovement(x, y);

}

From source file:at.juggle.games.memory.AssetManager.java

License:Apache License

public AssetManager(GameOptions options) {
    this.options = options;
    Preferences preferences = Gdx.app.getPreferences("memory_free_hd.prefs");
    if (preferences.contains("soundOn")) {
        options.soundOn = preferences.getBoolean("soundOn");
    }/*from ww  w  .j a  v a2 s . c  o m*/
    font = new BitmapFont(getFileHandle("berlin_64.fnt"), false);
    smallFont = new BitmapFont(getFileHandle("berlin_42.fnt"), false);
    card = new Texture(getFileHandle("card-front.png"));
    cardBack = new Texture(getFileHandle("card-back.png"));
    cardBackMark = new Texture(getFileHandle("card-back-mark.png"));
    check = new Texture(getFileHandle("Check_32x32.png"));
    positive = new Texture(getFileHandle("Positive_256x256.png"));
    grey = new Texture(getFileHandle("grey.png"));
    background = new Texture(getFileHandle("background.jpg"));
    gradientTop = new Texture(getFileHandle("gradient_oben.png"));
    gradientBottom = new Texture(getFileHandle("gradient_unten.png"));
    if (GameOptions.isFreeVersion) {
        logo = new Texture(getFileHandle("Logo.png"));
    } else {
        logo = new Texture(getFileHandle("Logo_donated.png"));
    }

    cardBack.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    cardBackMark.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    logo.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    Texture vehiclesTexture = new Texture(getFileHandle("vehicles.png"));
    vehiclesTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    TextureRegion[][] veh = TextureRegion.split(vehiclesTexture, 256, 256);

    icons = new TextureRegion[24];
    icons[0] = new TextureRegion(loadTexture("animals/Butterfly_128x128.png"));
    icons[1] = new TextureRegion(loadTexture("animals/Dolphin_128x128.png"));
    icons[2] = new TextureRegion(loadTexture("animals/Elephant_128x128.png"));
    icons[3] = new TextureRegion(loadTexture("animals/Hippopotamus_128x128.png"));
    icons[4] = new TextureRegion(loadTexture("animals/Panda_128x128.png"));
    icons[5] = new TextureRegion(loadTexture("animals/Turtle_128x128.png"));
    icons[6] = new TextureRegion(loadTexture("vacation/surfboard_256x256.png"));
    icons[7] = new TextureRegion(loadTexture("vacation/umbrella_256x256.png"));

    int count = 0;
    for (int i = 0; i < veh.length; i++) {
        TextureRegion[] textureRegions = veh[i];
        for (int j = 0; j < textureRegions.length; j++) {
            icons[8 + count] = textureRegions[j];
            count++;
        }
    }

    // Particle effects
    fireworks = new ParticleEffect();
    fireworks.load(getFileHandle("fireworks"), getFileHandle(""));

    // sounds
    sndFlipCard = Gdx.audio.newSound(getFileHandle("flipcard.ogg"));
    sndCheer = Gdx.audio.newSound(getFileHandle("drums.ogg"));
    sndDing = Gdx.audio.newSound(getFileHandle("ding.ogg"));
}

From source file:at.therefactory.jewelthief.ui.Particles.java

License:Open Source License

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
    };/*from   w  w  w  .  ja  va  2  s .  co m*/

    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;
    }
}

From source file:com.badlogic.gdx.tests.lw.ParticleEmitterTestLW.java

License:Apache License

@Override
public void create() {
    spriteBatch = new SpriteBatch();

    effect = new ParticleEffect();
    effect.load(Gdx.files.internal("data/test.p"), Gdx.files.internal("data"));
    effect.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    // Of course, a ParticleEffect is normally just used, without messing around with its emitters.
    emitters = new Array(effect.getEmitters());
    effect.getEmitters().clear();/*  www. j  a v a  2 s  . com*/
    effect.getEmitters().add(emitters.get(0));

    inputProcessor = new InputProcessorLW() {
        public boolean touchUp(int x, int y, int pointer, int button) {
            return false;
        }

        public boolean touchDragged(int x, int y, int pointer) {
            effect.setPosition(x, Gdx.graphics.getHeight() - y);
            return false;
        }

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            effect.setPosition(x, Gdx.graphics.getHeight() - y);
            return false;
        }

        public boolean keyUp(int keycode) {
            return false;
        }

        public boolean keyTyped(char character) {
            return false;
        }

        public boolean keyDown(int keycode) {
            ParticleEmitter emitter = emitters.get(emitterIndex);
            if (keycode == Input.Keys.DPAD_UP)
                particleCount += 5;
            else if (keycode == Input.Keys.DPAD_DOWN)
                particleCount -= 5;
            else if (keycode == Input.Keys.SPACE) {
                emitterIndex = (emitterIndex + 1) % emitters.size;
                emitter = emitters.get(emitterIndex);
                particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax()
                        / 1000f);
            } else
                return false;
            particleCount = Math.max(0, particleCount);
            if (particleCount > emitter.getMaxParticleCount())
                emitter.setMaxParticleCount(particleCount * 2);
            emitter.getEmission().setHigh(particleCount / emitter.getLife().getHighMax() * 1000);
            effect.getEmitters().clear();
            effect.getEmitters().add(emitter);
            return false;
        }

        @Override
        public boolean touchMoved(int x, int y) {
            return false;
        }

        @Override
        public boolean scrolled(int amount) {
            return false;
        }

        @Override
        public void touchTap(int x, int y) {

            ParticleEmitter emitter = emitters.get(emitterIndex);
            //            if (keycode == Input.Keys.DPAD_UP)
            //               particleCount += 5;
            //            else if (keycode == Input.Keys.DPAD_DOWN)
            //               particleCount -= 5;
            //            else if (keycode == Input.Keys.SPACE) {
            emitterIndex = (emitterIndex + 1) % emitters.size;
            emitter = emitters.get(emitterIndex);
            particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f);
            //            } else
            //               return false;
            particleCount = Math.max(0, particleCount);
            if (particleCount > emitter.getMaxParticleCount())
                emitter.setMaxParticleCount(particleCount * 2);
            emitter.getEmission().setHigh(particleCount / emitter.getLife().getHighMax() * 1000);
            effect.getEmitters().clear();
            effect.getEmitters().add(emitter);

            effect.setPosition(x, Gdx.graphics.getHeight() - y);

        }

        @Override
        public void touchDrop(int x, int y) {
            // TODO Auto-generated method stub

        }
    };

    Gdx.input.setInputProcessor(inputProcessor);
}

From source file:com.hajnar.GravityShip.GameWorld.java

License:Apache License

public GameWorld() {
    state = WORLD_RUNNING;/* ww w  .j  a va  2s.com*/

    thrustParticleEffect = new ParticleEffect();
    thrustParticleEffect.load(Gdx.files.internal("data/thrust.p"), Gdx.files.internal("data"));
    thrustParticleEmitters = thrustParticleEffect.getEmitters();
    explosionParticleEffect = new ParticleEffect();
    explosionParticleEffect.load(Gdx.files.internal("data/explossion.p"), Gdx.files.internal("data"));
    explosionParticleEmitters = explosionParticleEffect.getEmitters();
    starsParticleEffect = new ParticleEffect();
    starsParticleEffect.load(Gdx.files.internal("data/stars.p"), Gdx.files.internal("data"));
    starsParticleEmitters = starsParticleEffect.getEmitters();

    landingZones = new ArrayList<LandingZone>();
    canons = new ArrayList<Canon>();
    bullets = new ArrayList<Bullet>();
    blackHoles = new ArrayList<BlackHole>();
    stars = new ArrayList<Star>();
    objectsToDestroy = new ArrayList<GameObject>();
    collidingObjects = new GameObject[2];

    landedZoneType = 0;
    landedDuration = 0;
    firePauseDuration = 0;
    startFuelAmmount = 0;
    canonsFireInterval = 0;

    tmpVector = new Vector2();
}

From source file:com.kimmyj.lwp.example.LiveWallpaperProgram.java

License:Apache License

@Override
public void create() {
    width = Gdx.graphics.getWidth();//from w  ww  .java2s  . co m
    height = Gdx.graphics.getHeight();
    mCamera = new OrthographicCamera(width, height);
    mEffect = new ParticleEffect();
    mEffect.load(Gdx.files.internal("data/stars"), Gdx.files.internal("data"));
    mEffect.setPosition(width / 2, height / 2);
    mBatch = new SpriteBatch();
    mBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
    mBatch.setProjectionMatrix(mCamera.combined);
}

From source file:com.kotcrab.vis.editor.module.project.ParticleCacheModule.java

License:Apache License

private ParticleEffect get(FileHandle file, float scaleFactor) {
    ParticleEffect effect = new ParticleEffect();

    try {//from  w ww  .j  a  v a2s  .c  om
        effect.load(file, file.parent());
    } catch (GdxRuntimeException e) {
        throw new EditorRuntimeException(e);
    }

    effect.scaleEffect(scaleFactor);
    return effect;
}

From source file:com.kotcrab.vis.editor.module.scene.system.inflater.EditorParticleInflater.java

License:Apache License

@Override
protected void inserted(int entityId) {
    AssetReference assetRef = assetCm.get(entityId);
    ProtoVisParticle protoComponent = protoCm.get(entityId);

    VisParticle particle = partcielCm.create(entityId);

    try {//from w w w  .  j a  v a 2 s  .  c om
        particle.setEffect(particleCache.get(assetRef.asset, 1f / pixelsPerUnit));
    } catch (EditorRuntimeException e) {
        Log.exception(e);
        particle.setEffect(new ParticleEffect());
        loadingMonitor.addFailedResource(assetRef.asset, e);
    }

    protoComponent.fill(particle);

    protoCm.remove(entityId);
}

From source file:com.lynk.gdx.tool.particleeditor.EffectPanel.java

License:Apache License

void openEffect(boolean mergeIntoCurrent) {
    FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD);
    if (lastDir != null)
        dialog.setDirectory(lastDir);//  ww w .java  2 s  .  co  m
    dialog.setVisible(true);
    final String file = dialog.getFile();
    final String dir = dialog.getDirectory();
    if (dir == null || file == null || file.trim().length() == 0)
        return;
    lastDir = dir;
    ParticleEffect effect = new ParticleEffect();
    try {
        File effectFile = new File(dir, file);
        effect.loadEmitters(Gdx.files.absolute(effectFile.getAbsolutePath()));
        if (mergeIntoCurrent) {
            for (ParticleEmitter emitter : effect.getEmitters()) {
                addEmitter(emitter.getName(), false, emitter);
            }
        } else {
            editor.effect = effect;
            editor.effectFile = effectFile;
        }
        emitterTableModel.getDataVector().removeAllElements();
        editor.particleData.clear();
    } catch (Exception ex) {
        System.out.println("Error loading effect: " + new File(dir, file).getAbsolutePath());
        ex.printStackTrace();
        JOptionPane.showMessageDialog(editor, "Error opening effect.");
        return;
    }
    for (ParticleEmitter emitter : editor.effect.getEmitters()) {
        emitter.setPosition(editor.worldCamera.viewportWidth / 2, editor.worldCamera.viewportHeight / 2);
        emitterTableModel.addRow(new Object[] { emitter.getName(), true });
    }
    editIndex = 0;
    emitterTable.getSelectionModel().setSelectionInterval(editIndex, editIndex);
    editor.reloadRows();
}

From source file:com.maplescot.loggerbill.game.LoggerEngine.java

License:Creative Commons License

@Override
public void init() {
    BackgroundScenery.getInstance().init();

    Gdx.app.debug(TAG, "Compiling Shaders");

    ghostShader = new ShaderProgram(Gdx.files.internal(VERTEX_SHADER), Gdx.files.internal(FRAG_SHADER));
    if (!ghostShader.isCompiled()) {
        String msg = "Could not compile shader program: " + ghostShader.getLog();
        throw new GdxRuntimeException(msg);
    }//from   w  w w . ja va  2 s .  co  m

    nightShader = new ShaderProgram(Gdx.files.internal(NIGHT_VERTEX_SHADER),
            Gdx.files.internal(NIGHT_FRAG_SHADER));

    if (!nightShader.isCompiled()) {
        String msg = "Could not compile shader program: " + nightShader.getLog();
        throw new GdxRuntimeException(msg);
    }

    chips = new ParticleEffect();
    chips.load(Gdx.files.internal("particles/chips.pfx"), Gdx.files.internal("particles"));
    pausedDialog = new PausedDialog(this);

    // Calculate multiplier for relative screen coords.
    xMul = VIEWPORT_GUI_WIDTH / Gdx.graphics.getWidth();
    yMul = getViewportHeight() / Gdx.graphics.getHeight();
}