I’m trying to implement the following code into a class, as follows is the code ,and the attempted class.
Implementation
//----------------------------MIST------------------------------------
...
var particles = this.add.particles('rain');
var emitter = particles.createEmitter({
x: 500,
y: -400,
angle: { min: 0, max: 120 },
speed: 300,
gravityY: 100,
lifespan: { min: 1000, max: 2000 },
blendMode: 'ADD'
});
//this.mCloud = this.physics.add.existing(new Clouds(this, 500, 500,'clouds'))
this.Cloud = [];
this.levelData_Clouds = this.cache.json.get('level_clouds');
this.levelData_Clouds.cloudData.forEach(function(element){
this.Cloud.push(new Clouds(this, element.x, element.y, 'clouds', element.isAddative));
}, this)
emitter.startFollow(this.Cloud[0])
this.rCloud = [];
this.levelData_Clouds = this.cache.json.get('level_clouds');
this.levelData_Clouds.rain_cloudData.forEach(function(element){
this.rCloud.push(new RainClouds(this, element.x, element.y, 'rainclouds', element.isAddative));
}, this)
emitter.startFollow(this.rCloud[0])
...
Attempted Class.
As you can see here is the class some of what is there , but the constructor doesn’t work.
export default class Rain extends Phaser.GameObjects.Particles.Particle{
constructor (emitter){
super(emitter);
this.x: 500,
this.y: -400,
this.angle: { min: 0, max: 120 },
this.speed: 300,
this.gravityY: 100,
this.lifespan: { min: 1000, max: 2000 },
this.blendMode: 'ADD'
}
rain(){
this.Cloud = [];
this.levelData_Clouds = this.cache.json.get('level_clouds');
this.levelData_Clouds.cloudData.forEach((element)=>{
this.Cloud.push(new Clouds(this, element.x, element.y, 'clouds', element.isAddative));
}, this)
}
}