Search in sources :

Example 1 with ParticleEffect

use of com.badlogic.gdx.graphics.g2d.ParticleEffect in project libgdx by libgdx.

the class EffectPanel method openEffect.

void openEffect(boolean mergeIntoCurrent) {
    FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD);
    if (lastDir != null)
        dialog.setDirectory(lastDir);
    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();
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) ParticleEmitter(com.badlogic.gdx.graphics.g2d.ParticleEmitter) File(java.io.File)

Example 2 with ParticleEffect

use of com.badlogic.gdx.graphics.g2d.ParticleEffect in project libgdx by libgdx.

the class ParticleEmitterTest method create.

@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();
    effect.getEmitters().add(emitters.get(0));
    inputProcessor = new InputProcessor() {

        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);
            ParticleEmitter emitter = emitters.get(emitterIndex);
            particleCount += 100;
            System.out.println(particleCount);
            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;
        }

        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);
                // if we've previously stopped the emitter reset it
                if (emitter.isComplete())
                    emitter.reset();
                particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f);
            } else if (keycode == Input.Keys.ENTER) {
                emitter = emitters.get(emitterIndex);
                if (emitter.isComplete())
                    emitter.reset();
                else
                    emitter.allowCompletion();
            } 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 mouseMoved(int x, int y) {
            return false;
        }

        @Override
        public boolean scrolled(int amount) {
            return false;
        }
    };
    Gdx.input.setInputProcessor(inputProcessor);
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) Array(com.badlogic.gdx.utils.Array) ParticleEmitter(com.badlogic.gdx.graphics.g2d.ParticleEmitter) InputProcessor(com.badlogic.gdx.InputProcessor) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 3 with ParticleEffect

use of com.badlogic.gdx.graphics.g2d.ParticleEffect in project Entitas-Java by Rubentxu.

the class Mariano method create.

@Override
public GameEntity create(Engine engine, Entitas entitas) {
    PhysicsManagerGDX physics = engine.getManager(PhysicsManagerGDX.class);
    BodyBuilder bodyBuilder = physics.getBodyBuilder();
    TextureAtlas textureAtlas = assetsManager.getTextureAtlas(atlas);
    ParticleEffect dustEffect = assetsManager.get(effect, ParticleEffect.class);
    Array<TextureAtlas.AtlasRegion> heroWalking = textureAtlas.findRegions("Andando");
    Array<TextureAtlas.AtlasRegion> heroJump = textureAtlas.findRegions("Saltando");
    Array<TextureAtlas.AtlasRegion> heroFall = textureAtlas.findRegions("Cayendo");
    Array<TextureAtlas.AtlasRegion> heroIdle = textureAtlas.findRegions("Parado");
    Map<String, Animation<TextureRegion>> animationStates = EntitasCollections.createMap(String.class, Animation.class);
    animationStates.put("walking", new Animation(0.02f, heroWalking, Animation.PlayMode.LOOP));
    animationStates.put("jump", new Animation(0.02f * 7, heroJump, Animation.PlayMode.NORMAL));
    animationStates.put("fall", new Animation(0.02f * 5, heroFall, Animation.PlayMode.NORMAL));
    animationStates.put("idle", new Animation(0.02f * 4, heroIdle, Animation.PlayMode.LOOP));
    Body bodyPlayer = bodyBuilder.fixture(bodyBuilder.fixtureDefBuilder().boxShape(0.35f, 1).density(1)).type(BodyDef.BodyType.DynamicBody).fixedRotation().position(0, 5).mass(1).build();
    GameEntity entity = entitas.game.createEntity();
    entity.addRigidBody(bodyPlayer).addAnimations(animationStates, animationStates.get("idle"), 0).addTags("Mariano").setInteractive(true).addTextureView(null, new Bounds(0.9f, 1.15f), false, false, 1, 1, Color.WHITE).addInputController((inputManager, context) -> {
        boolean isGround = false;
        SensorEntity sensor = Indexed.getSensorsEntity(entity, "CollisionGround");
        if (sensor.getCollisionSensor().collisionSignal)
            isGround = true;
        Vector2 impulse = new Vector2();
        if (inputManager.isKeyDown(Input.Keys.D)) {
            impulse.x = 2;
            if (isGround)
                entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("walking");
            entity.getTextureView().flipX = false;
        } else if (inputManager.isKeyDown(Input.Keys.A)) {
            impulse.x = -2;
            if (isGround)
                entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("walking");
            entity.getTextureView().flipX = true;
        }
        if (inputManager.isKeyDown(Input.Keys.W)) {
            if (isGround)
                impulse.y = 4;
            entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("jump");
        }
        Vector2 vel = bodyPlayer.getLinearVelocity();
        if (!inputManager.isKeyDown(Input.Keys.A) && !inputManager.isKeyDown(Input.Keys.D) && isGround) {
            bodyPlayer.setLinearVelocity(new Vector2(0, vel.y));
            entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("idle");
        }
        if (Math.abs(vel.x) > 7) {
            vel.x = Math.signum(vel.x) * 7;
            bodyPlayer.setLinearVelocity(new Vector2(vel.x, vel.y));
        }
        if (!isGround && vel.y < 0) {
            entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("fall");
        }
        bodyPlayer.applyLinearImpulse(impulse, bodyPlayer.getWorldCenter(), false);
    });
    entitas.sensor.createEntity().addCollisionSensor("Ground").addLink(entity.getCreationIndex(), "CollisionGround");
    entitas.actuator.createEntity().addCameraActuator(((EngineGDX) engine).getCamera(), (short) 0.3f, 0.08f, 6, 1, "Mariano").addLink(entity.getCreationIndex(), "CameraActuator", true);
    entitas.actuator.createEntity().addParticleEffectActuator(dustEffect, true, -1, -1).addLink(entity.getCreationIndex(), "EffectActuator", true);
    return entity;
}
Also used : Bounds(ilargia.egdx.logicbricks.data.Bounds) EngineGDX(ilargia.egdx.impl.EngineGDX) BodyBuilder(ilargia.egdx.util.BodyBuilder) PhysicsManagerGDX(ilargia.egdx.impl.managers.PhysicsManagerGDX) ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Animation(com.badlogic.gdx.graphics.g2d.Animation) Body(com.badlogic.gdx.physics.box2d.Body)

