Skip to content

Commit

Permalink
add actor.particle.addExists methods
Browse files Browse the repository at this point in the history
  • Loading branch information
izure committed Jun 24, 2021
1 parent af5fd5d commit b41d2b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 93 deletions.
78 changes: 10 additions & 68 deletions @common/Phaser/ActorParticle.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions @common/Phaser/Particle/DefaultParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
40 changes: 17 additions & 23 deletions @test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {}
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit b41d2b7

Please sign in to comment.