Added Phasers new Physics Manager and restored the pre-1.1.4 ArcadePhysics system. The new manager can handle multiple physics systems running in parallel, which could be extremely useful for lots of games.

This commit is contained in:
photonstorm
2014-03-05 02:36:08 +00:00
parent cc82336952
commit 22b1ce9b9d
26 changed files with 4004 additions and 908 deletions
+1
View File
@@ -214,6 +214,7 @@ Bug Fixes:
* You can now load in CSV Tilemaps again and they get created properly (fixes #391)
* Tilemap.putTile can now insert a tile into a null/blank area of the map (before it could only replace existing tiles)
* Tilemap.putTile now correctly re-calculates the collision data based on the new collideIndexes array (fixes #371)
* Circle.circumferencePoint using the asDegrees parameter would apply degToRad instead of radToDeg (thanks Ziriax, fixes #509)
TO DO:
+22 -8
View File
@@ -135,14 +135,20 @@
<script src="$path/src/utils/Debug.js"></script>
<script src="$path/src/utils/Color.js"></script>
<script src="$path/src/physics/World.js"></script>
<script src="$path/src/physics/PointProxy.js"></script>
<script src="$path/src/physics/InversePointProxy.js"></script>
<script src="$path/src/physics/Body.js"></script>
<script src="$path/src/physics/Spring.js"></script>
<script src="$path/src/physics/Material.js"></script>
<script src="$path/src/physics/ContactMaterial.js"></script>
<script src="$path/src/physics/CollisionGroup.js"></script>
<script src="$path/src/physics/Physics.js"></script>
<script src="$path/src/physics/arcade/World.js"></script>
<script src="$path/src/physics/arcade/Body.js"></script>
<script src="$path/src/physics/arcade/QuadTree.js"></script>
<script src="$path/src/physics/p2/World.js"></script>
<script src="$path/src/physics/p2/PointProxy.js"></script>
<script src="$path/src/physics/p2/InversePointProxy.js"></script>
<script src="$path/src/physics/p2/Body.js"></script>
<script src="$path/src/physics/p2/Spring.js"></script>
<script src="$path/src/physics/p2/Material.js"></script>
<script src="$path/src/physics/p2/ContactMaterial.js"></script>
<script src="$path/src/physics/p2/CollisionGroup.js"></script>
<script src="$path/src/particles/Particles.js"></script>
<script src="$path/src/particles/arcade/ArcadeParticles.js"></script>
@@ -154,4 +160,12 @@
<script src="$path/src/tilemap/TilemapParser.js"></script>
<script src="$path/src/tilemap/Tileset.js"></script>
EOL;
/*
*/
?>
+1 -1
View File
@@ -1450,7 +1450,7 @@ declare module Phaser {
static intersectsRectangle(c: Phaser.Circle, r: Phaser.Rectangle): boolean;
//methods
circumference(): number;
circumferencePoint(angle: number, asDegrees: number, output?: Phaser.Point): Phaser.Point;
circumferencePoint(angle: number, asDegrees: boolean, output?: Phaser.Point): Phaser.Point;
clone(out: Phaser.Circle): Phaser.Circle;
contains(x: number, y: number): boolean;
copyFrom(source: any): Circle;
+54
View File
@@ -0,0 +1,54 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
var sprite1;
var sprite2;
function create() {
game.stage.backgroundColor = '#2d2d2d';
// This will check Sprite vs. Sprite collision
sprite1 = game.add.sprite(50, 200, 'atari');
sprite1.name = 'atari';
sprite2 = game.add.sprite(700, 220, 'mushroom');
sprite2.name = 'mushroom';
// Enable the physics bodies of both sprites
game.physics.enable([sprite1, sprite2]);
// And move 'em
sprite1.body.velocity.x = 100;
sprite2.body.velocity.x = -100;
}
function update() {
// object1, object2, collideCallback, processCallback, callbackContext
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);
}
function collisionHandler (obj1, obj2) {
// The two sprites are colliding
game.stage.backgroundColor = '#992d2d';
}
function render() {
// game.debug.physicsBody(sprite1.body);
// game.debug.physicsBody(sprite2.body);
}
-2
View File
@@ -139,8 +139,6 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loop)
// Set-up some event listeners
this.game.onPause.add(this.onPause, this);
this.game.onResume.add(this.onResume, this);
console.log('animation created', this);
};
+2 -2
View File
@@ -172,7 +172,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.world = null;
/**
* @property {Phaser.Physics.World} physics - Reference to the physics world.
* @property {Phaser.Physics} physics - Reference to the physics manager.
*/
this.physics = null;
@@ -414,7 +414,7 @@ Phaser.Game.prototype = {
this.tweens = new Phaser.TweenManager(this);
this.input = new Phaser.Input(this);
this.sound = new Phaser.SoundManager(this);
this.physics = new Phaser.Physics.World(this, this.physicsConfig);
this.physics = new Phaser.Physics(this, this.physicsConfig);
this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this);
-729
View File
@@ -1,729 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2014 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Game constructor
*
* Instantiate a new <code>Phaser.Game</code> object.
* @class Phaser.Game
* @classdesc This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
* @constructor
* @param {number} [width=800] - The width of your game in game pixels.
* @param {number} [height=600] - The height of your game in game pixels.
* @param {number} [renderer=Phaser.AUTO] - Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all).
* @param {string|HTMLElement} [parent=''] - The DOM element into which this games canvas will be injected. Either a DOM ID (string) or the element itself.
* @param {object} [state=null] - The default state object. A object consisting of Phaser.State functions (preload, create, update, render) or null.
* @param {boolean} [transparent=false] - Use a transparent canvas background or not.
* @param {boolean} [antialias=true] - Draw all image textures anti-aliased or not. The default is for smooth textures, but disable if your game features pixel art.
*/
Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) {
/**
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
*/
this.id = Phaser.GAMES.push(this) - 1;
/**
* @property {object} config - The Phaser.Game configuration object.
*/
this.config = null;
/**
* @property {HTMLElement} parent - The Games DOM parent.
* @default
*/
this.parent = '';
/**
* @property {number} width - The Game width (in pixels).
* @default
*/
this.width = 800;
/**
* @property {number} height - The Game height (in pixels).
* @default
*/
this.height = 600;
/**
* @property {boolean} transparent - Use a transparent canvas background or not.
* @default
*/
this.transparent = false;
/**
* @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
* @default
*/
this.antialias = true;
/**
* @property {number} renderer - The Pixi Renderer
* @default
*/
this.renderer = Phaser.AUTO;
/**
* @property {number} renderType - The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS or Phaser.WEBGL.
*/
this.renderType = Phaser.AUTO;
/**
* @property {number} state - The StateManager.
*/
this.state = null;
/**
* @property {boolean} isBooted - Whether the game engine is booted, aka available.
* @default
*/
this.isBooted = false;
/**
* @property {boolean} id -Is game running or paused?
* @default
*/
this.isRunning = false;
/**
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
*/
this.raf = null;
/**
* @property {Phaser.GameObjectFactory} add - Reference to the Phaser.GameObjectFactory.
*/
this.add = null;
/**
* @property {Phaser.GameObjectCreator} make - Reference to the GameObject Creator.
*/
this.make = null;
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;
/**
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;
/**
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;
/**
* @property {Phaser.Math} math - Reference to the math helper.
*/
this.math = null;
/**
* @property {Phaser.Net} net - Reference to the network class.
*/
this.net = null;
/**
* @property {Phaser.ScaleManager} scale - The game scale manager.
*/
this.scale = null;
/**
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
*/
this.sound = null;
/**
* @property {Phaser.Stage} stage - Reference to the stage.
*/
this.stage = null;
/**
* @property {Phaser.TimeManager} time - Reference to game clock.
*/
this.time = null;
/**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
*/
this.tweens = null;
/**
* @property {Phaser.World} world - Reference to the world.
*/
this.world = null;
/**
* @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper.
*/
this.rnd = null;
/**
* @property {Phaser.Device} device - Contains device information and capabilities.
*/
this.device = null;
/**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
*/
this.camera = null;
/**
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view, the canvas that the game is being rendered in to.
*/
this.canvas = null;
/**
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games, not WebGL)
*/
this.context = null;
/**
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
*/
this.debug = null;
/**
* @property {boolean} stepping - Enable core loop stepping with Game.enableStep().
* @default
* @readonly
*/
this.stepping = false;
/**
* @property {boolean} stepping - An internal property used by enableStep, but also useful to query from your own game objects.
* @default
* @readonly
*/
this.pendingStep = false;
/**
* @property {number} stepCount - When stepping is enabled this contains the current step cycle.
* @default
* @readonly
*/
this.stepCount = 0;
/**
* @property {boolean} _paused - Is game paused?
* @private
* @default
*/
this._paused = false;
/**
* @property {boolean} _codePaused - Was the game paused via code or a visibility change?
* @private
* @default
*/
this._codePaused = false;
// Parse the configuration object (if any)
if (arguments.length === 1 && typeof arguments[0] === 'object')
{
this.parseConfig(arguments[0]);
}
else
{
if (typeof width !== 'undefined')
{
this.width = width;
}
if (typeof height !== 'undefined')
{
this.height = height;
}
if (typeof renderer !== 'undefined')
{
this.renderer = renderer;
this.renderType = renderer;
}
if (typeof parent !== 'undefined')
{
this.parent = parent;
}
if (typeof transparent !== 'undefined')
{
this.transparent = transparent;
}
if (typeof antialias !== 'undefined')
{
this.antialias = antialias;
}
this.state = new Phaser.StateManager(this, state);
}
var _this = this;
this._onBoot = function () {
return _this.boot();
}
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
window.setTimeout(this._onBoot, 0);
}
else
{
document.addEventListener('DOMContentLoaded', this._onBoot, false);
window.addEventListener('load', this._onBoot, false);
}
return this;
};
Phaser.Game.prototype = {
/**
* Parses a Game configuration object.
*
* @method Phaser.Game#parseConfig
* @protected
*/
parseConfig: function (config) {
this.config = config;
if (config['width'])
{
this.width = Phaser.Utils.parseDimension(config['width'], 0);
}
if (config['height'])
{
this.height = Phaser.Utils.parseDimension(config['height'], 1);
}
if (config['renderer'])
{
this.renderer = config['renderer'];
this.renderType = config['renderer'];
}
if (config['parent'])
{
this.parent = config['parent'];
}
if (config['transparent'])
{
this.transparent = config['transparent'];
}
if (config['antialias'])
{
this.antialias = config['antialias'];
}
var state = null;
if (config['state'])
{
state = config['state'];
}
this.state = new Phaser.StateManager(this, state);
},
/**
* Initialize engine sub modules and start the game.
*
* @method Phaser.Game#boot
* @protected
*/
boot: function () {
if (this.isBooted)
{
return;
}
if (!document.body)
{
window.setTimeout(this._onBoot, 20);
}
else
{
document.removeEventListener('DOMContentLoaded', this._onBoot);
window.removeEventListener('load', this._onBoot);
this.onPause = new Phaser.Signal();
this.onResume = new Phaser.Signal();
this.isBooted = true;
this.device = new Phaser.Device(this);
this.math = Phaser.Math;
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
this.stage = new Phaser.Stage(this, this.width, this.height);
this.scale = new Phaser.ScaleManager(this, this.width, this.height);
this.setUpRenderer();
this.device.checkFullScreenSupport();
this.world = new Phaser.World(this);
this.add = new Phaser.GameObjectFactory(this);
this.make = new Phaser.GameObjectCreator(this);
this.cache = new Phaser.Cache(this);
this.load = new Phaser.Loader(this);
this.time = new Phaser.Time(this);
this.tweens = new Phaser.TweenManager(this);
this.input = new Phaser.Input(this);
this.sound = new Phaser.SoundManager(this);
this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this);
this.time.boot();
this.stage.boot();
this.world.boot();
this.input.boot();
this.sound.boot();
this.state.boot();
this.showDebugHeader();
this.isRunning = true;
if (this.config && this.config['forceSetTimeOut'])
{
this.raf = new Phaser.RequestAnimationFrame(this, this.config['forceSetTimeOut']);
}
else
{
this.raf = new Phaser.RequestAnimationFrame(this, false);
}
this.raf.start();
}
},
/**
* Displays a Phaser version debug header in the console.
*
* @method Phaser.Game#showDebugHeader
* @protected
*/
showDebugHeader: function () {
var v = Phaser.DEV_VERSION;
var r = 'Canvas';
var a = 'HTML Audio';
if (this.renderType == Phaser.WEBGL)
{
r = 'WebGL';
}
else if (this.renderType == Phaser.HEADLESS)
{
r = 'Headless';
}
if (this.device.webAudio)
{
a = 'WebAudio';
}
if (this.device.chrome)
{
var args = [
'%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ',
'background: #00bff3',
'background: #0072bc',
'color: #ffffff; background: #003471',
'background: #0072bc',
'background: #00bff3'
];
console.log.apply(console, args);
}
else
{
console.log('Phaser v' + v + '.np - Renderer: ' + r + ' - Audio: ' + a);
}
},
/**
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
*
* @method Phaser.Game#setUpRenderer
* @protected
*/
setUpRenderer: function () {
if (this.device.trident)
{
// Pixi WebGL renderer on IE11 doesn't work correctly at the moment, the pre-multiplied alpha gets all washed out.
// So we're forcing canvas for now until this is fixed, sorry. It's got to be better than no game appearing at all, right?
this.renderType = Phaser.CANVAS;
}
if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
{
if (this.device.canvas)
{
if (this.renderType === Phaser.AUTO)
{
this.renderType = Phaser.CANVAS;
}
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.canvas, this.transparent);
this.context = this.renderer.context;
}
else
{
throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.');
}
}
else
{
// They requested WebGL, and their browser supports it
this.renderType = Phaser.WEBGL;
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.canvas, this.transparent, this.antialias);
this.context = null;
}
if (!this.antialias)
{
this.stage.smoothed = false;
}
Phaser.Canvas.addToDOM(this.canvas, this.parent, true);
Phaser.Canvas.setTouchAction(this.canvas);
},
/**
* The core game loop.
*
* @method Phaser.Game#update
* @protected
* @param {number} time - The current time as provided by RequestAnimationFrame.
*/
update: function (time) {
this.time.update(time);
if (this._paused)
{
this.input.update();
if (this.renderType !== Phaser.HEADLESS)
{
this.renderer.render(this.stage);
this.plugins.render();
this.state.render();
this.plugins.postRender();
}
}
else
{
if (!this.pendingStep)
{
if (this.stepping)
{
this.pendingStep = true;
}
this.state.preUpdate();
this.plugins.preUpdate();
this.stage.preUpdate();
this.stage.update();
this.tweens.update();
this.sound.update();
this.input.update();
this.state.update();
this.plugins.update();
this.stage.postUpdate();
this.plugins.postUpdate();
}
if (this.renderType !== Phaser.HEADLESS)
{
this.renderer.render(this.stage);
this.plugins.render();
this.state.render();
this.plugins.postRender();
}
}
},
/**
* Enable core game loop stepping. When enabled you must call game.step() directly (perhaps via a DOM button?)
* Calling step will advance the game loop by one frame. This is extremely useful to hard to track down errors!
*
* @method Phaser.Game#enableStep
*/
enableStep: function () {
this.stepping = true;
this.pendingStep = false;
this.stepCount = 0;
},
/**
* Disables core game loop stepping.
*
* @method Phaser.Game#disableStep
*/
disableStep: function () {
this.stepping = false;
this.pendingStep = false;
},
/**
* When stepping is enabled you must call this function directly (perhaps via a DOM button?) to advance the game loop by one frame.
* This is extremely useful to hard to track down errors! Use the internal stepCount property to monitor progress.
*
* @method Phaser.Game#step
*/
step: function () {
this.pendingStep = false;
this.stepCount++;
},
/**
* Nuke the entire game from orbit
*
* @method Phaser.Game#destroy
*/
destroy: function () {
this.raf.stop();
this.input.destroy();
this.state.destroy();
this.state = null;
this.cache = null;
this.input = null;
this.load = null;
this.sound = null;
this.stage = null;
this.time = null;
this.world = null;
this.isBooted = false;
},
/**
* Called by the Stage visibility handler.
*
* @method Phaser.Game#gamePaused
*/
gamePaused: function (time) {
// If the game is already paused it was done via game code, so don't re-pause it
if (!this._paused)
{
this._paused = true;
this.time.gamePaused(time);
this.sound.setMute();
this.onPause.dispatch(this);
}
},
/**
* Called by the Stage visibility handler.
*
* @method Phaser.Game#gameResumed
*/
gameResumed: function (time) {
// Game is paused, but wasn't paused via code, so resume it
if (this._paused && !this._codePaused)
{
this._paused = false;
this.time.gameResumed(time);
this.input.reset();
this.sound.unsetMute();
this.onResume.dispatch(this);
}
}
};
Phaser.Game.prototype.constructor = Phaser.Game;
/**
* The paused state of the Game. A paused game doesn't update any of its subsystems.
* When a game is paused the onPause event is dispatched. When it is resumed the onResume event is dispatched.
* @name Phaser.Game#paused
* @property {boolean} paused - Gets and sets the paused state of the Game.
*/
Object.defineProperty(Phaser.Game.prototype, "paused", {
get: function () {
return this._paused;
},
set: function (value) {
if (value === true)
{
if (this._paused === false)
{
this._paused = true;
this._codePaused = true;
this.sound.mute = true;
this.time.gamePaused();
this.onPause.dispatch(this);
}
}
else
{
if (this._paused)
{
this._paused = false;
this._codePaused = false;
this.input.reset();
this.sound.mute = false;
this.time.gameResumed();
this.onResume.dispatch(this);
}
}
}
});
/**
* "Deleted code is debugged code." - Jeff Sickel
*/
+2 -9
View File
@@ -286,10 +286,7 @@ Phaser.StateManager.prototype = {
this.game.world.destroy();
if (this.game.physics)
{
this.game.physics.clear();
}
this.game.physics.clear();
if (this._clearCache === true)
{
@@ -388,11 +385,7 @@ Phaser.StateManager.prototype = {
this.states[key].world = this.game.world;
this.states[key].particles = this.game.particles;
this.states[key].rnd = this.game.rnd;
if (this.game.physics)
{
this.states[key].physics = this.game.physics;
}
this.states[key].physics = this.game.physics;
},
+3 -10
View File
@@ -466,18 +466,11 @@ Phaser.Image.prototype.reset = function(x, y) {
* @memberof Phaser.Image
* @return {Phaser.Image} This instance.
*/
Phaser.Image.prototype.bringToTop = function(child) {
Phaser.Image.prototype.bringToTop = function() {
if (typeof child === 'undefined')
if (this.parent)
{
if (this.parent)
{
this.parent.bringToTop(this);
}
}
else
{
this.parent.bringToTop(this);
}
return this;
+14 -19
View File
@@ -99,7 +99,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
this.input = null;
/**
* @property {Phaser.Physics.Body|null} body - The Sprites physics Body. Will be null unless physics has been enabled via `Sprite.physicsEnabled = true`.
* @property {Phaser.Physics.Arcade.Body|Phaser.Physics.P2.Body|null} body - The Sprites physics Body. Will be null unless physics has been enabled via `Sprite.physicsEnabled = true`.
*/
this.body = null;
@@ -253,6 +253,11 @@ Phaser.Sprite.prototype.preUpdate = function() {
this.animations.update();
if (this.exists && this.body)
{
this.body.preUpdate();
}
// Update any Children
for (var i = 0, len = this.children.length; i < len; i++)
{
@@ -287,12 +292,9 @@ Phaser.Sprite.prototype.postUpdate = function() {
this.key.render();
}
if (this.exists)
if (this.exists && this.body)
{
if (this.body)
{
this.body.postUpdate();
}
this.body.postUpdate();
}
// Fixed to Camera?
@@ -624,18 +626,11 @@ Phaser.Sprite.prototype.reset = function(x, y, health) {
* @memberof Phaser.Sprite
* @return (Phaser.Sprite) This instance.
*/
Phaser.Sprite.prototype.bringToTop = function(child) {
Phaser.Sprite.prototype.bringToTop = function() {
if (typeof child === 'undefined')
if (this.parent)
{
if (this.parent)
{
this.parent.bringToTop(this);
}
}
else
{
this.parent.bringToTop(this);
}
return this;
@@ -856,16 +851,15 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
});
/**
* By default Sprites won't add themselves to the physics world. By setting physicsEnabled to true a Rectangle physics body is
* By default Sprites won't add themselves to the physics simulation. By setting physicsEnabled to true a Rectangle physics body is
* attached to this Sprite matching its placement and dimensions, and will then start to process physics world updates.
* You can access all physics related properties via Sprite.body.
*
* Important: Enabling a Sprite for physics will automatically set `Sprite.anchor` to 0.5 s0 the physics body is centered on the Sprite.
* Important: Enabling a Sprite for physics will automatically set `Sprite.anchor` to 0.5 so the physics body is centered on the Sprite.
* If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics.
*
* @name Phaser.Sprite#physicsEnabled
* @property {boolean} physicsEnabled - Set to true to add this Sprite to the physics world. Set to false to destroy the body and remove it from the physics world.
*/
Object.defineProperty(Phaser.Sprite.prototype, "physicsEnabled", {
get: function () {
@@ -894,6 +888,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "physicsEnabled", {
}
});
*/
/**
* Sprite.exists controls if the core game loop and physics update this Sprite or not.
+1 -1
View File
@@ -482,7 +482,7 @@ Phaser.Circle.circumferencePoint = function (a, angle, asDegrees, out) {
if (asDegrees === true)
{
angle = Phaser.Math.radToDeg(angle);
angle = Phaser.Math.degToRad(angle);
}
out.x = a.x + a.radius * Math.cos(angle);
+145
View File
@@ -0,0 +1,145 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2014 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Physics manager.
*
* @class Phaser.Physics
*
* @classdesc todo
*
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {object} [physicsConfig=null] - A physics configuration object to pass to the Physics world on creation.
*/
Phaser.Physics = function (game, config) {
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
this.config = config;
this.arcade = new Phaser.Physics.Arcade(game);
this.p2 = null;
this.box2d = null;
this.chipmunk = null;
};
/**
* @const
* @type {number}
*/
Phaser.Physics.ARCADE = 0;
/**
* @const
* @type {number}
*/
Phaser.Physics.P2 = 1;
/**
* @const
* @type {number}
*/
Phaser.Physics.BOX2D = 2;
/**
* @const
* @type {number}
*/
Phaser.Physics.CHIPMUNK = 3;
Phaser.Physics.prototype = {
startSystem: function (system) {
if (system === Phaser.Physics.ARCADE)
{
this.arcade = new Phaser.Physics.Arcade(this.game);
}
else if (system === Phaser.Physics.P2)
{
this.p2 = new Phaser.Physics.P2(this.game, this.config);
}
else if (system === Phaser.Physics.BOX2D)
{
// Coming soon
}
else if (system === Phaser.Physics.CHIPMUNK)
{
// Coming soon
}
},
// Enables a sprites physics body
enable: function (object, system) {
if (typeof system === 'undefined') { system = Phaser.Physics.ARCADE; }
var i = 1;
if (Array.isArray(object))
{
// Add to Group
i = object.length;
}
else
{
object = [object];
}
while (i--)
{
if (object[i].body === null)
{
if (system === Phaser.Physics.ARCADE)
{
object[i].body = new Phaser.Physics.Arcade.Body(object[i]);
}
else if (system === Phaser.Physics.P2)
{
object[i].body = new Phaser.Physics.P2.Body(this.game, object[i], object[i].x, object[i].y, 1);
object[i].anchor.set(0.5);
}
}
}
},
update: function () {
// ArcadePhysics doesn't have a core to update
if (this.p2)
{
this.p2.update();
}
},
setBoundsToWorld: function () {
},
clear: function () {
if (this.p2)
{
this.p2.clear();
}
}
};
Phaser.Physics.prototype.constructor = Phaser.Physics;
+635
View File
@@ -0,0 +1,635 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than
* the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body.
*
* @class Phaser.Physics.Arcade.Body
* @classdesc Arcade Physics Body Constructor
* @constructor
* @param {Phaser.Sprite} sprite - The Sprite object this physics body belongs to.
*/
Phaser.Physics.Arcade.Body = function (sprite) {
/**
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
*/
this.sprite = sprite;
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = sprite.game;
/**
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
*/
this.offset = new Phaser.Point();
/**
* @property {number} x - The x position of the physics body.
* @readonly
*/
this.x = sprite.x;
/**
* @property {number} y - The y position of the physics body.
* @readonly
*/
this.y = sprite.y;
/**
* @property {number} preX - The previous x position of the physics body.
* @readonly
*/
this.preX = sprite.x;
/**
* @property {number} preY - The previous y position of the physics body.
* @readonly
*/
this.preY = sprite.y;
/**
* @property {number} preRotation - The previous rotation of the physics body.
* @readonly
*/
this.preRotation = sprite.angle;
/**
* @property {number} screenX - The x position of the physics body translated to screen space.
* @readonly
*/
this.screenX = sprite.x;
/**
* @property {number} screenY - The y position of the physics body translated to screen space.
* @readonly
*/
this.screenY = sprite.y;
/**
* @property {number} sourceWidth - The un-scaled original size.
* @readonly
*/
this.sourceWidth = sprite.texture.frame.width;
/**
* @property {number} sourceHeight - The un-scaled original size.
* @readonly
*/
this.sourceHeight = sprite.texture.frame.height;
/**
* @property {number} width - The calculated width of the physics body.
*/
this.width = sprite.width;
/**
* @property .numInternal ID cache
*/
this.height = sprite.height;
/**
* @property {number} halfWidth - The calculated width / 2 of the physics body.
*/
this.halfWidth = Math.floor(sprite.width / 2);
/**
* @property {number} halfHeight - The calculated height / 2 of the physics body.
*/
this.halfHeight = Math.floor(sprite.height / 2);
/**
* @property {Phaser.Point} center - The center coordinate of the Physics Body.
*/
this.center = new Phaser.Point(this.x + this.halfWidth, this.y + this.halfHeight);
/**
* @property {number} _sx - Internal cache var.
* @private
*/
this._sx = sprite.scale.x;
/**
* @property {number} _sy - Internal cache var.
* @private
*/
this._sy = sprite.scale.y;
/**
* @property {Phaser.Point} velocity - The velocity in pixels per second sq. of the Body.
*/
this.velocity = new Phaser.Point();
/**
* @property {Phaser.Point} acceleration - The velocity in pixels per second sq. of the Body.
*/
this.acceleration = new Phaser.Point();
/**
* @property {Phaser.Point} drag - The drag applied to the motion of the Body.
*/
this.drag = new Phaser.Point();
/**
* @property {Phaser.Point} gravity - A private Gravity setting for the Body.
*/
this.gravity = new Phaser.Point();
/**
* @property {Phaser.Point} bounce - The elasticitiy of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
*/
this.bounce = new Phaser.Point();
/**
* @property {Phaser.Point} maxVelocity - The maximum velocity in pixels per second sq. that the Body can reach.
* @default
*/
this.maxVelocity = new Phaser.Point(10000, 10000);
/**
* @property {number} angularVelocity - The angular velocity in pixels per second sq. of the Body.
* @default
*/
this.angularVelocity = 0;
/**
* @property {number} angularAcceleration - The angular acceleration in pixels per second sq. of the Body.
* @default
*/
this.angularAcceleration = 0;
/**
* @property {number} angularDrag - The angular drag applied to the rotation of the Body.
* @default
*/
this.angularDrag = 0;
/**
* @property {number} maxAngular - The maximum angular velocity in pixels per second sq. that the Body can reach.
* @default
*/
this.maxAngular = 1000;
/**
* @property {number} mass - The mass of the Body.
* @default
*/
this.mass = 1;
/**
* @property {boolean} skipQuadTree - If the Body is an irregular shape you can set this to true to avoid it being added to any QuadTrees.
* @default
*/
this.skipQuadTree = false;
// Allow collision
/**
* Set the allowCollision properties to control which directions collision is processed for this Body.
* For example allowCollision.up = false means it won't collide when the collision happened while moving up.
* @property {object} allowCollision - An object containing allowed collision.
*/
// This would be faster as an array
this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
/**
* This object is populated with boolean values when the Body collides with another.
* touching.up = true means the collision happened to the top of this Body for example.
* @property {object} touching - An object containing touching results.
*/
// This would be faster as an array
this.touching = { none: true, up: false, down: false, left: false, right: false };
/**
* This object is populated with previous touching values from the bodies previous collision.
* @property {object} wasTouching - An object containing previous touching results.
*/
// This would be faster as an array
this.wasTouching = { none: true, up: false, down: false, left: false, right: false };
/**
* @property {number} facing - A const reference to the direction the Body is traveling or facing.
* @default
*/
this.facing = Phaser.NONE;
/**
* @property {boolean} immovable - An immovable Body will not receive any impacts from other bodies.
* @default
*/
this.immovable = false;
/**
* @property {boolean} moves - Set to true to allow the Physics system to move this Body, other false to move it manually.
* @default
*/
this.moves = true;
/**
* @property {number} rotation - The amount the Body is rotated.
* @default
*/
this.rotation = 0;
/**
* @property {boolean} allowRotation - Allow this Body to be rotated? (via angularVelocity, etc)
* @default
*/
this.allowRotation = true;
/**
* @property {boolean} allowGravity - Allow this Body to be influenced by the global Gravity?
* @default
*/
this.allowGravity = true;
/**
* This flag allows you to disable the custom x separation that takes place by Physics.Arcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* @property {boolean} customSeparateX - Use a custom separation system or the built-in one?
* @default
*/
this.customSeparateX = false;
/**
* This flag allows you to disable the custom y separation that takes place by Physics.Arcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* @property {boolean} customSeparateY - Use a custom separation system or the built-in one?
* @default
*/
this.customSeparateY = false;
/**
* When this body collides with another, the amount of overlap is stored here.
* @property {number} overlapX - The amount of horizontal overlap during the collision.
*/
this.overlapX = 0;
/**
* When this body collides with another, the amount of overlap is stored here.
* @property {number} overlapY - The amount of vertical overlap during the collision.
*/
this.overlapY = 0;
this.hull = new Phaser.Rectangle();
/**
* @property {Phaser.Rectangle} hullX - The dynamically calculated hull used during collision.
*/
this.hullX = new Phaser.Rectangle();
/**
* @property {Phaser.Rectangle} hullY - The dynamically calculated hull used during collision.
*/
this.hullY = new Phaser.Rectangle();
/**
* If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true.
* @property {boolean} embedded - Body embed value.
*/
this.embedded = false;
/**
* A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World.
* @property {boolean} collideWorldBounds - Should the Body collide with the World bounds?
*/
this.collideWorldBounds = false;
this.blocked = { up: false, down: false, left: false, right: false };
};
Phaser.Physics.Arcade.Body.prototype = {
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#updateBounds
* @protected
*/
updateBounds: function (centerX, centerY, scaleX, scaleY) {
if (scaleX != this._sx || scaleY != this._sy)
{
this.width = this.sourceWidth * scaleX;
this.height = this.sourceHeight * scaleY;
this.halfWidth = Math.floor(this.width / 2);
this.halfHeight = Math.floor(this.height / 2);
this._sx = scaleX;
this._sy = scaleY;
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
}
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#preUpdate
* @protected
*/
preUpdate: function () {
// Store and reset collision flags
this.wasTouching.none = this.touching.none;
this.wasTouching.up = this.touching.up;
this.wasTouching.down = this.touching.down;
this.wasTouching.left = this.touching.left;
this.wasTouching.right = this.touching.right;
this.touching.none = true;
this.touching.up = false;
this.touching.down = false;
this.touching.left = false;
this.touching.right = false;
this.embedded = false;
this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = this.preX;
this.y = this.preY;
this.rotation = this.preRotation;
// this.overlapX = 0;
// this.overlapY = 0;
this.blocked.up = false;
this.blocked.down = false;
this.blocked.left = false;
this.blocked.right = false;
if (this.moves)
{
this.game.physics.arcade.updateMotion(this);
if (this.collideWorldBounds)
{
this.checkWorldBounds();
}
}
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#postUpdate
* @protected
*/
postUpdate: function () {
// if (this.overlapX !== 0)
// {
// this.x -= this.overlapX;
// }
// if (this.overlapY !== 0)
// {
// this.y -= this.overlapY;
// }
if (this.deltaX() < 0 && this.blocked.left === false)
{
this.facing = Phaser.LEFT;
this.sprite.x += this.deltaX();
}
else if (this.deltaX() > 0 && this.blocked.right === false)
{
this.facing = Phaser.RIGHT;
this.sprite.x += this.deltaX();
}
if (this.deltaY() < 0 && this.blocked.up === false)
{
this.facing = Phaser.UP;
this.sprite.y += this.deltaY();
}
else if (this.deltaY() > 0 && this.blocked.down === false)
{
this.facing = Phaser.DOWN;
this.sprite.y += this.deltaY();
}
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
if (this.allowRotation)
{
this.sprite.angle += this.deltaZ();
}
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#checkWorldBounds
* @protected
*/
checkWorldBounds: function () {
if (this.x < this.game.world.bounds.x)
{
this.x = this.game.world.bounds.x;
this.velocity.x *= -this.bounce.x;
}
else if (this.right > this.game.world.bounds.right)
{
this.x = this.game.world.bounds.right - this.width;
this.velocity.x *= -this.bounce.x;
}
if (this.y < this.game.world.bounds.y)
{
this.y = this.game.world.bounds.y;
this.velocity.y *= -this.bounce.y;
}
else if (this.bottom > this.game.world.bounds.bottom)
{
this.y = this.game.world.bounds.bottom - this.height;
this.velocity.y *= -this.bounce.y;
}
},
/**
* You can modify the size of the physics Body to be any dimension you need.
* So it could be smaller or larger than the parent Sprite. You can also control the x and y offset, which
* is the position of the Body relative to the top-left of the Sprite.
*
* @method Phaser.Physics.Arcade#setSize
* @param {number} width - The width of the Body.
* @param {number} height - The height of the Body.
* @param {number} offsetX - The X offset of the Body from the Sprite position.
* @param {number} offsetY - The Y offset of the Body from the Sprite position.
*/
setSize: function (width, height, offsetX, offsetY) {
offsetX = offsetX || this.offset.x;
offsetY = offsetY || this.offset.y;
this.sourceWidth = width;
this.sourceHeight = height;
this.width = this.sourceWidth * this._sx;
this.height = this.sourceHeight * this._sy;
this.halfWidth = Math.floor(this.width / 2);
this.halfHeight = Math.floor(this.height / 2);
this.offset.setTo(offsetX, offsetY);
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
},
/**
* Resets all Body values (velocity, acceleration, rotation, etc)
*
* @method Phaser.Physics.Arcade#reset
*/
reset: function () {
this.velocity.setTo(0, 0);
this.acceleration.setTo(0, 0);
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = this.preX;
this.y = this.preY;
this.rotation = this.preRotation;
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
},
/**
* Returns the absolute delta x value.
*
* @method Phaser.Physics.Arcade.Body#deltaAbsX
* @return {number} The absolute delta value.
*/
deltaAbsX: function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
},
/**
* Returns the absolute delta y value.
*
* @method Phaser.Physics.Arcade.Body#deltaAbsY
* @return {number} The absolute delta value.
*/
deltaAbsY: function () {
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
},
/**
* Returns the delta x value. The difference between Body.x now and in the previous step.
*
* @method Phaser.Physics.Arcade.Body#deltaX
* @return {number} The delta value. Positive if the motion was to the right, negative if to the left.
*/
deltaX: function () {
return this.x - this.preX;
},
/**
* Returns the delta y value. The difference between Body.y now and in the previous step.
*
* @method Phaser.Physics.Arcade.Body#deltaY
* @return {number} The delta value. Positive if the motion was downwards, negative if upwards.
*/
deltaY: function () {
return this.y - this.preY;
},
deltaZ: function () {
return this.rotation - this.preRotation;
}
};
/**
* @name Phaser.Physics.Arcade.Body#bottom
* @property {number} bottom - The bottom value of this Body (same as Body.y + Body.height)
*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @return {number}
*/
get: function () {
return Math.floor(this.y + this.height);
},
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @param {number} value
*/
set: function (value) {
if (value <= this.y)
{
this.height = 0;
}
else
{
this.height = (this.y - value);
}
}
});
/**
* @name Phaser.Physics.Arcade.Body#right
* @property {number} right - The right value of this Body (same as Body.x + Body.width)
*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @return {number}
*/
get: function () {
return Math.floor(this.x + this.width);
},
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @param {number} value
*/
set: function (value) {
if (value <= this.x)
{
this.width = 0;
}
else
{
this.width = this.x + value;
}
}
});
+265
View File
@@ -0,0 +1,265 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Javascript QuadTree
* @version 1.0
* @author Timo Hausmann
*
* @version 1.2, September 4th 2013
* @author Richard Davey
* The original code was a conversion of the Java code posted to GameDevTuts. However I've tweaked
* it massively to add node indexing, removed lots of temp. var creation and significantly
* increased performance as a result.
*
* Original version at https://github.com/timohausmann/quadtree-js/
*/
/**
* @copyright © 2012 Timo Hausmann
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* QuadTree Constructor
*
* @class Phaser.Physics.Arcade.QuadTree
* @classdesc A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts. However I've tweaked
* it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result. Original version at https://github.com/timohausmann/quadtree-js/
* @constructor
* @param {Description} physicsManager - Description.
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {number} width - The width of your game in game pixels.
* @param {number} height - The height of your game in game pixels.
* @param {number} maxObjects - Description.
* @param {number} maxLevels - Description.
* @param {number} level - Description.
*/
Phaser.Physics.Arcade.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
this.physicsManager = physicsManager;
this.ID = physicsManager.quadTreeID;
physicsManager.quadTreeID++;
this.maxObjects = maxObjects || 10;
this.maxLevels = maxLevels || 4;
this.level = level || 0;
this.bounds = {
x: Math.round(x),
y: Math.round(y),
width: width,
height: height,
subWidth: Math.floor(width / 2),
subHeight: Math.floor(height / 2),
right: Math.round(x) + Math.floor(width / 2),
bottom: Math.round(y) + Math.floor(height / 2)
};
this.objects = [];
this.nodes = [];
};
Phaser.Physics.Arcade.QuadTree.prototype = {
/*
* Split the node into 4 subnodes
*
* @method Phaser.Physics.Arcade.QuadTree#split
*/
split: function() {
this.level++;
// top right node
this.nodes[0] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
// top left node
this.nodes[1] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
// bottom left node
this.nodes[2] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
// bottom right node
this.nodes[3] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
},
/*
* Insert the object into the node. If the node
* exceeds the capacity, it will split and add all
* objects to their corresponding subnodes.
*
* @method Phaser.Physics.Arcade.QuadTree#insert
* @param {object} body - Description.
*/
insert: function (body) {
var i = 0;
var index;
// if we have subnodes ...
if (this.nodes[0] != null)
{
index = this.getIndex(body);
if (index !== -1)
{
this.nodes[index].insert(body);
return;
}
}
this.objects.push(body);
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
{
// Split if we don't already have subnodes
if (this.nodes[0] == null)
{
this.split();
}
// Add objects to subnodes
while (i < this.objects.length)
{
index = this.getIndex(this.objects[i]);
if (index !== -1)
{
// this is expensive - see what we can do about it
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
}
else
{
i++;
}
}
}
},
/*
* Determine which node the object belongs to.
*
* @method Phaser.Physics.Arcade.QuadTree#getIndex
* @param {object} rect - Description.
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
*/
getIndex: function (rect) {
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
var index = -1;
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
{
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
{
// rect fits within the top-left quadrant of this quadtree
index = 1;
}
else if ((rect.y > this.bounds.bottom))
{
// rect fits within the bottom-left quadrant of this quadtree
index = 2;
}
}
else if (rect.x > this.bounds.right)
{
// rect can completely fit within the right quadrants
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
{
// rect fits within the top-right quadrant of this quadtree
index = 0;
}
else if ((rect.y > this.bounds.bottom))
{
// rect fits within the bottom-right quadrant of this quadtree
index = 3;
}
}
return index;
},
/*
* Return all objects that could collide with the given object.
*
* @method Phaser.Physics.Arcade.QuadTree#retrieve
* @param {object} rect - Description.
* @Return {array} - Array with all detected objects.
*/
retrieve: function (sprite) {
var returnObjects = this.objects;
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
sprite.body.quadTreeIDs.push(this.ID);
if (this.nodes[0])
{
// if rect fits into a subnode ..
if (sprite.body.quadTreeIndex !== -1)
{
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
}
else
{
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
}
}
return returnObjects;
},
/*
* Clear the quadtree.
* @method Phaser.Physics.Arcade.QuadTree#clear
*/
clear: function () {
this.objects = [];
for (var i = 0, len = this.nodes.length; i < len; i++)
{
// if (typeof this.nodes[i] !== 'undefined')
if (this.nodes[i])
{
this.nodes[i].clear();
delete this.nodes[i];
}
}
}
};
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -7,11 +7,11 @@
/**
* Collision Group
*
* @class Phaser.Physics.CollisionGroup
* @class Phaser.Physics.P2.CollisionGroup
* @classdesc Physics Collision Group Constructor
* @constructor
*/
Phaser.Physics.CollisionGroup = function (bitmask) {
Phaser.Physics.P2.CollisionGroup = function (bitmask) {
/**
* @property {number} mask - The CollisionGroup bitmask.
@@ -7,25 +7,25 @@
/**
* Defines a physics material
*
* @class Phaser.Physics.ContactMaterial
* @class Phaser.Physics.P2.ContactMaterial
* @classdesc Physics ContactMaterial Constructor
* @constructor
* @param {Phaser.Physics.Material} materialA
* @param {Phaser.Physics.Material} materialB
* @param {Phaser.Physics.P2.Material} materialA
* @param {Phaser.Physics.P2.Material} materialB
* @param {object} [options]
*/
Phaser.Physics.ContactMaterial = function (materialA, materialB, options) {
Phaser.Physics.P2.ContactMaterial = function (materialA, materialB, options) {
/**
* @property {number} id - The contact material identifier.
*/
/**
* @property {Phaser.Physics.Material} materialA - First material participating in the contact material.
* @property {Phaser.Physics.P2.Material} materialA - First material participating in the contact material.
*/
/**
* @property {Phaser.Physics.Material} materialB - First second participating in the contact material.
* @property {Phaser.Physics.P2.Material} materialB - First second participating in the contact material.
*/
/**
@@ -60,5 +60,5 @@ Phaser.Physics.ContactMaterial = function (materialA, materialB, options) {
}
Phaser.Physics.ContactMaterial.prototype = Object.create(p2.ContactMaterial.prototype);
Phaser.Physics.ContactMaterial.prototype.constructor = Phaser.Physics.ContactMaterial;
Phaser.Physics.P2.ContactMaterial.prototype = Object.create(p2.ContactMaterial.prototype);
Phaser.Physics.P2.ContactMaterial.prototype.constructor = Phaser.Physics.P2.ContactMaterial;
@@ -7,26 +7,26 @@
/**
* A InversePointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays but inverses the values on set.
*
* @class Phaser.Physics.InversePointProxy
* @class Phaser.Physics.P2.InversePointProxy
* @classdesc InversePointProxy
* @constructor
* @param {Phaser.Game} game - A reference to the Phaser.Game instance.
* @param {any} destination - The object to bind to.
*/
Phaser.Physics.InversePointProxy = function (game, destination) {
Phaser.Physics.P2.InversePointProxy = function (game, destination) {
this.game = game;
this.destination = destination;
};
Phaser.Physics.InversePointProxy.prototype.constructor = Phaser.Physics.InversePointProxy;
Phaser.Physics.P2.InversePointProxy.prototype.constructor = Phaser.Physics.P2.InversePointProxy;
/**
* @name Phaser.Physics.InversePointProxy#x
* @name Phaser.Physics.P2.InversePointProxy#x
* @property {number} x - The x property of this InversePointProxy.
*/
Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "x", {
Object.defineProperty(Phaser.Physics.P2.InversePointProxy.prototype, "x", {
get: function () {
@@ -43,10 +43,10 @@ Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "x", {
});
/**
* @name Phaser.Physics.InversePointProxy#y
* @name Phaser.Physics.P2.InversePointProxy#y
* @property {number} y - The y property of this InversePointProxy.
*/
Object.defineProperty(Phaser.Physics.InversePointProxy.prototype, "y", {
Object.defineProperty(Phaser.Physics.P2.InversePointProxy.prototype, "y", {
get: function () {
@@ -7,11 +7,11 @@
/**
* \o/ ~ "Because I'm a Material girl"
*
* @class Phaser.Physics.Material
* @class Phaser.Physics.P2.Material
* @classdesc Physics Material Constructor
* @constructor
*/
Phaser.Physics.Material = function (name) {
Phaser.Physics.P2.Material = function (name) {
/**
* @property {string} name - The user defined name given to this Material.
@@ -23,5 +23,5 @@ Phaser.Physics.Material = function (name) {
}
Phaser.Physics.Material.prototype = Object.create(p2.Material.prototype);
Phaser.Physics.Material.prototype.constructor = Phaser.Physics.Material;
Phaser.Physics.P2.Material.prototype = Object.create(p2.Material.prototype);
Phaser.Physics.P2.Material.prototype.constructor = Phaser.Physics.P2.Material;
@@ -7,26 +7,26 @@
/**
* A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays.
*
* @class Phaser.Physics.PointProxy
* @class Phaser.Physics.P2.PointProxy
* @classdesc PointProxy
* @constructor
* @param {Phaser.Game} game - A reference to the Phaser.Game instance.
* @param {any} destination - The object to bind to.
*/
Phaser.Physics.PointProxy = function (game, destination) {
Phaser.Physics.P2.PointProxy = function (game, destination) {
this.game = game;
this.destination = destination;
};
Phaser.Physics.PointProxy.prototype.constructor = Phaser.Physics.PointProxy;
Phaser.Physics.P2.PointProxy.prototype.constructor = Phaser.Physics.P2.PointProxy;
/**
* @name Phaser.Physics.PointProxy#x
* @name Phaser.Physics.P2.PointProxy#x
* @property {number} x - The x property of this PointProxy.
*/
Object.defineProperty(Phaser.Physics.PointProxy.prototype, "x", {
Object.defineProperty(Phaser.Physics.P2.PointProxy.prototype, "x", {
get: function () {
@@ -43,10 +43,10 @@ Object.defineProperty(Phaser.Physics.PointProxy.prototype, "x", {
});
/**
* @name Phaser.Physics.PointProxy#y
* @name Phaser.Physics.P2.PointProxy#y
* @property {number} y - The y property of this PointProxy.
*/
Object.defineProperty(Phaser.Physics.PointProxy.prototype, "y", {
Object.defineProperty(Phaser.Physics.P2.PointProxy.prototype, "y", {
get: function () {
@@ -7,7 +7,7 @@
/**
* Creates a spring, connecting two bodies.
*
* @class Phaser.Physics.Spring
* @class Phaser.Physics.P2.Spring
* @classdesc Physics Spring Constructor
* @constructor
* @param {Phaser.Game} game - A reference to the current game.
@@ -21,7 +21,7 @@
* @param {Array} [localA] - Where to hook the spring to body A, in local body coordinates.
* @param {Array} [localB] - Where to hook the spring to body B, in local body coordinates.
*/
Phaser.Physics.Spring = function (game, bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB) {
Phaser.Physics.P2.Spring = function (game, bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB) {
/**
* @property {Phaser.Game} game - Local reference to game.
@@ -62,5 +62,5 @@ Phaser.Physics.Spring = function (game, bodyA, bodyB, restLength, stiffness, dam
}
Phaser.Physics.Spring.prototype = Object.create(p2.Spring.prototype);
Phaser.Physics.Spring.prototype.constructor = Phaser.Physics.Spring;
Phaser.Physics.P2.Spring.prototype = Object.create(p2.Spring.prototype);
Phaser.Physics.P2.Spring.prototype.constructor = Phaser.Physics.P2.Spring;
@@ -4,29 +4,24 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* @class Phaser.Physics
*/
Phaser.Physics = {};
/**
* @const
* @type {number}
*/
Phaser.Physics.LIME_CORONA_JSON = 0;
Phaser.Physics.P2.LIME_CORONA_JSON = 0;
// Add an extra properties to p2 that we need
p2.Body.prototype.parent = null;
p2.Spring.prototype.parent = null;
/**
* @class Phaser.Physics.World
* @class Phaser.Physics.P2
* @classdesc Physics World Constructor
* @constructor
* @param {Phaser.Game} game - Reference to the current game instance.
* @param {object} [config] - Physics configuration object passed in from the game constructor.
*/
Phaser.Physics.World = function (game, config) {
Phaser.Physics.P2 = function (game, config) {
/**
* @property {Phaser.Game} game - Local reference to game.
@@ -45,7 +40,7 @@ Phaser.Physics.World = function (game, config) {
this.world = new p2.World(config);
/**
* @property {array<Phaser.Physics.Material>} materials - A local array of all created Materials.
* @property {array<Phaser.Physics.P2.Material>} materials - A local array of all created Materials.
* @protected
*/
this.materials = [];
@@ -53,7 +48,7 @@ Phaser.Physics.World = function (game, config) {
/**
* @property {Phaser.InversePointProxy} gravity - The gravity applied to all bodies each step.
*/
this.gravity = new Phaser.Physics.InversePointProxy(game, this.world.gravity);
this.gravity = new Phaser.Physics.P2.InversePointProxy(game, this.world.gravity);
/**
* @property {p2.Body} bounds - The bounds body contains the 4 walls that border the World. Define or disable with setBounds.
@@ -149,9 +144,9 @@ Phaser.Physics.World = function (game, config) {
*/
this._collisionGroupID = 2;
this.nothingCollisionGroup = new Phaser.Physics.CollisionGroup(1);
this.boundsCollisionGroup = new Phaser.Physics.CollisionGroup(2);
this.everythingCollisionGroup = new Phaser.Physics.CollisionGroup(2147483648);
this.nothingCollisionGroup = new Phaser.Physics.P2.CollisionGroup(1);
this.boundsCollisionGroup = new Phaser.Physics.P2.CollisionGroup(2);
this.everythingCollisionGroup = new Phaser.Physics.P2.CollisionGroup(2147483648);
this.boundsCollidesWith = [];
@@ -162,12 +157,12 @@ Phaser.Physics.World = function (game, config) {
};
Phaser.Physics.World.prototype = {
Phaser.Physics.P2.prototype = {
/**
* Handles a p2 postStep event.
*
* @method Phaser.Physics.World#postStepHandler
* @method Phaser.Physics.P2#postStepHandler
* @private
* @param {object} event - The event data.
*/
@@ -179,7 +174,7 @@ Phaser.Physics.World.prototype = {
* Fired after the Broadphase has collected collision pairs in the world.
* Inside the event handler, you can modify the pairs array as you like, to prevent collisions between objects that you don't want.
*
* @method Phaser.Physics.World#postBroadphaseHandler
* @method Phaser.Physics.P2#postBroadphaseHandler
* @private
* @param {object} event - The event data.
*/
@@ -203,7 +198,7 @@ Phaser.Physics.World.prototype = {
/**
* Handles a p2 impact event.
*
* @method Phaser.Physics.World#impactHandler
* @method Phaser.Physics.P2#impactHandler
* @private
* @param {object} event - The event data.
*/
@@ -242,7 +237,7 @@ Phaser.Physics.World.prototype = {
/**
* Handles a p2 begin contact event.
*
* @method Phaser.Physics.World#beginContactHandler
* @method Phaser.Physics.P2#beginContactHandler
* @private
* @param {object} event - The event data.
*/
@@ -263,7 +258,7 @@ Phaser.Physics.World.prototype = {
/**
* Handles a p2 end contact event.
*
* @method Phaser.Physics.World#endContactHandler
* @method Phaser.Physics.P2#endContactHandler
* @private
* @param {object} event - The event data.
*/
@@ -302,7 +297,7 @@ Phaser.Physics.World.prototype = {
* Sets the given material against the 4 bounds of this World.
*
* @method Phaser.Physics#setWorldMaterial
* @param {Phaser.Physics.Material} material - The material to set.
* @param {Phaser.Physics.P2.Material} material - The material to set.
* @param {boolean} [left=true] - If true will set the material on the left bounds wall.
* @param {boolean} [right=true] - If true will set the material on the right bounds wall.
* @param {boolean} [top=true] - If true will set the material on the top bounds wall.
@@ -341,7 +336,7 @@ Phaser.Physics.World.prototype = {
* Sets the bounds of the Physics world to match the given world pixel dimensions.
* You can optionally set which 'walls' to create: left, right, top or bottom.
*
* @method Phaser.Physics.World#setBounds
* @method Phaser.Physics.P2#setBounds
* @param {number} x - The x coordinate of the top-left corner of the bounds.
* @param {number} y - The y coordinate of the top-left corner of the bounds.
* @param {number} width - The width of the bounds.
@@ -449,7 +444,7 @@ Phaser.Physics.World.prototype = {
},
/**
* @method Phaser.Physics.World#update
* @method Phaser.Physics.P2#update
*/
update: function () {
@@ -460,7 +455,7 @@ Phaser.Physics.World.prototype = {
/**
* Clears all bodies from the simulation.
*
* @method Phaser.Physics.World#clear
* @method Phaser.Physics.P2#clear
*/
clear: function () {
@@ -471,7 +466,7 @@ Phaser.Physics.World.prototype = {
/**
* Clears all bodies from the simulation and unlinks World from Game. Should only be called on game shutdown. Call `clear` on a State change.
*
* @method Phaser.Physics.World#destroy
* @method Phaser.Physics.P2#destroy
*/
destroy: function () {
@@ -484,8 +479,8 @@ Phaser.Physics.World.prototype = {
/**
* Add a body to the world.
*
* @method Phaser.Physics.World#addBody
* @param {Phaser.Physics.Body} body - The Body to add to the World.
* @method Phaser.Physics.P2#addBody
* @param {Phaser.Physics.P2.Body} body - The Body to add to the World.
* @return {boolean} True if the Body was added successfully, otherwise false.
*/
addBody: function (body) {
@@ -508,9 +503,9 @@ Phaser.Physics.World.prototype = {
/**
* Removes a body from the world.
*
* @method Phaser.Physics.World#removeBody
* @param {Phaser.Physics.Body} body - The Body to remove from the World.
* @return {Phaser.Physics.Body} The Body that was removed.
* @method Phaser.Physics.P2#removeBody
* @param {Phaser.Physics.P2.Body} body - The Body to remove from the World.
* @return {Phaser.Physics.P2.Body} The Body that was removed.
*/
removeBody: function (body) {
@@ -525,9 +520,9 @@ Phaser.Physics.World.prototype = {
/**
* Adds a Spring to the world.
*
* @method Phaser.Physics.World#addSpring
* @param {Phaser.Physics.Spring} spring - The Spring to add to the World.
* @return {Phaser.Physics.Spring} The Spring that was added.
* @method Phaser.Physics.P2#addSpring
* @param {Phaser.Physics.P2.Spring} spring - The Spring to add to the World.
* @return {Phaser.Physics.P2.Spring} The Spring that was added.
*/
addSpring: function (spring) {
@@ -542,9 +537,9 @@ Phaser.Physics.World.prototype = {
/**
* Removes a Spring from the world.
*
* @method Phaser.Physics.World#removeSpring
* @param {Phaser.Physics.Spring} spring - The Spring to remove from the World.
* @return {Phaser.Physics.Spring} The Spring that was removed.
* @method Phaser.Physics.P2#removeSpring
* @param {Phaser.Physics.P2.Spring} spring - The Spring to remove from the World.
* @return {Phaser.Physics.P2.Spring} The Spring that was removed.
*/
removeSpring: function (spring) {
@@ -559,9 +554,9 @@ Phaser.Physics.World.prototype = {
/**
* Adds a Constraint to the world.
*
* @method Phaser.Physics.World#addConstraint
* @param {Phaser.Physics.Constraint} constraint - The Constraint to add to the World.
* @return {Phaser.Physics.Constraint} The Constraint that was added.
* @method Phaser.Physics.P2#addConstraint
* @param {Phaser.Physics.P2.Constraint} constraint - The Constraint to add to the World.
* @return {Phaser.Physics.P2.Constraint} The Constraint that was added.
*/
addConstraint: function (constraint) {
@@ -576,9 +571,9 @@ Phaser.Physics.World.prototype = {
/**
* Removes a Constraint from the world.
*
* @method Phaser.Physics.World#removeConstraint
* @param {Phaser.Physics.Constraint} constraint - The Constraint to be removed from the World.
* @return {Phaser.Physics.Constraint} The Constraint that was removed.
* @method Phaser.Physics.P2#removeConstraint
* @param {Phaser.Physics.P2.Constraint} constraint - The Constraint to be removed from the World.
* @return {Phaser.Physics.P2.Constraint} The Constraint that was removed.
*/
removeConstraint: function (constraint) {
@@ -593,9 +588,9 @@ Phaser.Physics.World.prototype = {
/**
* Adds a Contact Material to the world.
*
* @method Phaser.Physics.World#addContactMaterial
* @param {Phaser.Physics.ContactMaterial} material - The Contact Material to be added to the World.
* @return {Phaser.Physics.ContactMaterial} The Contact Material that was added.
* @method Phaser.Physics.P2#addContactMaterial
* @param {Phaser.Physics.P2.ContactMaterial} material - The Contact Material to be added to the World.
* @return {Phaser.Physics.P2.ContactMaterial} The Contact Material that was added.
*/
addContactMaterial: function (material) {
@@ -610,9 +605,9 @@ Phaser.Physics.World.prototype = {
/**
* Removes a Contact Material from the world.
*
* @method Phaser.Physics.World#removeContactMaterial
* @param {Phaser.Physics.ContactMaterial} material - The Contact Material to be removed from the World.
* @return {Phaser.Physics.ContactMaterial} The Contact Material that was removed.
* @method Phaser.Physics.P2#removeContactMaterial
* @param {Phaser.Physics.P2.ContactMaterial} material - The Contact Material to be removed from the World.
* @return {Phaser.Physics.P2.ContactMaterial} The Contact Material that was removed.
*/
removeContactMaterial: function (material) {
@@ -627,10 +622,10 @@ Phaser.Physics.World.prototype = {
/**
* Gets a Contact Material based on the two given Materials.
*
* @method Phaser.Physics.World#getContactMaterial
* @param {Phaser.Physics.Material} materialA - The first Material to search for.
* @param {Phaser.Physics.Material} materialB - The second Material to search for.
* @return {Phaser.Physics.ContactMaterial|boolean} The Contact Material or false if none was found matching the Materials given.
* @method Phaser.Physics.P2#getContactMaterial
* @param {Phaser.Physics.P2.Material} materialA - The first Material to search for.
* @param {Phaser.Physics.P2.Material} materialB - The second Material to search for.
* @return {Phaser.Physics.P2.ContactMaterial|boolean} The Contact Material or false if none was found matching the Materials given.
*/
getContactMaterial: function (materialA, materialB) {
@@ -641,9 +636,9 @@ Phaser.Physics.World.prototype = {
/**
* Sets the given Material against all Shapes owned by all the Bodies in the given array.
*
* @method Phaser.Physics.World#setMaterial
* @param {Phaser.Physics.Material} material - The Material to be applied to the given Bodies.
* @param {array<Phaser.Physics.Body>} bodies - An Array of Body objects that the given Material will be set on.
* @method Phaser.Physics.P2#setMaterial
* @param {Phaser.Physics.P2.Material} material - The Material to be applied to the given Bodies.
* @param {array<Phaser.Physics.P2.Body>} bodies - An Array of Body objects that the given Material will be set on.
*/
setMaterial: function (material, bodies) {
@@ -661,16 +656,16 @@ Phaser.Physics.World.prototype = {
* Materials are a way to control what happens when Shapes collide. Combine unique Materials together to create Contact Materials.
* Contact Materials have properties such as friction and restitution that allow for fine-grained collision control between different Materials.
*
* @method Phaser.Physics.World#createMaterial
* @method Phaser.Physics.P2#createMaterial
* @param {string} [name] - Optional name of the Material. Each Material has a unique ID but string names are handy for debugging.
* @param {Phaser.Physics.Body} [body] - Optional Body. If given it will assign the newly created Material to the Body shapes.
* @return {Phaser.Physics.Material} The Material that was created. This is also stored in Phaser.Physics.World.materials.
* @param {Phaser.Physics.P2.Body} [body] - Optional Body. If given it will assign the newly created Material to the Body shapes.
* @return {Phaser.Physics.P2.Material} The Material that was created. This is also stored in Phaser.Physics.P2.materials.
*/
createMaterial: function (name, body) {
name = name || '';
var material = new Phaser.Physics.Material(name);
var material = new Phaser.Physics.P2.Material(name);
this.materials.push(material);
@@ -686,18 +681,18 @@ Phaser.Physics.World.prototype = {
/**
* Creates a Contact Material from the two given Materials. You can then edit the properties of the Contact Material directly.
*
* @method Phaser.Physics.World#createContactMaterial
* @param {Phaser.Physics.Material} [materialA] - The first Material to create the ContactMaterial from. If undefined it will create a new Material object first.
* @param {Phaser.Physics.Material} [materialB] - The second Material to create the ContactMaterial from. If undefined it will create a new Material object first.
* @method Phaser.Physics.P2#createContactMaterial
* @param {Phaser.Physics.P2.Material} [materialA] - The first Material to create the ContactMaterial from. If undefined it will create a new Material object first.
* @param {Phaser.Physics.P2.Material} [materialB] - The second Material to create the ContactMaterial from. If undefined it will create a new Material object first.
* @param {object} [options] - Material options object.
* @return {Phaser.Physics.ContactMaterial} The Contact Material that was created.
* @return {Phaser.Physics.P2.ContactMaterial} The Contact Material that was created.
*/
createContactMaterial: function (materialA, materialB, options) {
if (typeof materialA === 'undefined') { materialA = this.createMaterial(); }
if (typeof materialB === 'undefined') { materialB = this.createMaterial(); }
var contact = new Phaser.Physics.ContactMaterial(materialA, materialB, options);
var contact = new Phaser.Physics.P2.ContactMaterial(materialA, materialB, options);
return this.addContactMaterial(contact);
@@ -706,8 +701,8 @@ Phaser.Physics.World.prototype = {
/**
* Populates and returns an array of all current Bodies in the world.
*
* @method Phaser.Physics.World#getBodies
* @return {array<Phaser.Physics.Body>} An array containing all current Bodies in the world.
* @method Phaser.Physics.P2#getBodies
* @return {array<Phaser.Physics.P2.Body>} An array containing all current Bodies in the world.
*/
getBodies: function () {
@@ -726,8 +721,8 @@ Phaser.Physics.World.prototype = {
/**
* Populates and returns an array of all current Springs in the world.
*
* @method Phaser.Physics.World#getSprings
* @return {array<Phaser.Physics.Spring>} An array containing all current Springs in the world.
* @method Phaser.Physics.P2#getSprings
* @return {array<Phaser.Physics.P2.Spring>} An array containing all current Springs in the world.
*/
getSprings: function () {
@@ -746,8 +741,8 @@ Phaser.Physics.World.prototype = {
/**
* Populates and returns an array of all current Constraints in the world.
*
* @method Phaser.Physics.World#getConstraints
* @return {array<Phaser.Physics.Constraints>} An array containing all current Constraints in the world.
* @method Phaser.Physics.P2#getConstraints
* @return {array<Phaser.Physics.P2.Constraints>} An array containing all current Constraints in the world.
*/
getConstraints: function () {
@@ -766,7 +761,7 @@ Phaser.Physics.World.prototype = {
/**
* Test if a world point overlaps bodies.
*
* @method Phaser.Physics.World#hitTest
* @method Phaser.Physics.P2#hitTest
* @param {Phaser.Point} worldPoint - Point to use for intersection tests.
* @param {Array} bodies - A list of objects to check for intersection.
* @param {number} precision - Used for matching against particles and lines. Adds some margin to these infinitesimal objects.
@@ -779,7 +774,7 @@ Phaser.Physics.World.prototype = {
/**
* Converts the current world into a JSON object.
*
* @method Phaser.Physics.World#toJSON
* @method Phaser.Physics.P2#toJSON
* @return {object} A JSON representation of the world.
*/
toJSON: function () {
@@ -814,7 +809,7 @@ Phaser.Physics.World.prototype = {
this._collisionGroupID++;
var group = new Phaser.Physics.CollisionGroup(bitmask);
var group = new Phaser.Physics.P2.CollisionGroup(bitmask);
this.collisionGroups.push(group);
@@ -823,7 +818,7 @@ Phaser.Physics.World.prototype = {
},
/**
* @method Phaser.Physics.World.prototype.createBody
* @method Phaser.Physics.P2.prototype.createBody
* @param {number} x - The x coordinate of Body.
* @param {number} y - The y coordinate of Body.
* @param {number} mass - The mass of the Body. A mass of 0 means a 'static' Body is created.
@@ -840,7 +835,7 @@ Phaser.Physics.World.prototype = {
if (typeof addToWorld === 'undefined') { addToWorld = false; }
var body = new Phaser.Physics.Body(this.game, null, x, y, mass);
var body = new Phaser.Physics.P2.Body(this.game, null, x, y, mass);
if (data)
{
@@ -862,7 +857,7 @@ Phaser.Physics.World.prototype = {
},
/**
* @method Phaser.Physics.World.prototype.createBody
* @method Phaser.Physics.P2.prototype.createBody
* @param {number} x - The x coordinate of Body.
* @param {number} y - The y coordinate of Body.
* @param {number} mass - The mass of the Body. A mass of 0 means a 'static' Body is created.
@@ -879,7 +874,7 @@ Phaser.Physics.World.prototype = {
if (typeof addToWorld === 'undefined') { addToWorld = false; }
var body = new Phaser.Physics.Body(this.game, null, x, y, mass);
var body = new Phaser.Physics.P2.Body(this.game, null, x, y, mass);
if (data)
{
@@ -905,10 +900,10 @@ Phaser.Physics.World.prototype = {
};
/**
* @name Phaser.Physics.World#friction
* @name Phaser.Physics.P2#friction
* @property {number} friction - Friction between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "friction", {
Object.defineProperty(Phaser.Physics.P2.prototype, "friction", {
get: function () {
@@ -925,10 +920,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "friction", {
});
/**
* @name Phaser.Physics.World#restituion
* @name Phaser.Physics.P2#restituion
* @property {number} restitution - Default coefficient of restitution between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "restituion", {
Object.defineProperty(Phaser.Physics.P2.prototype, "restituion", {
get: function () {
@@ -945,10 +940,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "restituion", {
});
/**
* @name Phaser.Physics.World#applySpringForces
* @name Phaser.Physics.P2#applySpringForces
* @property {boolean} applySpringForces - Enable to automatically apply spring forces each step.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "applySpringForces", {
Object.defineProperty(Phaser.Physics.P2.prototype, "applySpringForces", {
get: function () {
@@ -965,10 +960,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "applySpringForces", {
});
/**
* @name Phaser.Physics.World#applyDamping
* @name Phaser.Physics.P2#applyDamping
* @property {boolean} applyDamping - Enable to automatically apply body damping each step.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "applyDamping", {
Object.defineProperty(Phaser.Physics.P2.prototype, "applyDamping", {
get: function () {
@@ -985,10 +980,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "applyDamping", {
});
/**
* @name Phaser.Physics.World#applyGravity
* @name Phaser.Physics.P2#applyGravity
* @property {boolean} applyGravity - Enable to automatically apply gravity each step.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "applyGravity", {
Object.defineProperty(Phaser.Physics.P2.prototype, "applyGravity", {
get: function () {
@@ -1005,10 +1000,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "applyGravity", {
});
/**
* @name Phaser.Physics.World#solveConstraints
* @name Phaser.Physics.P2#solveConstraints
* @property {boolean} solveConstraints - Enable/disable constraint solving in each step.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "solveConstraints", {
Object.defineProperty(Phaser.Physics.P2.prototype, "solveConstraints", {
get: function () {
@@ -1025,11 +1020,11 @@ Object.defineProperty(Phaser.Physics.World.prototype, "solveConstraints", {
});
/**
* @name Phaser.Physics.World#time
* @name Phaser.Physics.P2#time
* @property {boolean} time - The World time.
* @readonly
*/
Object.defineProperty(Phaser.Physics.World.prototype, "time", {
Object.defineProperty(Phaser.Physics.P2.prototype, "time", {
get: function () {
@@ -1040,10 +1035,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "time", {
});
/**
* @name Phaser.Physics.World#emitImpactEvent
* @name Phaser.Physics.P2#emitImpactEvent
* @property {boolean} emitImpactEvent - Set to true if you want to the world to emit the "impact" event. Turning this off could improve performance.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "emitImpactEvent", {
Object.defineProperty(Phaser.Physics.P2.prototype, "emitImpactEvent", {
get: function () {
@@ -1060,10 +1055,10 @@ Object.defineProperty(Phaser.Physics.World.prototype, "emitImpactEvent", {
});
/**
* @name Phaser.Physics.World#enableBodySleeping
* @name Phaser.Physics.P2#enableBodySleeping
* @property {boolean} enableBodySleeping - Enable / disable automatic body sleeping.
*/
Object.defineProperty(Phaser.Physics.World.prototype, "enableBodySleeping", {
Object.defineProperty(Phaser.Physics.P2.prototype, "enableBodySleeping", {
get: function () {
+1 -1
View File
@@ -117,7 +117,7 @@ Phaser.Utils.Debug.prototype = {
this.context = this.canvas.getContext('2d');
this.baseTexture = new PIXI.BaseTexture(this.canvas);
this.texture = new PIXI.Texture(this.baseTexture);
this.textureFrame = new Phaser.Frame(0, 0, 0, this.game.width, this.game.height, 'debug', game.rnd.uuid());
this.textureFrame = new Phaser.Frame(0, 0, 0, this.game.width, this.game.height, 'debug', this.game.rnd.uuid());
this.sprite = this.game.make.image(0, 0, this.texture, this.textureFrame);
this.game.stage.addChild(this.sprite);
}