Skip to content

Commit adb28d2

Browse files
committed
Added new Rectangle Arcade Physics Body type
1 parent c819599 commit adb28d2

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Body = require('./Body');
8+
var Class = require('../../utils/Class');
9+
10+
/**
11+
* @classdesc
12+
* An Arcade Physics Image is an Image with an Arcade Physics body and related components.
13+
* The body can be dynamic or static.
14+
*
15+
* The main difference between an Arcade Image and an Arcade Sprite is that you cannot animate an Arcade Image.
16+
*
17+
* @class Rectangle
18+
* @memberof Phaser.Physics.Arcade
19+
* @constructor
20+
* @since 3.17.0
21+
*
22+
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
23+
* @param {number} x - The horizontal position of this Game Object in the world.
24+
* @param {number} y - The vertical position of this Game Object in the world.
25+
* @param {number} width - .
26+
* @param {number} height - .
27+
*/
28+
var ArcadeRectangle = new Class({
29+
30+
Extends: Body,
31+
32+
initialize:
33+
34+
function ArcadeRectangle (world, x, y, width, height)
35+
{
36+
Body.call(this, world, null, x, y, width, height);
37+
}
38+
39+
});
40+
41+
module.exports = ArcadeRectangle;

src/physics/arcade/Factory.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var ArcadeImage = require('./ArcadeImage');
88
var ArcadeSprite = require('./ArcadeSprite');
9+
var ArcadeRectangle = require('./ArcadeRectangle');
910
var Class = require('../../utils/Class');
1011
var CONST = require('./const');
1112
var PhysicsGroup = require('./PhysicsGroup');
@@ -115,6 +116,15 @@ var Factory = new Class({
115116
return gameObject;
116117
},
117118

119+
rectangle: function (x, y, width, height)
120+
{
121+
var body = new ArcadeRectangle(this.world, x, y, width, height);
122+
123+
this.world.add(body);
124+
125+
return body;
126+
},
127+
118128
/**
119129
* Creates a new Arcade Image object with a Static body.
120130
*

0 commit comments

Comments
 (0)