phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37k stars 7.08k forks source link

Incorrect typing for Phaser.Types.GameObjects.Particles.RandomZoneSourceCallback #6784

Open IKhonakhbeeva opened 5 months ago

IKhonakhbeeva commented 5 months ago

Version

Description

There is a typescript error when I am trying to create RandomZone for ParticlesEmitter.

Example Test Code

const emitRect = new Phaser.Geom.Rectangle()
new Phaser.GameObjects.Particles.Zones.RandomZone(emitRect)

Error:

Argument of type 'Rectangle' is not assignable to parameter of type 'RandomZoneSource'. Types of property 'getRandomPoint' are incompatible. Type '(point?: O | undefined) => O' is not assignable to type 'RandomZoneSourceCallback'. Types of parameters 'point' and 'point' are incompatible. Type 'Vector2Like' is missing the following properties from type 'Point': type, setTo

Additional Information

zackabrah commented 3 months ago

Looks like the RandomZoneSourceCallback's parameter is typed as Phaser.Types.Math.Vector2Like whereas the emitRect's getRandomPoint function returns type Phaser.Geom.Point.

As a workaround you could do something like

const emitRect = new Phaser.Geom.Rectangle();
new Phaser.GameObjects.Particles.Zones.RandomZone({
  getRandomPoint: () => emitRect.getRandomPoint()
});
photonstorm commented 1 month ago

We will address this after the v3.85 release. We're going to remove the Point class and swap to using Vec2 everywhere instead, which will fix this. Until then, please use the workaround above.