From b41d2b7b65f0d39d47ec5e782fb802bc7f0a5fa4 Mon Sep 17 00:00:00 2001 From: izure <=> Date: Fri, 25 Jun 2021 08:13:36 +0900 Subject: [PATCH] add actor.particle.addExists methods --- @common/Phaser/ActorParticle.ts | 78 +++------------------- @common/Phaser/Particle/DefaultParticle.ts | 4 +- @test/src/index.ts | 40 +++++------ 3 files changed, 29 insertions(+), 93 deletions(-) diff --git a/@common/Phaser/ActorParticle.ts b/@common/Phaser/ActorParticle.ts index 835e9e5..587f0ff 100644 --- a/@common/Phaser/ActorParticle.ts +++ b/@common/Phaser/ActorParticle.ts @@ -1,13 +1,4 @@ import Phaser from 'phaser' -import { ExplodeParticle } from './Particle/ExplodeParticle' -import { FireflyParticle } from './Particle/FireflyParticle' -import { GlitterParticle } from './Particle/GlitterParticle' -import { JetParticle } from './Particle/JetParticle' -import { SmokeParticle } from './Particle/SmokeParticle' -import { SparkParticle } from './Particle/SparkParticle' -import { BurnParticle } from './Particle/BurnParticle' -import { SnowParticle } from './Particle/SnowParticle' -import { RainParticle } from './Particle/RainParticle' type ParticleEmitterConfig = Phaser.Types.GameObjects.Particles.ParticleEmitterConfig type Actor = Phaser.GameObjects.GameObject&Phaser.GameObjects.Components.Transform @@ -86,70 +77,21 @@ export class ActorParticle { } /** - * 사전에 만들어진 파티클 효과를 추가합니다. - * 이는 간단하게 원하는 파티클 종류를 구현하고 싶을 때 사용할 수 있습니다. + * 이미 생성된 파티클 게임 오브젝트 인스턴스를 등록합니다. + * 이렇게 등록된 객체는 액터를 따라다니며, 액터가 파괴되었을 때 함께 파괴됩니다. * @param key 파티클 키입니다. - * @param type 구현하고 싶은 파티클의 종류입니다. - * @param texture 파티클에서 사용할 텍스쳐 키입니다. - * @param emitRadius 파티클이 생성되는 영역의 범위입니다. 파티클은 이 범위 내에서 랜덤하게 생성될 것입니다. - * @param isTop 파티클이 액터 위에 그려질 것인지 여부를 설정합니다. 기본값은 `false`입니다. - * @param config 파티클 설정입니다. `speed`, `lifespan`, `blendMode`, `scale` 등이 있습니다. 자세한 내용은 아래 링크를 참고하십시오. - * https://photonstorm.github.io/phaser3-docs/Phaser.Types.GameObjects.Particles.html#.ParticleEmitterConfig + * @param particle 존재하는 파티클 게임 오브젝트 인스턴스입니다. + * @@param isTop 파티클이 액터 위에 그려질 것인지 여부를 설정합니다. 기본값은 `false`입니다. */ - addPrebuilt(key: string, texture: string, type: 'explode'|'firefly'|'glitter'|'jet'|'smoke'|'spark'|'burn'|'snow'|'rain', emitRadius: number|undefined, isTop: boolean = false, config: ParticleEmitterConfig = {}): this { - const { x, y } = this.actor - - this.remove(key) + addExists(key: string, particle: Phaser.GameObjects.Particles.ParticleEmitterManager, isTop: boolean = false): this { + const emitter = particle.emitters.first + emitter.startFollow(this.actor) - let particle - - switch (type) { - case 'explode': { - particle = new ExplodeParticle(this.scene, x, y, emitRadius, texture, config) - break - } - case 'firefly': { - particle = new FireflyParticle(this.scene, x, y, emitRadius, texture, config) - break - } - case 'glitter': { - particle = new GlitterParticle(this.scene, x ,y, emitRadius, texture, config) - break - } - case 'jet': { - particle = new JetParticle(this.scene, x ,y, emitRadius, texture, config) - break - } - case 'smoke': { - particle = new SmokeParticle(this.scene, x ,y, emitRadius, texture, config) - break - } - case 'spark': { - particle = new SparkParticle(this.scene, x ,y, emitRadius, texture, config) - break - } - case 'burn': { - particle = new BurnParticle(this.scene, x, y, emitRadius, texture, config) - break - } - case 'snow': { - particle = new SnowParticle(this.scene, x, y, emitRadius, texture, config) - break - } - case 'rain': { - particle = new RainParticle(this.scene, x, y, emitRadius, texture, config) - break - } - } - - if (particle) { - const emitter = particle.emitters.first - const option = ActorParticle.createEmitterOption(emitter, isTop) + const option = ActorParticle.createEmitterOption(emitter, isTop) - this.emittermap.set(key, option) + this.remove(key) - emitter.startFollow(this.actor) - } + this.emittermap.set(key, option) return this } diff --git a/@common/Phaser/Particle/DefaultParticle.ts b/@common/Phaser/Particle/DefaultParticle.ts index d883291..f771014 100644 --- a/@common/Phaser/Particle/DefaultParticle.ts +++ b/@common/Phaser/Particle/DefaultParticle.ts @@ -67,9 +67,9 @@ export abstract class DefaultParticle extends Phaser.GameObjects.Particles.Parti ...useDefaultEmitterConfig(), ...config }) - emitter.setPosition(x, y).start() + emitter.start() } - + this.scene.add.existing(this) } } \ No newline at end of file diff --git a/@test/src/index.ts b/@test/src/index.ts index c5bfe8a..079ec7b 100644 --- a/@test/src/index.ts +++ b/@test/src/index.ts @@ -13,6 +13,7 @@ import { getIsometricSide } from '~/@common/Math/MathUtil' class User extends Actor { private hp: number = 100 + declare scene: Test constructor(name: string, scene: Phaser.Scene, x: number, y: number, texture: string) { super(scene, x, y, texture) @@ -132,7 +133,7 @@ class Player extends User { }) rocket.fireMissile(betweenAngle, 0.1, 0.01, actors[0]) - rocket.particle.addPrebuilt('flame', 'particle-flash', 'jet', 0, false) + rocket.particle.addExists('flame', this.scene.particle.addJet(0, 0)) return {} }) @@ -178,18 +179,18 @@ fps: ${this.game.loop.actualFps} } class Test extends Phaser.Scene { - private player: Player|null = null - private map!: IsomScenePlugin - private cursor!: IsomCursorPlugin - private select!: IsomSelectPlugin - private dialogue!: DialoguePlugin - private modal!: ModalPlugin - private actor!: ActorPlugin - private fow!: FowPlugin - private spatial!: SpatialAudioPlugin - private environment!: EnvironmentPlugin - private feeling!: FeelingPlugin - private particle!: ParticlePlugin + player: Player|null = null + map!: IsomScenePlugin + cursor!: IsomCursorPlugin + select!: IsomSelectPlugin + dialogue!: DialoguePlugin + modal!: ModalPlugin + actor!: ActorPlugin + fow!: FowPlugin + spatial!: SpatialAudioPlugin + environment!: EnvironmentPlugin + feeling!: FeelingPlugin + particle!: ParticlePlugin private shiftKey!: Phaser.Input.Keyboard.Key private ctrlKey!: Phaser.Input.Keyboard.Key private side: number = 5000 @@ -239,17 +240,10 @@ class Test extends Phaser.Scene { // .setRevealer(this.player) // .changeDaylight('dawn', 0, true) - const particle = this.particle.addFirefly(-100, -100) - - // this.particle.addGlitter(200, 200) - // this.particle.addSmoke(200, 200) - // this.particle.addExplode(-200, -200) - // this.particle.addBurn(-500, -500) - - // this.particle.addSnow(300, 300, 1000) - this.particle.addRain(300, 300, 1000) + const particle = this.particle.addFirefly(0, 0) - this.player.particle.addPrebuilt('sp', 'particle-flash', 'burn', 0, false) + // this.player.particle.addExists('smoke', this.particle.addSmoke(0, 0), true) + // this.player.particle.addExists('explode', this.particle.addExplode(0, 0, 100), true) // this.environment // .addEnvironment('frozen')