From adb28d2f6e656e0ca92e99e45c04d0b845c792ea Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 27 Mar 2019 00:21:03 +0000 Subject: [PATCH] Added new Rectangle Arcade Physics Body type --- src/physics/arcade/ArcadeRectangle.js | 41 +++++++++++++++++++++++++++ src/physics/arcade/Factory.js | 10 +++++++ 2 files changed, 51 insertions(+) create mode 100644 src/physics/arcade/ArcadeRectangle.js diff --git a/src/physics/arcade/ArcadeRectangle.js b/src/physics/arcade/ArcadeRectangle.js new file mode 100644 index 000000000..2331972a2 --- /dev/null +++ b/src/physics/arcade/ArcadeRectangle.js @@ -0,0 +1,41 @@ +/** + * @author Richard Davey + * @copyright 2019 Photon Storm Ltd. + * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} + */ + +var Body = require('./Body'); +var Class = require('../../utils/Class'); + +/** + * @classdesc + * An Arcade Physics Image is an Image with an Arcade Physics body and related components. + * The body can be dynamic or static. + * + * The main difference between an Arcade Image and an Arcade Sprite is that you cannot animate an Arcade Image. + * + * @class Rectangle + * @memberof Phaser.Physics.Arcade + * @constructor + * @since 3.17.0 + * + * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param {number} x - The horizontal position of this Game Object in the world. + * @param {number} y - The vertical position of this Game Object in the world. + * @param {number} width - . + * @param {number} height - . + */ +var ArcadeRectangle = new Class({ + + Extends: Body, + + initialize: + + function ArcadeRectangle (world, x, y, width, height) + { + Body.call(this, world, null, x, y, width, height); + } + +}); + +module.exports = ArcadeRectangle; diff --git a/src/physics/arcade/Factory.js b/src/physics/arcade/Factory.js index 90b2b54dd..757099022 100644 --- a/src/physics/arcade/Factory.js +++ b/src/physics/arcade/Factory.js @@ -6,6 +6,7 @@ var ArcadeImage = require('./ArcadeImage'); var ArcadeSprite = require('./ArcadeSprite'); +var ArcadeRectangle = require('./ArcadeRectangle'); var Class = require('../../utils/Class'); var CONST = require('./const'); var PhysicsGroup = require('./PhysicsGroup'); @@ -115,6 +116,15 @@ var Factory = new Class({ return gameObject; }, + rectangle: function (x, y, width, height) + { + var body = new ArcadeRectangle(this.world, x, y, width, height); + + this.world.add(body); + + return body; + }, + /** * Creates a new Arcade Image object with a Static body. *