mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 04:33:31 +00:00
World now takes a config object. Cleaner and many more options now supported.
This commit is contained in:
parent
579489d47a
commit
67cba936da
3 changed files with 25 additions and 23 deletions
|
@ -39,13 +39,13 @@ var Body = new Class({
|
|||
this.vel = { x: 0, y: 0 };
|
||||
this.accel = { x: 0, y: 0 };
|
||||
this.friction = { x: 0, y: 0 };
|
||||
this.maxVel = { x: 100, y: 100 };
|
||||
this.maxVel = { x: world.defaults.maxVelocityX, y: world.defaults.maxVelocityY };
|
||||
|
||||
this.standing = false;
|
||||
|
||||
this.gravityFactor = 1;
|
||||
this.bounciness = 0;
|
||||
this.minBounceVelocity = 40;
|
||||
this.gravityFactor = world.defaults.gravityFactor;
|
||||
this.bounciness = world.defaults.bounciness;
|
||||
this.minBounceVelocity = world.defaults.minBounceVelocity;
|
||||
|
||||
this.accelGround = 0;
|
||||
this.accelAir = 0;
|
||||
|
@ -57,7 +57,7 @@ var Body = new Class({
|
|||
|
||||
this.debugShowBody = true;
|
||||
this.debugShowVelocity = true;
|
||||
this.debugBodyColor = world.debugColors.body;
|
||||
this.debugBodyColor = world.defaults.bodyDebugColor;
|
||||
|
||||
// min 44 deg, max 136 deg
|
||||
this.slopeStanding = { min: 0.767944870877505, max: 2.3736477827122884 };
|
||||
|
@ -131,7 +131,7 @@ var Body = new Class({
|
|||
var x = pos.x + this.size.x / 2;
|
||||
var y = pos.y + this.size.y / 2;
|
||||
|
||||
graphic.lineStyle(1, this.world.debugColors.velocity, 1);
|
||||
graphic.lineStyle(1, this.world.defaults.velocityDebugColor, 1);
|
||||
graphic.lineBetween(x, y, x + this.vel.x, y + this.vel.y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ var Body = require('./Body');
|
|||
var Class = require('../../utils/Class');
|
||||
var COLLIDES = require('./COLLIDES');
|
||||
var CollisionMap = require('./CollisionMap');
|
||||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
var Set = require('../../structs/Set');
|
||||
var Solver = require('./Solver');
|
||||
var TYPE = require('./TYPE');
|
||||
|
@ -12,46 +13,47 @@ var World = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function World (scene, gravity, cellSize, showDebug)
|
||||
function World (scene, config)
|
||||
{
|
||||
if (gravity === undefined) { gravity = 0; }
|
||||
if (cellSize === undefined) { cellSize = 64; }
|
||||
if (showDebug === undefined) { showDebug = false; }
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
this.events = scene.sys.events;
|
||||
|
||||
this.bodies = new Set();
|
||||
|
||||
this.gravity = gravity;
|
||||
this.gravity = GetFastValue(config, 'gravity', 0);
|
||||
|
||||
// Spatial hash cell dimensions
|
||||
this.cellSize = cellSize;
|
||||
this.cellSize = GetFastValue(config, 'cellSize', 64);
|
||||
|
||||
this.collisionMap = new CollisionMap();
|
||||
|
||||
this.delta = 0;
|
||||
|
||||
this.timeScale = 1;
|
||||
this.timeScale = GetFastValue(config, 'timeScale', 1);
|
||||
|
||||
// Impacts maximum time step is 20 fps.
|
||||
this.maxStep = 0.05;
|
||||
this.maxStep = GetFastValue(config, 'maxStep', 0.05);
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
this.drawDebug = false;
|
||||
this.drawDebug = GetFastValue(config, 'debug', false);
|
||||
|
||||
this.debugGraphic;
|
||||
|
||||
this.debugColors = {
|
||||
body: 0xff00ff,
|
||||
velocity: 0x00ff00
|
||||
this.defaults = {
|
||||
bodyDebugColor: GetFastValue(config, 'debugBodyColor', 0xff00ff),
|
||||
velocityDebugColor: GetFastValue(config, 'debugVelocityColor', 0x00ff00),
|
||||
maxVelocityX: GetFastValue(config, 'maxVelocityX', 100),
|
||||
maxVelocityY: GetFastValue(config, 'maxVelocityY', 100),
|
||||
minBounceVelocity: GetFastValue(config, 'minBounceVelocity', 40),
|
||||
gravityFactor: GetFastValue(config, 'gravityFactor', 1),
|
||||
bounciness: GetFastValue(config, 'bounciness', 0)
|
||||
};
|
||||
|
||||
this.delta = 0;
|
||||
|
||||
this._lastId = 0;
|
||||
|
||||
if (showDebug)
|
||||
if (this.drawDebug)
|
||||
{
|
||||
this.createDebugGraphic();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ var PhysicsManager = new Class({
|
|||
|
||||
if (config.system === 'impact')
|
||||
{
|
||||
this.world = new Physics.Impact.World(this.scene, config.gravity, config.cellSize, config.debug);
|
||||
this.world = new Physics.Impact.World(this.scene, config);
|
||||
this.add = new Physics.Impact.Factory(this.world);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue