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 void act(float delta){ battleTimer = (battleTimer + delta)%60; if( damageValLabel.isVisible() && damageValLabel.getY() < this.getHeight()){ damageValLabel.setY(damageValLabel.getY()+5); } if( battleShakeCam != null && battleShakeCam.isCameraShaking() ){ Vector2 shakeCoords = battleShakeCam.getNewShakePosition(); _image.setPosition(shakeCoords.x, shakeCoords.y); } for( int i = 0; i < _effects.size; i++){ ParticleEffect effect = _effects.get(i); if( effect == null ) continue; if( effect.isComplete() ){ _effects.removeIndex(i); effect.dispose(); }else{ effect.update(delta); } } super.act(delta); }
public static ParticleEffect getParticleEffect(ParticleEffectType particleEffectType, float positionX, float positionY){ ParticleEffect effect = new ParticleEffect(); effect.load(Gdx.files.internal(particleEffectType.getValue()), Gdx.files.internal(SFX_ROOT_DIR)); effect.setPosition(positionX, positionY); switch(particleEffectType){ case CANDLE_FIRE: effect.scaleEffect(1.6f); break; case LANTERN_FIRE: effect.scaleEffect(.6f); break; case LAVA_SMOKE: effect.scaleEffect(1.6f); break; case WAND_ATTACK: effect.scaleEffect(4.0f); break; default: break; } effect.start(); return effect; }
public Shoot(String nameTexture, int x, int y, GameObject shooter, ParticleEffect shootEffect, ParticleEffect destroyEffect, String shootFX) { super(nameTexture,x,y); this.shooter = shooter; shocked = false; originalShootPosition = new Vector2(x,y); //Creamos los efectos de partículas si no vienen nulos if (shootEffect != null) { this.shootEffect = shootEffect; shootEffect.start(); } if (destroyEffect != null) { this.destroyEffect = destroyEffect; destroyEffect.start(); } this.shootFX = shootFX; }
public Enemy(String textureName, int x, int y, int vitality, ParticleEffect destroyEffect) { super(textureName, x, y); initialPosition = new Vector2(x,y); this.vitality = vitality; deletable = false; this.destroyEffect = destroyEffect; timeToFlick = 0; timeForInvisible = RANGE_INVISIBLE_TIMER; targettedByShip = false; if(this.destroyEffect != null){ this.destroyEffect.getEmitters().first().setPosition(this.getX() + this.getWidth()/2, this.getY() + this.getHeight()/2); this.destroyEffect.start(); } }
public Car(String name, String lane, Texture texture, Vector2 pos, Vector2 direction) { super(texture, pos, direction); this.eType = 1; if(name.equals("CAR1")){ carWidth = TextureManager.CAR1.getWidth(); carHeight = TextureManager.CAR1.getHeight(); }else if(name.equals("CAR2")){ carWidth = TextureManager.CAR2.getWidth(); carHeight = TextureManager.CAR2.getHeight(); } smokeEffect = new ParticleEffect(); smokeEffect.load(Gdx.files.internal("effects/car_smoke_1.p"), Gdx.files.internal("effect_img")); smokeEffect.setPosition(this.pos.x + carWidth / 2, this.pos.y + carHeight / 10 ); smokeEffect.start(); }
public ActuatorEntity addParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) { ParticleEffectActuator component = (ParticleEffectActuator) recoverComponent(ActuatorComponentsLookup.ParticleEffectActuator); if (component == null) { component = new ParticleEffectActuator(effect, autoStart, locaPosX, locaPosY); } else { component.particleEffect = effect; component.actuator = (indexOwner) -> { GameEntity owner = Indexed.getInteractiveEntity(indexOwner); RigidBody rc = owner.getRigidBody(); Transform transform = rc.body.getTransform(); effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY); effect.update(Gdx.graphics.getDeltaTime()); if (autoStart && effect.isComplete()) effect.start(); }; } addComponent(ActuatorComponentsLookup.ParticleEffectActuator, component); return this; }
public ActuatorEntity replaceParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) { ParticleEffectActuator component = (ParticleEffectActuator) recoverComponent(ActuatorComponentsLookup.ParticleEffectActuator); if (component == null) { component = new ParticleEffectActuator(effect, autoStart, locaPosX, locaPosY); } else { component.particleEffect = effect; component.actuator = (indexOwner) -> { GameEntity owner = Indexed.getInteractiveEntity(indexOwner); RigidBody rc = owner.getRigidBody(); Transform transform = rc.body.getTransform(); effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY); effect.update(Gdx.graphics.getDeltaTime()); if (autoStart && effect.isComplete()) effect.start(); }; } replaceComponent(ActuatorComponentsLookup.ParticleEffectActuator, component); return this; }
public void addEffect(String name, Vector2 position, float angle){ logger.debug("Creating effect: " + name); ParticleEffect effect = App.assets.getEffect(name); if (effect == null) { logger.error("Couldn't create particle effect: " + name); return; } ParticleEffect e = new ParticleEffect(effect); for (ParticleEmitter emitter : e.getEmitters()){ float a1 = emitter.getAngle().getHighMin(), a2 = emitter.getAngle().getHighMax(); emitter.getRotation().setHighMin(a1 + angle); emitter.getRotation().setHighMax(a2 + angle); } e.setPosition(position.x * App.engine.PIXELS_PER_METER, position.y * App.engine.PIXELS_PER_METER); e.start(); effects.add(e); }
@Override public ParticleEffect getOrLoad(final String id) { final String[] data = Strings.split(id, '$'); if (data.length == 0) { throwUnknownPathException(); } final String path = determinePath(data[0]); getIdsToPaths().put(id, path); final AssetManager assetManager = getAssetManager(); if (assetManager.isLoaded(path)) { return assetManager.get(path, getType()); } if (data.length > 1) { final String atlasName = TextureAtlasProvider.getTextureAtlasPath(data[1]); final ParticleEffectParameter parameters = new ParticleEffectParameter(); parameters.atlasFile = atlasName; assetManager.load(path, ParticleEffect.class, parameters); } else { assetManager.load(path, ParticleEffect.class); } return null; }
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); } }
/** Creates a new AssetManager with all default loaders. */ public AssetManager (FileHandleResolver resolver) { setLoader(BitmapFont.class, new BitmapFontLoader(resolver)); setLoader(Music.class, new MusicLoader(resolver)); setLoader(Pixmap.class, new PixmapLoader(resolver)); setLoader(Sound.class, new SoundLoader(resolver)); setLoader(TextureAtlas.class, new TextureAtlasLoader(resolver)); setLoader(Texture.class, new TextureLoader(resolver)); setLoader(Skin.class, new SkinLoader(resolver)); setLoader(ParticleEffect.class, new ParticleEffectLoader(resolver)); setLoader(PolygonRegion.class, new PolygonRegionLoader(resolver)); setLoader(I18NBundle.class, new I18NBundleLoader(resolver)); setLoader(Model.class, ".g3dj", new G3dModelLoader(new JsonReader(), resolver)); setLoader(Model.class, ".g3db", new G3dModelLoader(new UBJsonReader(), resolver)); setLoader(Model.class, ".obj", new ObjLoader(resolver)); executor = new AsyncExecutor(1); }
public FireWorksLayer(GameGrid gameGrid) { super(); gameGrid.events().register(this); TutorialEngine.instance().eventBus().register(this); AchievementEngine.instance().eventBus().register(this); ParticleEffect particleEffect = new ParticleEffect(); particleEffect.load(Gdx.files.internal("particles/firework.p"), Gdx.files.internal("particles")); Set<float[]> colors = Sets.newHashSet(); colors.add(makeParticleColorArray(Color.WHITE, Color.RED, Color.ORANGE)); colors.add(makeParticleColorArray(Color.WHITE, Color.BLUE, Color.GREEN)); colors.add(makeParticleColorArray(Color.WHITE, Color.YELLOW, Color.PINK)); colors.add(makeParticleColorArray(Color.WHITE, Color.PINK, Color.MAGENTA)); colors.add(makeParticleColorArray(Color.WHITE, Color.BLUE, Color.CYAN)); colorsIterator = Iterators.cycle(colors); worldBounds = new Rectangle(); for (int i = 0; i < 10; i++) { addChild(new ParticleEffectManager(new ParticleEffect(particleEffect), colorsIterator, worldBounds)); } }
@Override public boolean match(FileHandle file) { boolean result = file.extension().equals("p"); if(result) { Engine.getAssetManager().load(file.path().replace("\\", "/"),ParticleEffect.class); return result; } result = file.extension().equals("pp"); if(result) { ParticleEffectParameter parameter = new ParticleEffectParameter(); parameter.atlasFile = file.pathWithoutExtension().replace("\\", "/")+".atlas"; Engine.getAssetManager().load(file.path().replace("\\", "/"),ParticleEffect.class,parameter); return result; } return false; }
public AchievementButton(TextureAtlas hudAtlas, AchievementEngine achievementEngine) { super(hudAtlas.findRegion("achievements"), Colors.ICS_BLUE); activeAnimation = new Animation(ANIMATION_DURATION, hudAtlas.findRegions("achievements-active")); nextAnimationTime = 0; particleEffect = new ParticleEffect(); particleEffect.load(Gdx.files.internal("particles/sparkle.p"), Gdx.files.internal("particles")); addListener(new VibrateClickListener() { public void onClick(InputEvent event, float x, float y) { new AchievementListView(getStage()).show(); } }); setVisible(false); }
/** * Set particle for this actor, centerPosition is used to center the * particle on this actor sizes. * * @param particleEffect the particle effect * @param isParticleEffectActive the is particle effect active * @param isStart the is start * @param centerPosition the center position */ public void setParticleEffect(ParticleEffect particleEffect, boolean isParticleEffectActive, boolean isStart, boolean centerPosition) { this.particleEffect = particleEffect; this.isParticleEffectActive = isParticleEffectActive; if (!centerPosition) { this.particleEffect.setPosition(getX(), getY()); } else { particlePosX = getWidth() / 2.0f; particlePosY = getHeight() / 2.0f; this.particleEffect.setPosition(getX() + particlePosX, getY() + particlePosY); } if (isStart) { this.particleEffect.start(); } }
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; }
public void enqueueAssets() { // Textures manager.load(PlayerTex, Texture.class); manager.load(CoinTex, Texture.class); // Particles manager.load(CoinPrt, ParticleEffect.class); // Fonts manager.load(DefaultFnt, BitmapFont.class); // Skins manager.load(DefaultSkin, Skin.class); // Sounds manager.load(CoinSound, Sound.class); manager.load(FinishSound, Sound.class); }
@Override public void update(float deltaTime) { Gdx.gl.glClearColor(bgColour[0], bgColour[1], bgColour[2], bgColour[3]); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); super.update(deltaTime); for (ParticleEffect particle : particles) particle.draw(batch, deltaTime); batch.end(); if (ZeroBit.debugEnabled) { shapeRenderer.setProjectionMatrix(camera.combined); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); for (Entity entity : getEntities()) debugRender(entity); shapeRenderer.end(); } }
/** * Adds a ParticleEffect from a ParticleEffectVO. Uses ParticleEmitterBox2D * @param item ParticleEffectVO to add */ private static void addParticle(ParticleEffectVO item) { ParticleEffect particleEffect = new ParticleEffect(); particleEffect.load(Gdx.files.internal(particlesPath + "/" + item.particleName), atlas); particleEffect.scaleEffect(ZeroBit.pixelsToMeters * item.scaleX); for (int i=0; i < particleEffect.getEmitters().size; i++) { particleEffect.getEmitters().set(i, new ParticleEmitterBox2D(b2dSystem.getB2World(), particleEffect.getEmitters().get(i))); ParticleEmitter emitter = particleEffect.getEmitters().get(i); // Spawn scaling doesn't seem to alter the actual dimensions of the effect like in the editor /*emitter.getSpawnWidth().setHigh(emitter.getSpawnWidth().getHighMin() * item.scaleX, emitter.getSpawnWidth().getHighMax() * item.scaleX); emitter.getSpawnWidth().setLow(emitter.getSpawnWidth().getLowMin() * item.scaleX, emitter.getSpawnWidth().getLowMax() * item.scaleX); emitter.getSpawnHeight().setHigh(emitter.getSpawnHeight().getHighMin() * item.scaleY, emitter.getSpawnHeight().getHighMax() * item.scaleY); emitter.getSpawnHeight().setLow(emitter.getSpawnHeight().getLowMin() * item.scaleY, emitter.getSpawnHeight().getLowMax() * item.scaleY);*/ emitter.setPosition(item.x * ZeroBit.pixelsToMeters, item.y * ZeroBit.pixelsToMeters); } //entityManager.getEngine().getSystem(RenderingSystem.class).addParticle(particleEffect); ParticleComponent pc = new ParticleComponent(); pc.addParticle(particleEffect); addEntity(item, null, pc, new VisualComponent()); }
@Override public void loadAssets() { loader.parseLevel(world); game.assets.manager.load("data/hud/hud.pack", TextureAtlas.class); game.assets.manager.load("data/hud/controls.pack", TextureAtlas.class); game.assets.manager.load("data/maryo/small.pack", TextureAtlas.class); game.assets.manager.load("data/game/logo/smc_big_1.png", Texture.class, game.assets.textureParameter); game.assets.manager.load("data/game/background/more_hills.png", Texture.class, game.assets.textureParameter); game.assets.manager.load("data/sounds/audio_on.mp3", Sound.class); cloudsPEffect = new ParticleEffect(); cloudsPEffect.load(game.assets.resolver.resolve("data/animation/particles/clouds_emitter.p"), game.assets.resolver.resolve("data/clouds/default_1/")); cloudsPEffect.setPosition(Constants.MENU_CAMERA_WIDTH / 2, Constants.MENU_CAMERA_HEIGHT); cloudsPEffect.start(); game.assets.manager.load("data/hud/lock.png", Texture.class, game.assets.textureParameter); exitDialog.loadAssets(); settingsDialog.loadAssets(); }
private static Item createFireplant(Box box, boolean loadAssets, Assets assets) { if(loadAssets) { assets.manager.load("data/animation/particles/box_activated.p", ParticleEffect.class, assets.particleEffectParameter); assets.manager.load("data/sounds/item/fireplant.mp3", Sound.class); assets.manager.load("data/game/items/fireplant.pack", TextureAtlas.class); assets.manager.load("data/animation/particles/fireplant_emitter.p", ParticleEffect.class, assets.particleEffectParameter); } else { Vector2 size = new Vector2(Fireplant.DEF_SIZE, Fireplant.DEF_SIZE); Vector3 pos = new Vector3(box.position); pos.x = box.position.x + box.mDrawRect.width * 0.5f - size.x * 0.5f; Fireplant fireplant = new Fireplant(box.world, size, pos); fireplant.initAssets(); fireplant.visible = false; return fireplant; } return null; }
public static Item createMoon(World world, Vector3 position, boolean loadAssets, Assets assets, boolean initAssets) { if(loadAssets) { assets.manager.load("data/animation/particles/box_activated.p", ParticleEffect.class, assets.particleEffectParameter); assets.manager.load("data/game/items/moon.pack", TextureAtlas.class); assets.manager.load("data/sounds/item/moon.mp3", Sound.class); } else { Moon moon = new Moon(world, new Vector2(Moon.DEF_SIZE, Moon.DEF_SIZE), new Vector3(position)); if(initAssets)moon.initAssets(); moon.visible = false; return moon; } return null; }
public static Item createStar(World world, Vector3 position, boolean loadAssets, Assets assets, boolean initAssets) { if(loadAssets) { assets.manager.load("data/animation/particles/box_activated.p", ParticleEffect.class, assets.particleEffectParameter); assets.manager.load("data/game/items/star.png", Texture.class, assets.textureParameter); } else { Star star = new Star(world, new Vector2(Star.DEF_SIZE, Star.DEF_SIZE), new Vector3(position)); if(initAssets)star.initAssets(); star.visible = false; return star; } return null; }
public Assets() { textureParameter = new TextureLoader.TextureParameter(); //textureParameter.genMipMaps = true; textureParameter.magFilter = Texture.TextureFilter.Linear; textureParameter.minFilter = Texture.TextureFilter.Linear; resolver = new MaryoFileHandleResolver(); manager = new AssetManager(resolver); particleEffectParameter = new ParticleEffectLoader.ParticleEffectParameter(); particleEffectParameter.imagesDir = resolver.resolve("data/animation/particles"); // set the loaders for the generator and the fonts themselves manager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver)); manager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver)); manager.setLoader(ParticleEffect.class, ".p", new ParticleEffectLoader(resolver)); manager.setLoader(Sound.class, ".mp3", new SoundLoader(new InternalFileHandleResolver())); manager.setLoader(Music.class, ".mp3", new MusicLoader(new InternalFileHandleResolver())); }
@Override protected void process (int entityId) { VisParticle particle = particleCm.get(entityId); Transform transform = transformCm.get(entityId); ParticleEffect effect = particle.getEffect(); if (transform.isDirty()) { particle.updateValues(transform.getX(), transform.getY()); } if (ignoreActive || particle.isActiveOnStart()) effect.update(world.delta); effect.draw(batch); if (effect.isComplete()) effect.reset(); }
@Override protected void inserted (int entityId) { AssetReference assetRef = assetCm.get(entityId); ProtoVisParticle protoComponent = protoCm.get(entityId); VisParticle particle = partcielCm.create(entityId); try { 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); }
@Override public void onRemoveTrailColor(MonsterColor color) { Maze maze = color.getMonster().getMaze(); ParticleEffect effect = manager.create(Assets.getInstance().get(Assets.FLARE, ParticleEffect.class), false); float x = color.getX() * maze.getBlockSize() + maze.getX() + maze.getBlockSize() / 2; float y = color.getY() * maze.getBlockSize() + maze.getY() + maze.getBlockSize() / 2; effect.setPosition(x, y); manager.setColor(effect, new float[]{color.r, color.g, color.b}, new float[]{0f}); effect.start(); for (ParticleEmitter e : effect.getEmitters()) { e.getScale().setLow(Gdx.graphics.getWidth() / 30f); e.getDuration().setLow(Monster.LENGTH * StupidMonsterLogic.INTERVAL / 104); e.getLife().setLow(Monster.LENGTH * StupidMonsterLogic.INTERVAL / 140); e.getDuration().setLowMin(Monster.LENGTH * StupidMonsterLogic.INTERVAL / 140); e.getLife().setLowMin(Monster.LENGTH * StupidMonsterLogic.INTERVAL / 140); e.getVelocity().setLow(Gdx.graphics.getWidth() / 50f); } effects.put(color, effect); Gdx.input.vibrate(20); }
@Override public void onMove(GameObject object) { ParticleEffect effect = effects.get(object); Integer count = particleCounts.get(object); if (effect != null) { if (object.isIced()) { if (particleManager.getParticleCount(effect) == count) { particleManager.setParticleCount(effect, count / 20); } } else { if (particleManager.getParticleCount(effect) != count) { particleManager.setParticleCount(effect, count); } } if (object.getType().equals(GameObjectType.ALIEN)) { effect.setPosition(object.getCenterX(), object.getCenterY() + object.getHeight() / 3f); } else { effect.setPosition(object.getCenterX(), object.getCenterY()); } } }
@Override public void onCreateColor(Monster monster, MonsterColor color) { ParticleEffect effect = manager.create(Assets.getInstance().get(Assets.FLARE, ParticleEffect.class), false); Maze maze = monster.getMaze(); float x = color.getX() * maze.getBlockSize() + maze.getX() + maze.getBlockSize() / 2; float y = color.getY() * maze.getBlockSize() + maze.getY() + maze.getBlockSize() / 2; effect.setPosition(x, y); manager.setColor(effect, new float[]{color.r, color.g, color.b}, new float[]{0f}); effect.start(); for (ParticleEmitter e : effect.getEmitters()) { e.getScale().setLow(Gdx.graphics.getWidth() / 100f); e.getDuration().setLow(Monster.LENGTH * StupidMonsterLogic.INTERVAL); e.getLife().setLow(Monster.LENGTH * StupidMonsterLogic.INTERVAL); e.getDuration().setLowMin(Monster.LENGTH * StupidMonsterLogic.INTERVAL); e.getLife().setLowMin(Monster.LENGTH * StupidMonsterLogic.INTERVAL); e.getVelocity().setLow(Gdx.graphics.getWidth() / 300f); } effects.put(color, effect); }
@Override public void setAlpha(float alpha) { // TODO: Alpha doesn't work for particles here as intended :( this.alpha = alpha; for (ParticleEffect e : effects.keySet()) { for (ParticleEmitter emitter : e.getEmitters()) { ScaledNumericValue v = emitter.getTransparency(); v.setHigh(alpha); v.setLow(alpha); } } }
@Override public void processActuator(EffectActuator actuator, float deltaTime) { ParticleEffectView view = actuator.effectView; ParticleEffect effect = view.effect; if (actuator.active) { Log.debug(tag, "Effect reset"); effect.reset(); } else { Log.debug(tag, "Effect allowCompletion"); effect.allowCompletion(); } if (actuator.opacity != -1) view.setOpacity(actuator.opacity); if (actuator.tint != null) view.setTint(actuator.tint); if (actuator.position != null) { if (view.attachedTransform != null) view.setLocalPosition(actuator.position); else view.setPosition(actuator.position); } }
/** * 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 onInit(BaseGame game, Entity entity) { // create new particle effect this.particleEffect = new ParticleEffect(); // load effect game.getAssetManager().load(this.particleEffectFile, ParticleEffect.class); game.getAssetManager().finishLoadingAsset(this.particleEffectFile); this.particleEffect = game.getAssetManager().get(this.particleEffectFile, ParticleEffect.class); if (this.autoStart) { // start particle effect this.particleEffect.start(); } }
public static void draw() { GameMain.instance.activeStage.getBatch().begin(); for (ParticleEffect particleEffect : effects) { particleEffect.draw(GameMain.instance.activeStage.getBatch()); particleEffect.update(Gdx.graphics.getDeltaTime()); } GameMain.instance.activeStage.getBatch().end(); }
@Override public void create() { game_prefs = Gdx.app.getPreferences(prefs_name); game_stage = new Stage(view); game_states = new ObjectMap<String, GameState>(); game_stage.setDebugAll(false); current_gamestates = new Array<GameState>(); transition_state = new GameState(null); transition_state.setGame(this); assets = new AssetManager(); assets.setLoader(TiledMap.class, new KyperMapLoader(assets.getFileHandleResolver())); assets.setLoader(ParticleEffect.class, new ParticleEffectLoader(assets.getFileHandleResolver())); assets.setLoader(ShaderProgram.class, new ShaderProgramLoader(assets.getFileHandleResolver(), VERTEX_SUFFIX, FRAGMENT_SUFFIX)); sound = new SoundManager(this); packages = new Array<String>(); packages.add("com.kyperbox.objects"); global_data = new UserData(GAME_DATA_NAME); input = new GameInput(); Gdx.input.setInputProcessor(game_stage); initiate(); }
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; } }
/** * Resets the position, start color and duration of the given firework effects to random values. * * @param effect */ private void resetFireworksEffect(ParticleEffect effect) { effect.reset(); effect.setDuration(Utils.randomWithin(180, 250)); effect.setPosition(Utils.randomWithin(0, WINDOW_WIDTH), Utils.randomWithin(0, WINDOW_HEIGHT)); float[] colors = effect.getEmitters().get(0).getTint().getColors(); int randomStartColor = Utils.randomWithin(0, startColors.length - 1); for (int i = 0; i < 6; i++) { colors[i] = startColors[randomStartColor][i % 3]; } for (ParticleEmitter emitter : effect.getEmitters()) { emitter.getTint().setColors(colors); } }