Bullet
Introduction¶
Move game object toward current angle of game object, with a constant speed.
- Author: Rex
- Arcade behavior of game object
Usage¶
Install plugin¶
Load minify file¶
- Enable arcade physics engine in configuration of game
var config = { // ... physics: { default: 'arcade', arcade: { // debug: true } } } var game = new Phaser.Game(config);
- Load plugin (minify file) in preload stage
scene.load.plugin('rexbulletplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexbulletplugin.min.js', true);
- Add bullet behavior
var bullet = scene.plugins.get('rexbulletplugin').add(gameObject, config);
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Enable arcade physics engine and install plugin in configuration of game
import BulletPlugin from 'phaser3-rex-plugins/plugins/bullet-plugin.js'; var config = { physics: { default: 'arcade', arcade: { // debug: true } }, // ... plugins: { global: [{ key: 'rexBullet', plugin: BulletPlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config);
- Add bullet behavior
var bullet = scene.plugins.get('rexBullet').add(gameObject, config);
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Enable arcade physics engine in configuration of game
var config = { // ... physics: { default: 'arcade', arcade: { // debug: true } } } var game = new Phaser.Game(config);
- Import class
import Bullet from 'phaser3-rex-plugins/plugins/bullet.js';
- Add bullet behavior
var bullet = new Bullet(gameObject, config);
Create instance¶
var bullet = scene.plugins.get('rexBullet').add(gameObject, {
speed: 200,
// enable: true
});
speed
: moving speed, pixels in second.enable
: setfalse
to disable moving.
Speed¶
- Set
bullet.setSpeed(speed); // bullet.speed = speed;
- Get
var speed = bullet.speed;