Random place
Introduction¶
Place objects randomly inside an area without overlapping.
- Author: Rex
- Methods
Live demos¶
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexrandomplaceplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexrandomplaceplugin.min.js', true); - Random place objects
scene.plugins.get('rexrandomplaceplugin').randomPlace(gameObjects, config);
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins - Install plugin in configuration of game
import RandomPlacePlugin from 'phaser3-rex-plugins/plugins/randomplace-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexRandomPlace', plugin: RandomPlacePlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config); - Random place objects
scene.plugins.get('rexRandomPlace').randomPlace(gameObjects, config);
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins - Import class
import RandomPlace from 'phaser3-rex-plugins/plugins/randomplace.js'; - Random place objects
RandomPlace(gameObjects, config);
Random place¶
scene.plugins.get('rexRandomPlace').randomPlace(gameObjects, {
radius: radius,
getPositionCallback: undefined,
area: areaGeomObject,
});
gameObjects: An array of gameObjects. Each item can be- A game objects.
- A plain object contains
{ gameObject: gameObject, radius: radius, }radius: Collision radius of this game object.
radius: Default collision radius of each game object.getPositionCallback: A callback to get a random position.undefined: Usearea.getRandomPoint(out)as callback.- A function object :
function(out) { out.x = 0; out.y = 0; }
area: A geom object, which hasgetRandomPointmethod.