UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

1,499 lines (1,297 loc) 8.38 MB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define("Phaser", [], factory); else if(typeof exports === 'object') exports["Phaser"] = factory(); else root["Phaser"] = factory(); })(this, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 50792 (module) { "use strict"; var has = Object.prototype.hasOwnProperty , prefix = '~'; /** * Constructor to create a storage for our `EE` objects. * An `Events` instance is a plain object whose properties are event names. * * @constructor * @private */ function Events() {} // // We try to not inherit from `Object.prototype`. In some engines creating an // instance in this way is faster than calling `Object.create(null)` directly. // If `Object.create(null)` is not supported we prefix the event names with a // character to make sure that the built-in object properties are not // overridden or used as an attack vector. // if (Object.create) { Events.prototype = Object.create(null); // // This hack is needed because the `__proto__` property is still inherited in // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. // if (!new Events().__proto__) prefix = false; } /** * Representation of a single event listener. * * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} [once=false] Specify if the listener is a one-time listener. * @constructor * @private */ function EE(fn, context, once) { this.fn = fn; this.context = context; this.once = once || false; } /** * Add a listener for a given event. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} context The context to invoke the listener with. * @param {Boolean} once Specify if the listener is a one-time listener. * @returns {EventEmitter} * @private */ function addListener(emitter, event, fn, context, once) { if (typeof fn !== 'function') { throw new TypeError('The listener must be a function'); } var listener = new EE(fn, context || emitter, once) , evt = prefix ? prefix + event : event; if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); else emitter._events[evt] = [emitter._events[evt], listener]; return emitter; } /** * Clear event by name. * * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. * @param {(String|Symbol)} evt The Event name. * @private */ function clearEvent(emitter, evt) { if (--emitter._eventsCount === 0) emitter._events = new Events(); else delete emitter._events[evt]; } /** * Minimal `EventEmitter` interface that is molded against the Node.js * `EventEmitter` interface. * * @constructor * @public */ function EventEmitter() { this._events = new Events(); this._eventsCount = 0; } /** * Return an array listing the events for which the emitter has registered * listeners. * * @returns {Array} * @public */ EventEmitter.prototype.eventNames = function eventNames() { var names = [] , events , name; if (this._eventsCount === 0) return names; for (name in (events = this._events)) { if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); } if (Object.getOwnPropertySymbols) { return names.concat(Object.getOwnPropertySymbols(events)); } return names; }; /** * Return the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Array} The registered listeners. * @public */ EventEmitter.prototype.listeners = function listeners(event) { var evt = prefix ? prefix + event : event , handlers = this._events[evt]; if (!handlers) return []; if (handlers.fn) return [handlers.fn]; for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { ee[i] = handlers[i].fn; } return ee; }; /** * Return the number of listeners listening to a given event. * * @param {(String|Symbol)} event The event name. * @returns {Number} The number of listeners. * @public */ EventEmitter.prototype.listenerCount = function listenerCount(event) { var evt = prefix ? prefix + event : event , listeners = this._events[evt]; if (!listeners) return 0; if (listeners.fn) return 1; return listeners.length; }; /** * Calls each of the listeners registered for a given event. * * @param {(String|Symbol)} event The event name. * @returns {Boolean} `true` if the event had listeners, else `false`. * @public */ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return false; var listeners = this._events[evt] , len = arguments.length , args , i; if (listeners.fn) { if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); switch (len) { case 1: return listeners.fn.call(listeners.context), true; case 2: return listeners.fn.call(listeners.context, a1), true; case 3: return listeners.fn.call(listeners.context, a1, a2), true; case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; } for (i = 1, args = new Array(len -1); i < len; i++) { args[i - 1] = arguments[i]; } listeners.fn.apply(listeners.context, args); } else { var length = listeners.length , j; for (i = 0; i < length; i++) { if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); switch (len) { case 1: listeners[i].fn.call(listeners[i].context); break; case 2: listeners[i].fn.call(listeners[i].context, a1); break; case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; default: if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { args[j - 1] = arguments[j]; } listeners[i].fn.apply(listeners[i].context, args); } } } return true; }; /** * Add a listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.on = function on(event, fn, context) { return addListener(this, event, fn, context, false); }; /** * Add a one-time listener for a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn The listener function. * @param {*} [context=this] The context to invoke the listener with. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.once = function once(event, fn, context) { return addListener(this, event, fn, context, true); }; /** * Remove the listeners of a given event. * * @param {(String|Symbol)} event The event name. * @param {Function} fn Only remove the listeners that match this function. * @param {*} context Only remove the listeners that have this context. * @param {Boolean} once Only remove one-time listeners. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { var evt = prefix ? prefix + event : event; if (!this._events[evt]) return this; if (!fn) { clearEvent(this, evt); return this; } var listeners = this._events[evt]; if (listeners.fn) { if ( listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context) ) { clearEvent(this, evt); } } else { for (var i = 0, events = [], length = listeners.length; i < length; i++) { if ( listeners[i].fn !== fn || (once && !listeners[i].once) || (context && listeners[i].context !== context) ) { events.push(listeners[i]); } } // // Reset the array, or remove it completely if we have no more listeners. // if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; else clearEvent(this, evt); } return this; }; /** * Remove all listeners, or those of the specified event. * * @param {(String|Symbol)} [event] The event name. * @returns {EventEmitter} `this`. * @public */ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { var evt; if (event) { evt = prefix ? prefix + event : event; if (this._events[evt]) clearEvent(this, evt); } else { this._events = new Events(); this._eventsCount = 0; } return this; }; // // Alias methods names because people roll like that. // EventEmitter.prototype.off = EventEmitter.prototype.removeListener; EventEmitter.prototype.addListener = EventEmitter.prototype.on; // // Expose the prefix. // EventEmitter.prefixed = prefix; // // Allow `EventEmitter` to be imported as module namespace. // EventEmitter.EventEmitter = EventEmitter; // // Expose the module. // if (true) { module.exports = EventEmitter; } /***/ }, /***/ 93300 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Benjamin D. Richards <benjamindrichards@gmail.com> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var BlendModes = __webpack_require__(10312); /** * Adds a Bloom effect to a Camera or GameObject or list thereof. * * Bloom is a phenomenon where bright light spreads across an image. * It can be used to add to the realism of a scene, * although too much is obvious and a subtle effect is best. * * This Action creates a Bloom effect by applying several Filters to the target. * * - `ParallelFilters` splits the filter stream, allowing us to combine * the results of other filters with the original image. * The other filters are added to the `top` stream. * - `Threshold` removes darker colors. * - `Blur` spreads the remaining bright colors out. * * This Action returns an object containing references to these filters. * You can control their properties directly, * e.g. if you want to animate the Bloom, * or if you want to set properties this Action doesn't surface. * * The Bloom effect will be destroyed like any other filter on target shutdown. * To disable or remove the Bloom effect manually, access the `parallelFilters` * controller in the return object. It holds the other filters. * * - `parallelFilters.active = false`: deactivate Bloom * - `parallelFilters.destroy()`: destroy Bloom * * Bloom is best as a full-screen effect. If you apply it to a GameObject with * alpha regions, it cannot blend the light glow properly with the background. * This is because the glow should use ADD blend, but the object itself should * use NORMAL blend, and it can't do both. * You can still apply bloom to a GameObject, * but it works best on a solid texture. * * @example * // Apply bloom to the scene camera. * Phaser.Actions.AddEffectBloom(this.cameras.main); * * @example * // Access the filters that make up a Bloom effect. * const { parallelFilters, threshold, blur } = Phaser.Actions.AddEffectBloom(this.cameras.main)[0]; // The return is an array. * * // Destroy the bloom effect. * parallelFilters.destroy(); * * @example * // Emulate the Phaser 3 Bloom effect, * // including the way bloom strength darkens instead of mixes. * const { parallelFilters, threshold, blur } = Phaser.Actions.AddEffectBloom( * image, * { * blendAmount: 0.5, * blurQuality: 1, * } * ); * * threshold.active = false; * parallelFilters.bottom.addBlend(undefined, Phaser.BlendModes.MULTIPLY, 1, [ 0. * 5, 0.5, 0.5, 0.5 ]); * * @function Phaser.Actions.AddEffectBloom * @since 4.0.0 * * @param {Phaser.Cameras.Scene2D.Camera|Phaser.GameObjects.GameObject|Array.<(Phaser.Cameras.Scene2D.Camera|Phaser.GameObjects.GameObject)>} items - Recipients of the Bloom effect * @param {Phaser.Types.Actions.AddEffectBloomConfig} [config] - Initial configuration of the Bloom effect. * * @return {Phaser.Types.Actions.AddEffectBloomReturn[]} A list of objects containing the filters which were created. */ var AddEffectBloom = function (items, config) { if (!Array.isArray(items)) { items = [ items ]; } if (!config) { config = {}; } var threshold = config.threshold === undefined ? 0.5 : config.threshold; var blurRadius = config.blurRadius === undefined ? 2 : config.blurRadius; var blurSteps = config.blurSteps === undefined ? 4 : config.blurSteps; var blurQuality = config.blurQuality === undefined ? 0 : config.blurQuality; var blendAmount = config.blendAmount === undefined ? 1 : config.blendAmount; var blendMode = config.blendMode === undefined ? BlendModes.ADD : config.blendMode; var output = []; for (var i = 0; i < items.length; i++) { var item = items[i]; if (item.enableFilters) { item.enableFilters(); } var filterList = config.useInternal ? item.filters.internal : item.filters.external; var parallelFilters = filterList.addParallelFilters(); var thresholdFilter = parallelFilters.top.addThreshold(threshold, 1); var blurFilter = parallelFilters.top.addBlur(blurQuality, blurRadius, blurRadius, 1, 0xffffff, blurSteps); parallelFilters.blend.blendMode = blendMode; parallelFilters.blend.amount = blendAmount; output.push({ item: item, parallelFilters: parallelFilters, threshold: thresholdFilter, blur: blurFilter }); } return output; }; module.exports = AddEffectBloom; /***/ }, /***/ 56704 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Benjamin D. Richards <benjamindrichards@gmail.com> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var DESTROY_EVENT = __webpack_require__(16438); var BlendModes = __webpack_require__(10312); var DESTROY = __webpack_require__(41337); var GameObject = __webpack_require__(95643); var UUID = __webpack_require__(45650); /** * Adds a Shine effect to a Camera or GameObject or list thereof. * * Shine simulates a highlight glancing from a surface. * It's a brief specular reflection of a bright light, * typically from a fairly flat surface which only reflects the highlight * from certain angles. * In a game, you might use this to highlight an important object, * convey a sense of glossiness, * or move an interference band across a transmission. * * This Action works by creating several resources. * * - A Gradient object generates the region of the shine. * - A DynamicTexture holds the shine region. * - A Tween animates the shine region. * - A Blend filter combines the shine and the image. * - (Optional) A ParallelFilters filter adds the rest of the image back in. * * You may configure the effect in several ways using the `config` parameter. * * Use `radius`, `direction` and `scale` to set the gradient orientation. * Scale defaults to 2, twice the size of the target, * to guarantee that the highlight leaves the image completely before repeating. * The radius also adds an extra offset on either side of the image * so the gradient has space to enter and exit the image. * * Use `colorFactor` to control the RGBA color of the highlight. * You can overdrive this to values greater than 1 to create very bright shine. * By default, it has a slight red tint to create warm highlights. * * Use `displacementMap` and `displacement` to add a Displacement filter * to the Gradient. This creates the impression of a slightly scuffed surface. * You may add other filters to the Gradient; they will be rendered into the * DynamicTexture for use in the final blend. * * Use `reveal` to put the effect into reveal mode. * In this mode, the image is only visible under the shine. * * Use `duration`, `yoyo` and `ease` to control the Tween animation. * * The resources created in this way will be automatically destroyed * when the target is destroyed. You may remove them earlier yourself. * Unless you use them in other systems, they are isolated and safe to destroy. * (The Tween requires the other resources to exist while it exists.) * * When you target multiple objects with this method, * each creates its own set of resources. Each set is independent, * and may be destroyed or manipulated without affecting the others. * * You can create your own Shine effects using this as a base or as inspiration. * * @example * // Slowly move a cyan highlight up and down an image. * // Use a displacement map to dirty up the highlight. * const { dynamicTexture, gradient, tween } = Phaser.Actions.AddEffectShine(this.image, { * duration: 5000, * direction: Math.PI / 2, * scale: 1, * displacementMap: 'displace', * colorFactor: [ 0.5,2,2,1 ], * yoyo: true, * ease: 'Quad.inout' * })[0]; // The return is an array. * * @function Phaser.Actions.AddEffectShine * @since 4.0.0 * * @param {Phaser.Cameras.Scene2D.Camera|Phaser.GameObjects.GameObject|Array.<(Phaser.Cameras.Scene2D.Camera|Phaser.GameObjects.GameObject)>} items - Recipients of the Shine effect * @param {Phaser.Types.Actions.AddEffectShineConfig} [config] - Initial configuration of the Shine effect. * * @return {Phaser.Types.Actions.AddEffectShineReturn[]} A list of objects containing the resources which were created. */ var AddEffectShine = function (items, config) { if (!config) { config = {}; } if (!Array.isArray(items)) { items = [ items ]; } var firstItem = items[0]; var scene = firstItem.scene; var gradientDirection = config.direction === undefined ? 0.5 : config.direction % (Math.PI * 2); var gradientScale = config.scale === undefined ? 2 : config.scale; var gradientRadius = (config.radius || 0.5) / gradientScale; var gradientWidth = config.width || firstItem.width || 128; var gradientHeight = config.height || firstItem.height || 128; var start = { x: 0, y: 0 }; if (gradientDirection < 0) { gradientDirection += Math.PI * 2; } if (gradientDirection > Math.PI * 3 / 2) { // Bottom-left start start.y = 1; } else if (gradientDirection > Math.PI) { // Bottom-right start start.x = 1; start.y = 1; } else if (gradientDirection > Math.PI / 2) { // Top-right start start.x = 1; } var output = []; for (var i = 0; i < items.length; i++) { var item = items[i]; // Create Gradient object. var gradientConfig = { origin: 0, width: gradientWidth, height: gradientHeight, config: { offset: -gradientRadius, repeatMode: 3, // Triangular shapeMode: 0, // Linear direction: gradientDirection, length: gradientScale, start: start, bands: config.bands || [ { interpolation: 2, // Sinusoidal for smooth transitions colorStart: 0xffffff, colorEnd: [ 1, 1, 1, 0 ], size: gradientRadius }, { colorStart: [ 1, 1, 1, 0 ], size: 1 - gradientRadius } ] } }; var gradient = scene.make.gradient(gradientConfig, false); // Create displacement effect. if (config.displacementMap) { var displacement = config.displacement || 0.1; gradient.enableFilters().filters.internal.addDisplacement(config.displacementMap, displacement, displacement); } // Create DynamicTexture. var key = UUID(); var textures = scene.textures; while (textures.exists(key)) { key = UUID(); } var dynamicTexture = textures.addDynamicTexture(key, gradient.width, gradient.height); // Create Tween. var tween = scene.tweens.add({ targets: gradient, offset: 1 + gradientRadius, repeat: -1, yoyo: !!config.yoyo, ease: config.ease, duration: config.duration || 2000, repeatDelay: config.repeatDelay || 0, onUpdate: function () { dynamicTexture.clear().draw(gradient).render(); } }); // Enable filters on target. if (item instanceof GameObject) { item.enableFilters(); } // Combine gradient texture with target. var filterList = config.useExternal ? item.filters.external : item.filters.internal; var blendFilter; var parallelFilters; var colorFactor = config.colorFactor || [ 1.15, 0.85, 0.85, 1 ]; if (!config.reveal) { parallelFilters = filterList.addParallelFilters(); blendFilter = parallelFilters.top.addBlend(key, BlendModes.MULTIPLY, 1, colorFactor); parallelFilters.blend.blendMode = BlendModes.ADD; } else { blendFilter = filterList.addBlend(key, BlendModes.MULTIPLY, 1, colorFactor); } // Set up tidy-up. // Gradient is only referenced from the tween, and will self-dispose. // Filters will self-dispose. // Tween and dynamic texture must be removed if the target is destroyed. var tidyup = function () { tween.destroy(); dynamicTexture.destroy(); }; if (item instanceof GameObject) { item.on(DESTROY, tidyup); } else { item.on(DESTROY_EVENT, tidyup); } output.push({ item: item, dynamicTexture: dynamicTexture, gradient: gradient, tween: tween, parallelFilters: parallelFilters, blendFilter: blendFilter }); } // Return relevant objects. return output; }; module.exports = AddEffectShine; /***/ }, /***/ 245 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Benjamin D. Richards <benjamindrichards@gmail.com> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var GameObject = __webpack_require__(95643); var Rectangle = __webpack_require__(93232); var FitToRegion = __webpack_require__(94591); /** * Apply a Mask to a GameObject or Camera or list thereof using a Shape. * * This is a quick way to add a mask to an object/camera. * It creates a Shape and uses FitToRegion to size it correctly. * * By default, the Mask is a circle, scaled to fit both X and Y axes * of the game canvas (so it's not really a circle any more). * * You can change the shape to 'square', 'rectangle', or 'ellipse'. * Control the shape of rectangles or ellipses via `config.aspectRatio`. * * You can change the coverage much like FitToRegion. * You can scale to fit inside, outside, or both axes. * You can set the target region; if you do not, the action will choose * an appropriate region for you. * * The action supports an optional Blur effect, applied to the shape. * This is good for soft edges on masks. * You can use `config.padding` to shrink the shape region inward, leaving room for the blur to spread outward to the intended boundary. * * The Shape is removed from the scene upon creation. * You don't need to manage its life cycle; it should be garbage collected * once the Mask filter is destroyed, usually when the scene or target * is shut down. * If you want to access the Shape, it is available on the mask filter. * * If you apply this to multiple objects at once, * they all have their own shape and mask filter. * Note that, if you use external filters, the masks will seem to line up. * In this case, it might be more efficient to put all the targets into * a Layer or Container and mask that instead. * * @example * const mask = Phaser.Actions.AddMaskShape(target, { * blurRadius: 2, * padding: 2 * })[0]; // The return is an array. * const shape = mask.maskGameObject; // This reference prevents garbage collection until `shape` is dropped. * const blur = shape.filters.external.list[0]; // Nothing else should be in this list. * * @function Phaser.Actions.AddMaskShape * @since 4.0.0 * * @param {Phaser.GameObjects.GameObject | Phaser.Cameras.Scene2D.Camera | Array.<(Phaser.GameObjects.GameObject | Phaser.Cameras.Scene2D.Camera)>} items - The GameObject or Camera or list thereof to which to apply a mask. * @param {Phaser.Types.Actions.AddMaskShapeConfig} config - The configuration of the mask shape. * * @return {Phaser.Filters.Mask[]} The new Mask filters, in order of target. */ var AddMaskShape = function (items, config) { if (!Array.isArray(items)) { items = [ items ]; } if (!config) { config = {}; } var aspectRatio = (config.aspectRatio === undefined) ? 1 : config.aspectRatio; var padding = config.padding || 0; var scene = items[0].scene; var output = []; for (var i = 0; i < items.length; i++) { var item = items[i]; var region = config.region; if (!region) { if (config.useInternal && item._sizeComponent) { region = new Rectangle(0, 0, item.width, item.height); } else { region = new Rectangle(0, 0, scene.scale.width, scene.scale.height); } } // Create a shape to use as a mask. var shape; switch (config.shape) { case 'ellipse': { shape = scene.add.ellipse(0, 0, aspectRatio, 1, 0xffffff); break; } case 'square': { shape = scene.add.rectangle(0, 0, 1, 1, 0xffffff); break; } case 'rectangle': { shape = scene.add.rectangle(0, 0, aspectRatio, 1, 0xffffff); break; } case 'circle': default: { shape = scene.add.circle(0, 0, 1, 0xffffff); break; } } // Remove shape from scene, as we don't need to display it, // and it will be garbage collected once the Mask is destroyed. scene.children.remove(shape); // Apply padding. if (padding) { region = new Rectangle( region.x + padding, region.y + padding, region.width - padding * 2, region.height - padding * 2 ); } // Transform shape to fit to target. FitToRegion(shape, config.scaleMode, region); // Optionally, blur shape. if (config.blurRadius > 0) { shape.enableFilters().filters.external.addBlur( config.blurQuality, config.blurRadius, config.blurRadius, 1, undefined, config.blurSteps ); } // Apply mask. if (item instanceof GameObject) { item.enableFilters(); } var filterList = config.useInternal ? item.filters.internal : item.filters.external; var mask = filterList.addMask(shape, config.invert); output.push(mask); } return output; }; module.exports = AddMaskShape; /***/ }, /***/ 11517 (module, __unused_webpack_exports, __webpack_require__) { /** * @author samme * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var QuickSet = __webpack_require__(38829); /** * Takes an array of Game Objects and aligns them next to each other. * * The alignment position is controlled by the `position` parameter, which should be one * of the Phaser.Display.Align constants, such as `Phaser.Display.Align.TOP_LEFT`, * `Phaser.Display.Align.TOP_CENTER`, etc. * * The first item isn't moved. The second item is aligned next to the first, * then the third next to the second, and so on. * * @function Phaser.Actions.AlignTo * @since 3.22.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {number} position - The position to align the items with. This is an align constant, such as `Phaser.Display.Align.LEFT_CENTER`. * @param {number} [offsetX=0] - Optional horizontal offset from the position, in pixels. * @param {number} [offsetY=0] - Optional vertical offset from the position, in pixels. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. */ var AlignTo = function (items, position, offsetX, offsetY) { var target = items[0]; for (var i = 1; i < items.length; i++) { var item = items[i]; QuickSet(item, target, position, offsetX, offsetY); target = item; } return items; }; module.exports = AlignTo; /***/ }, /***/ 80318 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var PropertyValueInc = __webpack_require__(66979); /** * Takes an array of Game Objects, or any objects that have a public `angle` property, * and then adds the given value to each of their `angle` properties. * * The optional `step` property is applied incrementally, multiplied by each item in the array. * * To use this with a Group: `Angle(group.getChildren(), value, step)` * * @function Phaser.Actions.Angle * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {number} value - The amount, in degrees, to be added to the `angle` property. * @param {number} [step=0] - This is added to the `value` amount, multiplied by the iteration counter. For example, a `step` of 10 will add 0 to the first item, 10 to the second, 20 to the third, and so on. * @param {number} [index=0] - An optional offset to start searching from within the items array. * @param {number} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. */ var Angle = function (items, value, step, index, direction) { return PropertyValueInc(items, 'angle', value, step, index, direction); }; module.exports = Angle; /***/ }, /***/ 60757 (module) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ /** * Takes an array of objects and passes each of them to the given callback. * * @function Phaser.Actions.Call * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {Phaser.Types.Actions.CallCallback} callback - The callback to be invoked. It will be passed just one argument: the item from the array. * @param {*} context - The scope in which the callback will be invoked. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that was passed to this Action. */ var Call = function (items, callback, context) { for (var i = 0; i < items.length; i++) { var item = items[i]; callback.call(context, item); } return items; }; module.exports = Call; /***/ }, /***/ 94591 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Benjamin D. Richards <benjamindrichards@gmail.com> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var Rectangle = __webpack_require__(87841); var GetFastValue = __webpack_require__(95540); /** * Fit GameObjects to a region. * * This is a quick way to fit a background to a scene, * move an object without worrying about origins, * or cover a hole of known size. * * This will transform each object to fit into a rectangular region. * Rotation is ignored, but translation and scale are changed. * Note that negative scale will become positive; use flip to resolve this. * The object must support transformation. * * The fit can scale proportionally, to touch the inside or outside of the region; * but by default it scales both axes independently to touch all sides. * * The region is an axis-aligned bounding box (AABB). * By default, it is derived from the object, via the scene scale properties, * i.e. `{ x: 0, y: 0, width: scene.scale.width, height: scene.scale.height }`. * * If the game object has no size or origin, e.g. a Container, * then it is tricky to figure out how to resize it to fit. * The `itemCoverage` parameter allows you to set `width`, `height`, `originX` * and/or `originY` properties to supplement available data. * These settings take precedence over original item properties, even if they exist. * * @function Phaser.Actions.FitToRegion * @since 4.0.0 * * @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} items - The GameObject or GameObjects to fit to the region. Each must have the Phaser.GameObjects.Components.Transform component. * @param {number} [scaleMode=0] - The scale mode. 0 sets each axis to fill the region independently. -1 scales both axes uniformly so the item touches the _inside_ of the region. 1 scales both axes uniformly so the item touches the _outside_ of the region. * @param {Phaser.Types.Math.RectangleLike} [region] - The region to fit. If not defined, it will be inferred from the first item's scene scale. * @param {Phaser.Types.Actions.FitToRegionItemCoverage} [itemCoverage] - Override or define the region covered by the item. This is intended to provide dimensions for objects which don't have them, such as Containers, allowing them to resize. * * @return {Phaser.GameObjects.GameObject[]} - The items that were fitted. */ var FitToRegion = function (items, scaleMode, region, itemCoverage) { if (!Array.isArray(items)) { items = [ items ]; } if (scaleMode === undefined) { scaleMode = 0; } if (!region) { var scene = items[0].scene; region = new Rectangle(0, 0, scene.scale.width, scene.scale.height); } if (!itemCoverage) { itemCoverage = {}; } for (var i = 0; i < items.length; i++) { var item = items[i]; var itemWidth = GetFastValue(itemCoverage, 'width', GetFastValue(item, 'width', 1)); var itemHeight = GetFastValue(itemCoverage, 'height', GetFastValue(item, 'height', 1)); var itemOriginX = GetFastValue(itemCoverage, 'originX', GetFastValue(item, 'originX', 0.5)); var itemOriginY = GetFastValue(itemCoverage, 'originY', GetFastValue(item, 'originY', 0.5)); // Reposition item. item.x = region.x + region.width * itemOriginX; item.y = region.y + region.height * itemOriginY; // Compute relative scales. var itemScaleXToRegion = region.width / itemWidth; var itemScaleYToRegion = region.height / itemHeight; switch (scaleMode) { case -1: { // Scale to fit the inside of the region. item.setScale(Math.min(itemScaleXToRegion, itemScaleYToRegion)); break; } case 0: { // Scale both axes independently to match the region. item.setScale(itemScaleXToRegion, itemScaleYToRegion); break; } case 1: { // Scale to envelop the outside of the region. item.setScale(Math.max(itemScaleXToRegion, itemScaleYToRegion)); break; } } } return item; }; module.exports = FitToRegion; /***/ }, /***/ 69927 (module) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ /** * Takes an array of objects and returns the first element in the array that has properties which match * all of those specified in the `compare` object. For example, if the compare object was: `{ scaleX: 0.5, alpha: 1 }` * then it would return the first item which had the property `scaleX` set to 0.5 and `alpha` set to 1. * * To use this with a Group: `GetFirst(group.getChildren(), compare, index)` * * @function Phaser.Actions.GetFirst * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be searched by this action. * @param {object} compare - The comparison object. Each property in this object will be checked against the items of the array. * @param {number} [index=0] - An optional offset to start searching from within the items array. * * @return {?(object|Phaser.GameObjects.GameObject)} The first object in the array that matches the comparison object, or `null` if no match was found. */ var GetFirst = function (items, compare, index) { if (index === undefined) { index = 0; } for (var i = index; i < items.length; i++) { var item = items[i]; var match = true; for (var property in compare) { if (item[property] !== compare[property]) { match = false; } } if (match) { return item; } } return null; }; module.exports = GetFirst; /***/ }, /***/ 32265 (module) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ /** * Takes an array of objects and returns the last element in the array that has properties which match * all of those specified in the `compare` object. For example, if the compare object was: `{ scaleX: 0.5, alpha: 1 }` * then it would return the last item which had the property `scaleX` set to 0.5 and `alpha` set to 1. * * To use this with a Group: `GetLast(group.getChildren(), compare, index)` * * @function Phaser.Actions.GetLast * @since 3.3.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be searched by this action. * @param {object} compare - The comparison object. Each property in this object will be checked against the items of the array. * @param {number} [index=0] - An optional offset to start searching from within the items array. * * @return {?(object|Phaser.GameObjects.GameObject)} The last object in the array that matches the comparison object, or `null` if no match was found. */ var GetLast = function (items, compare, index) { if (index === undefined) { index = 0; } for (var i = items.length - 1; i >= index; i--) { var item = items[i]; var match = true; for (var property in compare) { if (item[property] !== compare[property]) { match = false; } } if (match) { return item; } } return null; }; module.exports = GetLast; /***/ }, /***/ 94420 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var AlignIn = __webpack_require__(11879); var CONST = __webpack_require__(60461); var GetFastValue = __webpack_require__(95540); var NOOP = __webpack_require__(29747); var Zone = __webpack_require__(41481); var tempZone = new Zone({ sys: { queueDepthSort: NOOP, events: { once: NOOP } } }, 0, 0, 1, 1).setOrigin(0, 0); /** * Takes an array of Game Objects, or any objects that have public `x` and `y` properties, * and positions them in a grid layout based on the configuration provided. * * The grid is defined by a `width` (number of columns) and/or `height` (number of rows). * Each cell in the grid has a size defined by `cellWidth` and `cellHeight`, in pixels. * Items are placed into cells starting from the top-left origin (`x`, `y`) and filling * left-to-right, top-to-bottom by default. If only `width` is set to -1, items are laid * out in a single horizontal row. If only `height` is set to -1, items are laid out in a * single vertical column. When both `width` and `height` are set, the grid fills * row-by-row, stopping early if the grid is full before all items have been placed. * * The `position` option controls how each item is aligned within its cell, using one of * the `Phaser.Display.Align` constants such as `CENTER` or `TOP_LEFT`. * * @function Phaser.Actions.GridAlign * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {Phaser.Types.Actions.GridAlignConfig} options - The GridAlign Configuration object. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. */ var GridAlign = function (items, options) { if (options === undefined) { options = {}; } var widthSet = options.hasOwnProperty('width'); var heightSet = options.hasOwnProperty('height'); var width = GetFastValue(options, 'width', -1); var height = GetFastValue(options, 'height', -1); var cellWidth = GetFastValue(options, 'cellWidth', 1); var cellHeight = GetFastValue(options, 'cellHeight', cellWidth); var position = GetFastValue(options, 'position', CONST.TOP_LEFT); var x = GetFastValue(options, 'x', 0); var y = GetFastValue(options, 'y', 0); var cx = 0; var cy = 0; var w = (width * cellWidth); var h = (height * cellHeight); tempZone.setPosition(x, y); tempZone.setSize(cellWidth, cellHeight); for (var i = 0; i < items.length; i++) { AlignIn(items[i], tempZone, position); if (widthSet && width === -1) { // We keep laying them out horizontally until we've done them all tempZone.x += cellWidth; } else if (heightSet && height === -1) { // We keep laying them out vertically until we've done them all tempZone.y += cellHeight; } else if (heightSet && !widthSet) { // We keep laying them out until we hit the column limit cy += cellHeight; tempZone.y += cellHeight; if (cy === h) { cy = 0; cx += cellWidth; tempZone.y = y; tempZone.x += cellWidth; if (cx === w) { // We've hit the column limit, so return, even if there are items left break; } } } else { // We keep laying them out until we hit the column limit cx += cellWidth; tempZone.x += cellWidth; if (cx === w) { cx = 0; cy += cellHeight; tempZone.x = x; tempZone.y += cellHeight; if (cy === h) { // We've hit the column limit, so return, even if there are items left break; } } } } return items; }; module.exports = GridAlign; /***/ }, /***/ 41721 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var PropertyValueInc = __webpack_require__(66979); /** * Takes an array of Game Objects, or any objects that have a public `alpha` property, * and then adds the given value to each of their `alpha` properties. * * The optional `step` property is applied incrementally, multiplied by each item in the array. * * To use this with a Group: `IncAlpha(group.getChildren(), value, step)` * * @function Phaser.Actions.IncAlpha * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {number} value - The amount to be added to the `alpha` property. * @param {number} [step=0] - This is added to the `value` amount, multiplied by the iteration counter. * @param {number} [index=0] - An optional offset to start searching from within the items array. * @param {number} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. */ var IncAlpha = function (items, value, step, index, direction) { return PropertyValueInc(items, 'alpha', value, step, index, direction); }; module.exports = IncAlpha; /***/ }, /***/ 67285 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var PropertyValueInc = __webpack_require__(66979); /** * Takes an array of Game Objects, or any objects that have a public `x` property, * and then adds the given value to each of their `x` properties. * * The optional `step` property is applied incrementally, multiplied by each item in the array. * * To use this with a Group: `IncX(group.getChildren(), value, step)` * * @function Phaser.Actions.IncX * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {number} value - The amount to be added to the `x` property. * @param {number} [step=0] - This is added to the `value` amount, multiplied by the iteration counter. * @param {number} [index=0] - An optional offset to start searching from within the items array. * @param {number} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. */ var IncX = function (items, value, step, index, direction) { return PropertyValueInc(items, 'x', value, step, index, direction); }; module.exports = IncX; /***/ }, /***/ 9074 (module, __unused_webpack_exports, __webpack_require__) { /** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2026 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var PropertyValueInc = __webpack_require__(66979); /** * Takes an array of Game Objects, or any objects that have public `x` and `y` properties, * and then adds the given value to each of them. * * The optional `stepX` and `stepY` properties are applied incrementally, multiplied by each item in the array. * * To use this with a Group: `IncXY(group.getChildren(), x, y, stepX, stepY)` * * @function Phaser.Actions.IncXY * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. * @param {number} x - The amount to be added to the `x` property. * @param {number} [y=x] - The amount to be added to the `y` property. If `undefined` or `null` it uses the `x` value. * @param {number} [stepX=0] - This is added to the `x` amount, multiplied by the iteration counter. * @param {number} [stepY=0] - This is added to the `y` amount, multiplied by the iteration counter. * @param {number} [index=0] - An optional offset to start searching from within the items array. * @param {number} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. */ var IncXY = function (items, x, y, stepX, stepY, index, direction) { if (y === undefined || y === null) { y = x; } PropertyValueInc(items, 'x', x, stepX, index, direction); return PropertyValueInc(items, 'y',