Modal behavior
Introduction¶
Pop-up modal dialog, then scale-down this dialog.
- Author: Rex
- Behavior of game object
Live demos¶
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexmodalplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexmodalplugin.min.js', true);
- Add modal behavior
var modal = scene.plugins.get('rexmodalplugin').add(gameObject, config);
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Add modal behavior
var modal = scene.plugins.get('rexModal').add(gameObject, config);
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Import class
import { ModalBehavoir } from 'phaser3-rex-plugins/plugins/modal.js';
- Add modal behavior
var modal = new ModalBehavoir(gameObject, config);
Create instance¶
var modal = scene.plugins.get('rexModal').add(gameObject, {
// cover: {
// color: 0x0,
// alpha: 0.8,
// transitIn: function(gameObject, duration) { },
// transitOut: function(gameObject, duration) { },
// },
// cover: false,
// When to close modal dialog?
// touchOutsideClose: false,
// anyTouchClose: false,
// timeOutClose: false,
// manualClose: false,
// duration: {
// in: 200,
// hold: 2000,
// out: 200
// }
// transitIn: 0,
// transitOut: 0,
// destroy: true,
// openOnStart: true
});
cover
: Configuration of Cover -- A rectangle shape covered full window, and block all touch events.false
: Don't create cover game object.cover.transitIn
: Custom callback. Default behavior is fade-in.function(gameObject, duration) { }
cover.transitOut
: Custom callback. Default behavior is fade-out.function(gameObject, duration) { }
touchOutsideClose
: Set totrue
to close modal dialog when clicking out side of gameObject.- Default value is
false
. Will be set tofalse
ifanyTouchClose
is set totrue
.
- Default value is
anyTouchClose
: Set totrue
to close modal dialog when any clicking.- Default value is
false
.
- Default value is
timeOutClose
: Set totrue
to close modal dialog when holding time out (duration.hold
).- If
duration.hold
is given, default value istrue
. Otherwise default value isfalse
.
- If
manualClose
: Set totrue
to close modal dialog viamodal.requestClose()
method.- Default value is
false
. When this parameter istrue
, other closing methods will be disabled. - If
touchOutsideClose
,anyTouchClose
, andtimeOutClose
arefalse
, it is equal tomanualClose
.
- Default value is
duration
: Duration of transition-in, hold, trantion-out.duration.in
: Duration of transition-in (open dialog).0
: No transition, open dialog immediately.
duration.out
: Duration of transition-out (close dialog).0
: No transition, close dialog immediately.
duration.hold
: Duration of hold.-1
: DisabletimeOutClose
.
transitIn
: Transition behavior of opening dialog.0
,'popUp'
: Pop up dialog from0
to current scale.1
,'fadeIn'
: Fade in dialog- Custom callback
function(gameObject, duration) { }
transitOut
: Tween behavior of closing dialog.0
,'scaleDown'
: Scale down dialog1
,'fadeOut'
: Fade out dialog- Custom callback
function(gameObject, duration) { }
destroy
true
: Destroy dialog game object and this behavior when closing completed. Default behavior.fasle
: Keep dialog game object and this behavior when closing completed. Could reuse it later.
openOnStart
:true
: Open dialog game object (modal.requestOpen()
) at beginning. Default behavior.false
: Open dialog game object manually.
Open¶
- Will open modal dialog game object (run transition-in callback) when creating this behavior,
if
openOnStart
is set totrue
. - Invoke
modal.requestOpen()
to open modal dialog game object again, after closing modal dialog.- Set
destroy
tofalse
to reuse dialog game object and this behavior.
- Set
Close¶
modal.requestClose();
// modal.requestClose(closeEventData);
closeEventData
: Emit'close'
event when closed dialog complete, passcloseEventData
to callback of this event.modal.on('close', function(closeEventData) { })
Events¶
- On opened dialog
modal.on('open', function(gameObject, modal) { })
- On closed dialog
modal.on('close', function(closeEventData) { })