mirror of
https://github.com/wassname/phaser.git
synced 2026-07-03 17:10:40 +08:00
Physics shape offset now finally working
This commit is contained in:
@@ -113,6 +113,10 @@
|
||||
<Content Include="physics\AABB.js">
|
||||
<DependentUpon>AABB.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\IPhysicsShape.ts" />
|
||||
<Content Include="physics\IPhysicsShape.js">
|
||||
<DependentUpon>IPhysicsShape.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\PhysicsManager.js">
|
||||
<DependentUpon>PhysicsManager.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
@@ -17,15 +17,16 @@ module Phaser.Components {
|
||||
this._game = parent.game;
|
||||
this._sprite = parent;
|
||||
|
||||
this.gravityFactor = new Vec2(1, 1);
|
||||
this.drag = new Vec2(0, 0);
|
||||
this.bounce = new Vec2(0, 0);
|
||||
this.friction = new Vec2(0.05, 0.05);
|
||||
this.velocity = new Vec2(0, 0);
|
||||
this.acceleration = new Vec2(0, 0);
|
||||
// Copy from PhysicsManager?
|
||||
this.gravity = new Vec2;
|
||||
this.drag = new Vec2;
|
||||
this.bounce = new Vec2;
|
||||
this.friction = new Vec2;
|
||||
this.velocity = new Vec2;
|
||||
this.acceleration = new Vec2;
|
||||
|
||||
//this.AABB = new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height);
|
||||
this.AABB = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
|
||||
this.shape = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ module Phaser.Components {
|
||||
*/
|
||||
private _sprite: Sprite;
|
||||
|
||||
public AABB: Phaser.Physics.AABB;
|
||||
public shape: Phaser.Physics.IPhysicsShape;
|
||||
|
||||
/**
|
||||
* Whether this object will be moved by impacts with other objects or not.
|
||||
@@ -53,14 +54,13 @@ module Phaser.Components {
|
||||
*/
|
||||
public moves: bool = true;
|
||||
|
||||
public gravityFactor: Vec2;
|
||||
public gravity: Vec2;
|
||||
public drag: Vec2;
|
||||
public bounce: Vec2;
|
||||
public friction: Vec2;
|
||||
public velocity: Vec2;
|
||||
public acceleration: Vec2;
|
||||
|
||||
|
||||
/**
|
||||
* Internal function for updating the position and speed of this object.
|
||||
*/
|
||||
@@ -68,10 +68,12 @@ module Phaser.Components {
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this._sprite.x = this.AABB.position.x - this.AABB.halfWidth;
|
||||
this._sprite.y = this.AABB.position.y - this.AABB.halfHeight;
|
||||
//this._sprite.x = this.AABB.position.x;
|
||||
//this._sprite.y = this.AABB.position.y;
|
||||
this._sprite.x = (this.shape.position.x - this.shape.bounds.halfWidth) - this.shape.offset.x;
|
||||
this._sprite.y = (this.shape.position.y - this.shape.bounds.halfHeight) - this.shape.offset.y;
|
||||
//this._sprite.x = (this.shape.position.x - this.shape.bounds.halfWidth);
|
||||
//this._sprite.y = (this.shape.position.y - this.shape.bounds.halfHeight);
|
||||
//this._sprite.x = (this.shape.position.x);
|
||||
//this._sprite.y = (this.shape.position.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,13 +48,14 @@ module Phaser {
|
||||
this.width = this.frameBounds.width;
|
||||
this.height = this.frameBounds.height;
|
||||
|
||||
this.physics = new Phaser.Components.Physics(this);
|
||||
|
||||
// Transform related (if we add any more then move to a component)
|
||||
this.origin = new Phaser.Vec2(0, 0);
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.skew = new Phaser.Vec2(0, 0);
|
||||
|
||||
this.physics = new Phaser.Components.Physics(this);
|
||||
this.physics.shape.physics = this.physics;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+59
-232
@@ -1,5 +1,8 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../core/Rectangle.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="PhysicsManager.ts" />
|
||||
/// <reference path="IPhysicsShape.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Physics - AABB
|
||||
@@ -7,253 +10,78 @@
|
||||
|
||||
module Phaser.Physics {
|
||||
|
||||
export class AABB {
|
||||
export class AABB implements IPhysicsShape {
|
||||
|
||||
constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number) {
|
||||
|
||||
this.game = game;
|
||||
this.world = game.world.physics;
|
||||
this.sprite = sprite;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.halfWidth = Math.round(width / 2);
|
||||
this.halfHeight = Math.round(height / 2);
|
||||
if (sprite !== null)
|
||||
{
|
||||
this.sprite = sprite;
|
||||
this.scale = Vec2Utils.clone(this.sprite.scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sprite = null;
|
||||
this.physics = null;
|
||||
this.scale = new Vec2(1, 1);
|
||||
}
|
||||
|
||||
this.position = new Vec2(x + this.halfWidth, y + this.halfHeight);
|
||||
this.oldPosition = new Vec2(x + this.halfWidth, y + this.halfHeight);
|
||||
this.newVelocity = new Vec2(0, 0);
|
||||
//this.bounds = new Rectangle(x + Math.round(width / 2), y + Math.round(height / 2), width, height);
|
||||
this.bounds = new Rectangle(x + Math.round(width / 2), y + Math.round(height / 2), width, height);
|
||||
this.position = new Vec2(x + this.bounds.halfWidth, y + this.bounds.halfHeight);
|
||||
this.oldPosition = new Vec2(x + this.bounds.halfWidth, y + this.bounds.halfHeight);
|
||||
this.offset = new Vec2(0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to Game.
|
||||
*/
|
||||
public game: Game;
|
||||
public world: PhysicsManager;
|
||||
public sprite: Sprite;
|
||||
public physics: Phaser.Components.Physics;
|
||||
|
||||
public position: Vec2;
|
||||
public oldPosition: Vec2;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public halfWidth: number;
|
||||
public halfHeight: number;
|
||||
public offset: Vec2;
|
||||
public scale: Vec2;
|
||||
public bounds: Rectangle;
|
||||
|
||||
public oH: number;
|
||||
public oV: number;
|
||||
|
||||
private _drag: number;
|
||||
public preUpdate() {
|
||||
|
||||
public newVelocity: Vec2;
|
||||
this.oldPosition.copyFrom(this.position);
|
||||
|
||||
if (this.sprite)
|
||||
{
|
||||
// Update position to sprite value
|
||||
//console.log('a', this.position.x, this.position.y);
|
||||
this.position.setTo((this.sprite.x + this.bounds.halfWidth) + this.offset.x, (this.sprite.y + this.bounds.halfHeight) + this.offset.y);
|
||||
//console.log('b', this.position.x, this.position.y);
|
||||
//this.position.setTo(this.sprite.x, this.sprite.y);
|
||||
|
||||
// Update scale / dimensions
|
||||
if (Vec2Utils.equals(this.scale, this.sprite.scale) == false)
|
||||
{
|
||||
console.log('scaled');
|
||||
this.scale.copyFrom(this.sprite.scale);
|
||||
this.bounds.width = this.sprite.width;
|
||||
this.bounds.height = this.sprite.height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
if (this.sprite.physics.moves)
|
||||
{
|
||||
this.oldPosition.x = this.position.x;
|
||||
this.oldPosition.y = this.position.y;
|
||||
|
||||
this.updateMotion();
|
||||
this.collideWorld();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private updateMotion() {
|
||||
public setSize(width: number, height: number) {
|
||||
|
||||
/*
|
||||
var delta: number;
|
||||
var velocityDelta: number;
|
||||
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
|
||||
this.angularVelocity += velocityDelta;
|
||||
this._angle += this.angularVelocity * this._game.time.elapsed;
|
||||
this.angularVelocity += velocityDelta;
|
||||
*/
|
||||
|
||||
// move to temp vars
|
||||
var delta;
|
||||
|
||||
var velocityDelta = (this.computeVelocity(this.sprite.physics.velocity.x, this.sprite.physics.acceleration.x, this.sprite.physics.drag.x) - this.sprite.physics.velocity.x) / 2;
|
||||
this.sprite.physics.velocity.x += velocityDelta;
|
||||
delta = this.sprite.physics.velocity.x * this.game.time.elapsed;
|
||||
this.sprite.physics.velocity.x += velocityDelta;
|
||||
this.position.x += delta;
|
||||
|
||||
var velocityDelta = (this.computeVelocity(this.sprite.physics.velocity.y, this.sprite.physics.acceleration.y, this.sprite.physics.drag.y) - this.sprite.physics.velocity.y) / 2;
|
||||
this.sprite.physics.velocity.y += velocityDelta;
|
||||
delta = this.sprite.physics.velocity.y * this.game.time.elapsed;
|
||||
this.sprite.physics.velocity.y += velocityDelta;
|
||||
this.position.y += delta;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
|
||||
*
|
||||
* @param {number} Velocity Any component of velocity (e.g. 20).
|
||||
* @param {number} Acceleration Rate at which the velocity is changing.
|
||||
* @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
||||
* @param {number} Max An absolute value cap for the velocity.
|
||||
*
|
||||
* @return {number} The altered Velocity value.
|
||||
*/
|
||||
public computeVelocity(velocity: number, acceleration: number = 0, drag: number = 0, max: number = 10000): number {
|
||||
|
||||
if (acceleration !== 0)
|
||||
{
|
||||
velocity += acceleration * this.game.time.elapsed;
|
||||
}
|
||||
else if (drag !== 0)
|
||||
{
|
||||
this._drag = drag * this.game.time.elapsed;
|
||||
|
||||
if (velocity - this._drag > 0)
|
||||
{
|
||||
velocity = velocity - this._drag;
|
||||
}
|
||||
else if (velocity + this._drag < 0)
|
||||
{
|
||||
velocity += this._drag;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((velocity != 0) && (max != 10000))
|
||||
{
|
||||
if (velocity > max)
|
||||
{
|
||||
velocity = max;
|
||||
}
|
||||
else if (velocity < -max)
|
||||
{
|
||||
velocity = -max;
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
|
||||
}
|
||||
|
||||
private collideWorld() {
|
||||
|
||||
// Collide on the x-axis
|
||||
var dx: number = this.world.bounds.x - (this.position.x - this.halfWidth);
|
||||
|
||||
if (0 < dx)
|
||||
{
|
||||
// Hit Left
|
||||
this.oH = 1;
|
||||
this.position.x += dx;
|
||||
|
||||
if (this.sprite.physics.bounce.x > 0)
|
||||
{
|
||||
this.sprite.physics.velocity.x *= -(this.sprite.physics.bounce.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sprite.physics.velocity.x = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dx = (this.position.x + this.halfWidth) - this.world.bounds.right;
|
||||
|
||||
if (0 < dx)
|
||||
{
|
||||
// Hit Right
|
||||
this.oH = -1;
|
||||
this.position.x -= dx;
|
||||
|
||||
if (this.sprite.physics.bounce.x > 0)
|
||||
{
|
||||
this.sprite.physics.velocity.x *= -(this.sprite.physics.bounce.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sprite.physics.velocity.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collide on the y-axis
|
||||
var dy: number = this.world.bounds.y - (this.position.y - this.halfHeight);
|
||||
|
||||
if (0 < dy)
|
||||
{
|
||||
// Hit Top
|
||||
this.oV = 1;
|
||||
this.position.y += dy;
|
||||
|
||||
if (this.sprite.physics.bounce.y > 0)
|
||||
{
|
||||
this.sprite.physics.velocity.y *= -(this.sprite.physics.bounce.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sprite.physics.velocity.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dy = (this.position.y + this.halfHeight) - this.world.bounds.bottom;
|
||||
|
||||
if (0 < dy)
|
||||
{
|
||||
// Hit Bottom
|
||||
this.oV = -1;
|
||||
this.position.y -= dy;
|
||||
|
||||
if (this.sprite.physics.bounce.y > 0)
|
||||
{
|
||||
this.sprite.physics.velocity.y *= -(this.sprite.physics.bounce.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sprite.physics.velocity.y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private processWorld(px, py, dx, dy, tile) {
|
||||
|
||||
// Velocity
|
||||
//this.sprite.physics.velocity.x = this.position.x - this.oldPosition.x;
|
||||
//this.sprite.physics.velocity.y = this.position.y - this.oldPosition.y;
|
||||
|
||||
// Optimise!!!
|
||||
var dp: number = (this.sprite.physics.velocity.x * dx + this.sprite.physics.velocity.y * dy);
|
||||
var nx: number = dp * dx;
|
||||
var ny: number = dp * dy;
|
||||
var tx: number = this.sprite.physics.velocity.x - nx;
|
||||
var ty: number = this.sprite.physics.velocity.y - ny;
|
||||
|
||||
var bx, by, fx, fy;
|
||||
|
||||
if (dp < 0)
|
||||
{
|
||||
fx = tx * this.sprite.physics.friction.x;
|
||||
fy = ty * this.sprite.physics.friction.y;
|
||||
bx = (nx * (1 + this.sprite.physics.bounce.x));
|
||||
by = (ny * (1 + this.sprite.physics.bounce.y));
|
||||
//this.sprite.physics.velocity.x = bx;
|
||||
//this.sprite.physics.velocity.y = by;
|
||||
}
|
||||
else
|
||||
{
|
||||
bx = by = fx = fy = 0;
|
||||
}
|
||||
|
||||
this.position.x += px;
|
||||
this.position.y += py;
|
||||
|
||||
this.oldPosition.x += px + bx + fx;
|
||||
this.oldPosition.y += py + by + fy;
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
|
||||
}
|
||||
|
||||
@@ -261,7 +89,7 @@ module Phaser.Physics {
|
||||
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(0,255,0)';
|
||||
context.strokeRect(this.position.x - this.halfWidth, this.position.y - this.halfHeight, this.width, this.height);
|
||||
context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
|
||||
@@ -273,8 +101,8 @@ module Phaser.Physics {
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x - this.halfWidth, this.position.y - this.halfHeight);
|
||||
context.lineTo(this.position.x - this.halfWidth, this.position.y + this.halfHeight);
|
||||
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
@@ -282,8 +110,8 @@ module Phaser.Physics {
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x + this.halfWidth, this.position.y - this.halfHeight);
|
||||
context.lineTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
||||
context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
@@ -292,8 +120,8 @@ module Phaser.Physics {
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x - this.halfWidth, this.position.y - this.halfHeight);
|
||||
context.lineTo(this.position.x + this.halfWidth, this.position.y - this.halfHeight);
|
||||
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
@@ -301,13 +129,12 @@ module Phaser.Physics {
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x - this.halfWidth, this.position.y + this.halfHeight);
|
||||
context.lineTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
||||
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../core/Rectangle.ts" />
|
||||
/// <reference path="PhysicsManager.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Physics - IPhysicsShape
|
||||
*/
|
||||
|
||||
module Phaser.Physics {
|
||||
|
||||
export interface IPhysicsShape {
|
||||
|
||||
game: Game;
|
||||
world: PhysicsManager;
|
||||
sprite: Sprite;
|
||||
physics: Phaser.Components.Physics;
|
||||
|
||||
position: Vec2;
|
||||
oldPosition: Vec2;
|
||||
offset: Vec2;
|
||||
|
||||
bounds: Rectangle;
|
||||
oH: number;
|
||||
oV: number;
|
||||
|
||||
setSize(width: number, height: number);
|
||||
preUpdate();
|
||||
update();
|
||||
render(context:CanvasRenderingContext2D);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="IPhysicsShape.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - PhysicsManager
|
||||
@@ -13,12 +14,12 @@ module Phaser.Physics {
|
||||
|
||||
constructor(game: Game, width: number, height: number) {
|
||||
|
||||
this._game = game;
|
||||
this.game = game;
|
||||
|
||||
this.gravity = new Vec2(0, 0.2);
|
||||
this.drag = new Vec2(1, 1);
|
||||
this.bounce = new Vec2(0.3, 0.7);
|
||||
this.friction = new Vec2(0.05, 0.05);
|
||||
this.gravity = new Vec2;
|
||||
this.drag = new Vec2;
|
||||
this.bounce = new Vec2;
|
||||
this.friction = new Vec2;
|
||||
|
||||
this.bounds = new Rectangle(0, 0, width, height);
|
||||
|
||||
@@ -29,9 +30,15 @@ module Phaser.Physics {
|
||||
/**
|
||||
* Local private reference to Game.
|
||||
*/
|
||||
private _game: Game;
|
||||
public game: Game;
|
||||
|
||||
private _objects;
|
||||
private _objects: IPhysicsShape[];
|
||||
|
||||
// Temp calculation vars
|
||||
private _drag: number;
|
||||
private _delta: number;
|
||||
private _velocityDelta: number;
|
||||
private _length: number = 0;
|
||||
|
||||
public bounds: Rectangle;
|
||||
|
||||
@@ -40,30 +47,23 @@ module Phaser.Physics {
|
||||
public bounce: Vec2;
|
||||
public friction: Vec2;
|
||||
|
||||
private minFriction: number = 0;
|
||||
private maxFriction: number = 1;
|
||||
// Add some sanity checks here + remove method, etc
|
||||
public add(shape: IPhysicsShape): IPhysicsShape {
|
||||
|
||||
private minBounce: number = 0;
|
||||
private maxBounce: number = 1;
|
||||
this._objects.push(shape);
|
||||
return shape;
|
||||
|
||||
private minGravity: number = 0;
|
||||
private maxGravity: number = 1;
|
||||
|
||||
private _i: number = 0;
|
||||
private _length: number = 0;
|
||||
|
||||
public add(o) {
|
||||
this._objects.push(o);
|
||||
this._length++;
|
||||
return o;
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
// iterate through the objects here, updating and colliding
|
||||
for (this._i = 0; this._i < this._length; this._i++)
|
||||
this._length = this._objects.length;
|
||||
|
||||
for (var i = 0; i < this._length; i++)
|
||||
{
|
||||
this._objects[this._i].update();
|
||||
this._objects[i].preUpdate();
|
||||
this.updateMotion(this._objects[i]);
|
||||
this.collideWorld(this._objects[i]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,13 +71,214 @@ module Phaser.Physics {
|
||||
public render() {
|
||||
|
||||
// iterate through the objects here, updating and colliding
|
||||
for (this._i = 0; this._i < this._length; this._i++)
|
||||
for (var i = 0; i < this._length; i++)
|
||||
{
|
||||
this._objects[this._i].render(this._game.stage.context);
|
||||
this._objects[i].render(this.game.stage.context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private updateMotion(obj: IPhysicsShape) {
|
||||
|
||||
if (obj.physics.moves == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
|
||||
this.angularVelocity += velocityDelta;
|
||||
this._angle += this.angularVelocity * this._game.time.elapsed;
|
||||
this.angularVelocity += velocityDelta;
|
||||
*/
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(obj.physics.velocity.x, obj.physics.gravity.x, obj.physics.acceleration.x, obj.physics.drag.x) - obj.physics.velocity.x) / 2;
|
||||
obj.physics.velocity.x += this._velocityDelta;
|
||||
this._delta = obj.physics.velocity.x * this.game.time.elapsed;
|
||||
obj.physics.velocity.x += this._velocityDelta;
|
||||
obj.position.x += this._delta;
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(obj.physics.velocity.y, obj.physics.gravity.y, obj.physics.acceleration.y, obj.physics.drag.y) - obj.physics.velocity.y) / 2;
|
||||
obj.physics.velocity.y += this._velocityDelta;
|
||||
this._delta = obj.physics.velocity.y * this.game.time.elapsed;
|
||||
obj.physics.velocity.y += this._velocityDelta;
|
||||
obj.position.y += this._delta;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
|
||||
*
|
||||
* @param {number} Velocity Any component of velocity (e.g. 20).
|
||||
* @param {number} Acceleration Rate at which the velocity is changing.
|
||||
* @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
||||
* @param {number} Max An absolute value cap for the velocity.
|
||||
*
|
||||
* @return {number} The altered Velocity value.
|
||||
*/
|
||||
public computeVelocity(velocity: number, gravity: number = 0, acceleration: number = 0, drag: number = 0, max: number = 10000): number {
|
||||
|
||||
if (acceleration !== 0)
|
||||
{
|
||||
velocity += (acceleration + gravity) * this.game.time.elapsed;
|
||||
}
|
||||
else if (drag !== 0)
|
||||
{
|
||||
this._drag = drag * this.game.time.elapsed;
|
||||
|
||||
if (velocity - this._drag > 0)
|
||||
{
|
||||
velocity = velocity - this._drag;
|
||||
}
|
||||
else if (velocity + this._drag < 0)
|
||||
{
|
||||
velocity += this._drag;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = 0;
|
||||
}
|
||||
|
||||
velocity += gravity;
|
||||
}
|
||||
|
||||
if ((velocity != 0) && (max != 10000))
|
||||
{
|
||||
if (velocity > max)
|
||||
{
|
||||
velocity = max;
|
||||
}
|
||||
else if (velocity < -max)
|
||||
{
|
||||
velocity = -max;
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
|
||||
}
|
||||
|
||||
private collideWorld(obj:IPhysicsShape) {
|
||||
|
||||
// Collide on the x-axis
|
||||
var dx: number = obj.world.bounds.x - (obj.position.x - obj.bounds.halfWidth);
|
||||
|
||||
if (0 < dx)
|
||||
{
|
||||
// Hit Left
|
||||
obj.oH = 1;
|
||||
obj.position.x += dx;
|
||||
|
||||
if (obj.sprite.physics.bounce.x > 0)
|
||||
{
|
||||
obj.sprite.physics.velocity.x *= -(obj.sprite.physics.bounce.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.sprite.physics.velocity.x = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dx = (obj.position.x + obj.bounds.halfWidth) - obj.world.bounds.right;
|
||||
|
||||
if (0 < dx)
|
||||
{
|
||||
// Hit Right
|
||||
obj.oH = -1;
|
||||
obj.position.x -= dx;
|
||||
|
||||
if (obj.sprite.physics.bounce.x > 0)
|
||||
{
|
||||
obj.sprite.physics.velocity.x *= -(obj.sprite.physics.bounce.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.sprite.physics.velocity.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collide on the y-axis
|
||||
var dy: number = obj.world.bounds.y - (obj.position.y - obj.bounds.halfHeight);
|
||||
|
||||
if (0 < dy)
|
||||
{
|
||||
// Hit Top
|
||||
obj.oV = 1;
|
||||
obj.position.y += dy;
|
||||
|
||||
if (obj.sprite.physics.bounce.y > 0)
|
||||
{
|
||||
obj.sprite.physics.velocity.y *= -(obj.sprite.physics.bounce.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.sprite.physics.velocity.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dy = (obj.position.y + obj.bounds.halfHeight) - obj.world.bounds.bottom;
|
||||
|
||||
if (0 < dy)
|
||||
{
|
||||
// Hit Bottom
|
||||
obj.oV = -1;
|
||||
obj.position.y -= dy;
|
||||
|
||||
if (obj.sprite.physics.bounce.y > 0)
|
||||
{
|
||||
obj.sprite.physics.velocity.y *= -(obj.sprite.physics.bounce.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.sprite.physics.velocity.y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
private processWorld(px, py, dx, dy, tile) {
|
||||
|
||||
// Velocity
|
||||
//this.sprite.physics.velocity.x = this.position.x - this.oldPosition.x;
|
||||
//this.sprite.physics.velocity.y = this.position.y - this.oldPosition.y;
|
||||
|
||||
// Optimise!!!
|
||||
var dp: number = (this.sprite.physics.velocity.x * dx + this.sprite.physics.velocity.y * dy);
|
||||
var nx: number = dp * dx;
|
||||
var ny: number = dp * dy;
|
||||
var tx: number = this.sprite.physics.velocity.x - nx;
|
||||
var ty: number = this.sprite.physics.velocity.y - ny;
|
||||
|
||||
var bx, by, fx, fy;
|
||||
|
||||
if (dp < 0)
|
||||
{
|
||||
fx = tx * this.sprite.physics.friction.x;
|
||||
fy = ty * this.sprite.physics.friction.y;
|
||||
bx = (nx * (1 + this.sprite.physics.bounce.x));
|
||||
by = (ny * (1 + this.sprite.physics.bounce.y));
|
||||
//this.sprite.physics.velocity.x = bx;
|
||||
//this.sprite.physics.velocity.y = by;
|
||||
}
|
||||
else
|
||||
{
|
||||
bx = by = fx = fy = 0;
|
||||
}
|
||||
|
||||
this.position.x += px;
|
||||
this.position.y += py;
|
||||
|
||||
this.oldPosition.x += px + bx + fx;
|
||||
this.oldPosition.y += py + by + fy;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ TODO:
|
||||
* Fix bug in Tween yoyo + loop combo
|
||||
* Copy the setTransform from Sprite to Camera
|
||||
* Move Camera.scroll.x to just Camera.x/y
|
||||
* Get AABB offset working somehow
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +48,8 @@ V1.0.0
|
||||
* Sprite.modified is set to true if scale, rotation, skew or flip have been used.
|
||||
* Added Tween.loop property so they can now re-run themselves indefinitely.
|
||||
* Added Tween.yoyo property so they can reverse themselves after completing.
|
||||
* Added Gravity to the Physics component.
|
||||
|
||||
|
||||
V0.9.6
|
||||
|
||||
|
||||
+476
-442
File diff suppressed because it is too large
Load Diff
@@ -8,13 +8,15 @@
|
||||
}
|
||||
var atari;
|
||||
function create() {
|
||||
atari = game.add.sprite(200, 200, 'atari');
|
||||
atari = game.add.sprite(200, 300, 'atari');
|
||||
atari.texture.alpha = 0.5;
|
||||
atari.physics.bounce.setTo(0.5, 0.5);
|
||||
//atari.scale.setTo(2, 2);
|
||||
atari.physics.shape.setSize(150, 50);
|
||||
atari.physics.shape.offset.setTo(250, 25);
|
||||
//atari.physics.gravity.setTo(0, 2);
|
||||
atari.physics.bounce.setTo(0.7, 0.7);
|
||||
atari.physics.drag.setTo(10, 10);
|
||||
//atari.physics.gravityFactor.x = 0;
|
||||
//atari.physics.gravityFactor.y = 0;
|
||||
}
|
||||
}
|
||||
function update() {
|
||||
atari.physics.acceleration.x = 0;
|
||||
atari.physics.acceleration.y = 0;
|
||||
|
||||
@@ -16,15 +16,17 @@
|
||||
|
||||
function create() {
|
||||
|
||||
atari = game.add.sprite(200, 200, 'atari');
|
||||
atari = game.add.sprite(200, 300, 'atari');
|
||||
atari.texture.alpha = 0.5;
|
||||
//atari.scale.setTo(2, 2);
|
||||
|
||||
atari.physics.bounce.setTo(0.5, 0.5);
|
||||
atari.physics.shape.setSize(150, 50);
|
||||
atari.physics.shape.offset.setTo(50, 25);
|
||||
|
||||
//atari.physics.gravity.setTo(0, 2);
|
||||
atari.physics.bounce.setTo(0.7, 0.7);
|
||||
atari.physics.drag.setTo(10, 10);
|
||||
|
||||
//atari.physics.gravityFactor.x = 0;
|
||||
//atari.physics.gravityFactor.y = 0;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
Vendored
+234
-222
@@ -3019,6 +3019,207 @@ module Phaser {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phaser - Vec2Utils
|
||||
*
|
||||
* A collection of methods useful for manipulating and performing operations on 2D vectors.
|
||||
*
|
||||
*/
|
||||
module Phaser {
|
||||
class Vec2Utils {
|
||||
/**
|
||||
* Adds two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the sum of the two vectors.
|
||||
*/
|
||||
static add(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Subtracts two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the difference of the two vectors.
|
||||
*/
|
||||
static subtract(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Multiplies two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the sum of the two vectors multiplied.
|
||||
*/
|
||||
static multiply(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Divides two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the sum of the two vectors divided.
|
||||
*/
|
||||
static divide(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Scales a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {number} s Scaling value.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the scaled vector.
|
||||
*/
|
||||
static scale(a: Vec2, s: number, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Rotate a 2D vector by 90 degrees.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the scaled vector.
|
||||
*/
|
||||
static perp(a: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Checks if two 2D vectors are equal.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
static equals(a: Vec2, b: Vec2): bool;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} epsilon
|
||||
* @return {Boolean}
|
||||
*/
|
||||
static epsilonEquals(a: Vec2, b: Vec2, epsilon: number): bool;
|
||||
/**
|
||||
* Get the distance between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static distance(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* Get the distance squared between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static distanceSq(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* Project two 2D vectors onto another vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static project(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Project this vector onto a vector of unit length.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static projectUnit(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Right-hand normalize (make unit length) a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static normalRightHand(a: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Normalize (make unit length) a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static normalize(a: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* The dot product of two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static dot(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* The cross product of two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static cross(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* The angle between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static angle(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* The angle squared between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static angleSq(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* Rotate a 2D vector around the origin to the given angle (theta).
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Number} theta The angle of rotation in radians.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static rotate(a: Vec2, b: Vec2, theta: number, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Clone a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is a copy of the source Vec2.
|
||||
*/
|
||||
static clone(a: Vec2, out?: Vec2): Vec2;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phaser - Physics - IPhysicsShape
|
||||
*/
|
||||
module Phaser.Physics {
|
||||
interface IPhysicsShape {
|
||||
game: Game;
|
||||
world: PhysicsManager;
|
||||
sprite: Sprite;
|
||||
physics: Components.Physics;
|
||||
position: Vec2;
|
||||
oldPosition: Vec2;
|
||||
offset: Vec2;
|
||||
bounds: Rectangle;
|
||||
oH: number;
|
||||
oV: number;
|
||||
setSize(width: number, height: number);
|
||||
preUpdate();
|
||||
update();
|
||||
render(context: CanvasRenderingContext2D);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phaser - PhysicsManager
|
||||
*
|
||||
* Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding
|
||||
@@ -3030,50 +3231,21 @@ module Phaser.Physics {
|
||||
/**
|
||||
* Local private reference to Game.
|
||||
*/
|
||||
private _game;
|
||||
public game: Game;
|
||||
private _objects;
|
||||
private _drag;
|
||||
private _delta;
|
||||
private _velocityDelta;
|
||||
private _length;
|
||||
public bounds: Rectangle;
|
||||
public gravity: Vec2;
|
||||
public drag: Vec2;
|
||||
public bounce: Vec2;
|
||||
public friction: Vec2;
|
||||
private minFriction;
|
||||
private maxFriction;
|
||||
private minBounce;
|
||||
private maxBounce;
|
||||
private minGravity;
|
||||
private maxGravity;
|
||||
private _i;
|
||||
private _length;
|
||||
public add(o);
|
||||
public add(shape: IPhysicsShape): IPhysicsShape;
|
||||
public update(): void;
|
||||
public render(): void;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phaser - Physics - AABB
|
||||
*/
|
||||
module Phaser.Physics {
|
||||
class AABB {
|
||||
constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number);
|
||||
/**
|
||||
* Local private reference to Game.
|
||||
*/
|
||||
public game: Game;
|
||||
public world: PhysicsManager;
|
||||
public sprite: Sprite;
|
||||
public position: Vec2;
|
||||
public oldPosition: Vec2;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public halfWidth: number;
|
||||
public halfHeight: number;
|
||||
public oH: number;
|
||||
public oV: number;
|
||||
private _drag;
|
||||
public newVelocity: Vec2;
|
||||
public update(): void;
|
||||
private updateMotion();
|
||||
private updateMotion(obj);
|
||||
/**
|
||||
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
|
||||
*
|
||||
@@ -3084,10 +3256,30 @@ module Phaser.Physics {
|
||||
*
|
||||
* @return {number} The altered Velocity value.
|
||||
*/
|
||||
public computeVelocity(velocity: number, acceleration?: number, drag?: number, max?: number): number;
|
||||
private integrate();
|
||||
private collideWorld();
|
||||
private processWorld(px, py, dx, dy, tile);
|
||||
public computeVelocity(velocity: number, gravity?: number, acceleration?: number, drag?: number, max?: number): number;
|
||||
private collideWorld(obj);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phaser - Physics - AABB
|
||||
*/
|
||||
module Phaser.Physics {
|
||||
class AABB implements IPhysicsShape {
|
||||
constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number);
|
||||
public game: Game;
|
||||
public world: PhysicsManager;
|
||||
public sprite: Sprite;
|
||||
public physics: Components.Physics;
|
||||
public position: Vec2;
|
||||
public oldPosition: Vec2;
|
||||
public offset: Vec2;
|
||||
public scale: Vec2;
|
||||
public bounds: Rectangle;
|
||||
public oH: number;
|
||||
public oV: number;
|
||||
public preUpdate(): void;
|
||||
public update(): void;
|
||||
public setSize(width: number, height: number): void;
|
||||
public render(context: CanvasRenderingContext2D): void;
|
||||
}
|
||||
}
|
||||
@@ -4817,186 +5009,6 @@ module Phaser {
|
||||
module Phaser {
|
||||
}
|
||||
/**
|
||||
* Phaser - Vec2Utils
|
||||
*
|
||||
* A collection of methods useful for manipulating and performing operations on 2D vectors.
|
||||
*
|
||||
*/
|
||||
module Phaser {
|
||||
class Vec2Utils {
|
||||
/**
|
||||
* Adds two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the sum of the two vectors.
|
||||
*/
|
||||
static add(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Subtracts two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the difference of the two vectors.
|
||||
*/
|
||||
static subtract(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Multiplies two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the sum of the two vectors multiplied.
|
||||
*/
|
||||
static multiply(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Divides two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the sum of the two vectors divided.
|
||||
*/
|
||||
static divide(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Scales a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {number} s Scaling value.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the scaled vector.
|
||||
*/
|
||||
static scale(a: Vec2, s: number, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Rotate a 2D vector by 90 degrees.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the scaled vector.
|
||||
*/
|
||||
static perp(a: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Checks if two 2D vectors are equal.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
static equals(a: Vec2, b: Vec2): bool;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} epsilon
|
||||
* @return {Boolean}
|
||||
*/
|
||||
static epsilonEquals(a: Vec2, b: Vec2, epsilon: number): bool;
|
||||
/**
|
||||
* Get the distance between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static distance(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* Get the distance squared between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static distanceSq(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* Project two 2D vectors onto another vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static project(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Project this vector onto a vector of unit length.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static projectUnit(a: Vec2, b: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Right-hand normalize (make unit length) a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static normalRightHand(a: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Normalize (make unit length) a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static normalize(a: Vec2, out?: Vec2): Vec2;
|
||||
/**
|
||||
* The dot product of two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static dot(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* The cross product of two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static cross(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* The angle between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static angle(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* The angle squared between two 2D vectors.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @return {Number}
|
||||
*/
|
||||
static angleSq(a: Vec2, b: Vec2): number;
|
||||
/**
|
||||
* Rotate a 2D vector around the origin to the given angle (theta).
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} b Reference to a source Vec2 object.
|
||||
* @param {Number} theta The angle of rotation in radians.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static rotate(a: Vec2, b: Vec2, theta: number, out?: Vec2): Vec2;
|
||||
/**
|
||||
* Clone a 2D vector.
|
||||
*
|
||||
* @param {Vec2} a Reference to a source Vec2 object.
|
||||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is a copy of the source Vec2.
|
||||
*/
|
||||
static clone(a: Vec2, out?: Vec2): Vec2;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Phaser - Pointer
|
||||
*
|
||||
* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||
@@ -6436,7 +6448,7 @@ module Phaser.Components {
|
||||
*
|
||||
*/
|
||||
private _sprite;
|
||||
public AABB: Physics.AABB;
|
||||
public shape: Physics.IPhysicsShape;
|
||||
/**
|
||||
* Whether this object will be moved by impacts with other objects or not.
|
||||
* @type {boolean}
|
||||
@@ -6447,7 +6459,7 @@ module Phaser.Components {
|
||||
* @type {boolean}
|
||||
*/
|
||||
public moves: bool;
|
||||
public gravityFactor: Vec2;
|
||||
public gravity: Vec2;
|
||||
public drag: Vec2;
|
||||
public bounce: Vec2;
|
||||
public friction: Vec2;
|
||||
|
||||
+476
-442
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user