Example 4 with ParticleEffect

use of com.badlogic.gdx.graphics.g2d.ParticleEffect in project libgdx by libgdx.

the class ParticleEffectLoader method load.

@Override
public ParticleEffect load(AssetManager am, String fileName, FileHandle file, ParticleEffectParameter param) {
    ParticleEffect effect = new ParticleEffect();
    if (param != null && param.atlasFile != null)
        effect.load(file, am.get(param.atlasFile, TextureAtlas.class), param.atlasPrefix);
    else if (param != null && param.imagesDir != null)
        effect.load(file, param.imagesDir);
    else
        effect.load(file, file.parent());
    return effect;
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect)

Example 5 with ParticleEffect

use of com.badlogic.gdx.graphics.g2d.ParticleEffect in project libgdx by libgdx.

the class ParticleEmittersTest method render.

public void render() {
    ui.act();
    spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    float delta = Gdx.graphics.getDeltaTime();
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    spriteBatch.begin();
    for (ParticleEffect e : effects) e.draw(spriteBatch, delta);
    spriteBatch.end();
    fpsCounter += delta;
    if (fpsCounter > 3) {
        fpsCounter = 0;
        String log = effects.size + " particle effects, FPS: " + Gdx.graphics.getFramesPerSecond() + ", Render calls: " + spriteBatch.renderCalls;
        Gdx.app.log("libgdx", log);
        logLabel.setText(log);
    }
    ui.draw();
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect)

Aggregations

ParticleEffect (com.badlogic.gdx.graphics.g2d.ParticleEffect)6 InputProcessor (com.badlogic.gdx.InputProcessor)2 ParticleEmitter (com.badlogic.gdx.graphics.g2d.ParticleEmitter)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 Animation (com.badlogic.gdx.graphics.g2d.Animation)1 ParticleEffectPool (com.badlogic.gdx.graphics.g2d.ParticleEffectPool)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Body (com.badlogic.gdx.physics.box2d.Body)1 Array (com.badlogic.gdx.utils.Array)1 EngineGDX (ilargia.egdx.impl.EngineGDX)1 PhysicsManagerGDX (ilargia.egdx.impl.managers.PhysicsManagerGDX)1 Bounds (ilargia.egdx.logicbricks.data.Bounds)1 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)1 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)1 BodyBuilder (ilargia.egdx.util.BodyBuilder)1 File (java.io.File)1