Merge branch 'photonstorm/097'

This commit is contained in:
Sean
2013-06-14 08:41:39 +08:00
153 changed files with 16219 additions and 11421 deletions
+6 -4
View File
@@ -1,9 +1,9 @@
/// <reference path="core/Rectangle.ts" />
/// <reference path="geom/Rectangle.ts" />
/// <reference path="math/LinkedList.ts" />
/// <reference path="math/QuadTree.ts" />
/// <reference path="core/Point.ts" />
/// <reference path="core/Vec2.ts" />
/// <reference path="core/Circle.ts" />
/// <reference path="geom/Point.ts" />
/// <reference path="math/Vec2.ts" />
/// <reference path="geom/Circle.ts" />
/// <reference path="core/Group.ts" />
/// <reference path="core/Signal.ts" />
/// <reference path="core/SignalBinding.ts" />
@@ -416,6 +416,8 @@ module Phaser {
this.onUpdateCallback.call(this.callbackContext);
}
this.world.postUpdate();
this.renderer.render();
if (this._loadComplete && this.onRenderCallback)
+8 -8
View File
@@ -210,8 +210,8 @@ module Phaser {
* @return {number} Distance (in pixels)
*/
public distanceToPoint(a: Sprite, target: Point): number {
var dx: number = (a.x + a.origin.x) - (target.x);
var dy: number = (a.y + a.origin.y) - (target.y);
var dx: number = (a.x + a.transform.origin.x) - (target.x);
var dy: number = (a.y + a.transform.origin.y) - (target.y);
return this.game.math.vectorLength(dx, dy);
}
@@ -223,8 +223,8 @@ module Phaser {
* @return {number} The distance between the given sprite and the mouse coordinates
*/
public distanceToMouse(a: Sprite): number {
var dx: number = (a.x + a.origin.x) - this.game.input.x;
var dy: number = (a.y + a.origin.y) - this.game.input.y;
var dx: number = (a.x + a.transform.origin.x) - this.game.input.x;
var dy: number = (a.y + a.transform.origin.y) - this.game.input.y;
return this.game.math.vectorLength(dx, dy);
}
@@ -240,8 +240,8 @@ module Phaser {
* @return {number} The angle (in radians unless asDegrees is true)
*/
public angleBetweenPoint(a: Sprite, target: Point, asDegrees: bool = false): number {
var dx: number = (target.x) - (a.x + a.origin.x);
var dy: number = (target.y) - (a.y + a.origin.y);
var dx: number = (target.x) - (a.x + a.transform.origin.x);
var dy: number = (target.y) - (a.y + a.transform.origin.y);
if (asDegrees)
{
@@ -265,8 +265,8 @@ module Phaser {
*/
public angleBetween(a: Sprite, b: Sprite, asDegrees: bool = false): number {
var dx: number = (b.x + b.origin.x) - (a.x + a.origin.x);
var dy: number = (b.y + b.origin.y) - (a.y + a.origin.y);
var dx: number = (b.x + b.transform.origin.x) - (a.x + a.transform.origin.x);
var dy: number = (b.y + b.transform.origin.y) - (a.y + a.transform.origin.y);
if (asDegrees)
{
+36 -28
View File
@@ -74,36 +74,24 @@
<Content Include="components\sprite\Input.js">
<DependentUpon>Input.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="components\Texture.ts" />
<Content Include="components\Texture.js">
<DependentUpon>Texture.ts</DependentUpon>
</Content>
<Content Include="components\Tile.ts" />
<Content Include="components\TilemapLayer.ts" />
<TypeScriptCompile Include="components\Transform.ts" />
<Content Include="components\Transform.js">
<DependentUpon>Transform.ts</DependentUpon>
</Content>
<Content Include="Game.js">
<DependentUpon>Game.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="core\Rectangle.ts" />
<TypeScriptCompile Include="core\Point.ts" />
<TypeScriptCompile Include="components\sprite\Texture.ts" />
<TypeScriptCompile Include="components\camera\CameraFX.ts" />
<Content Include="components\camera\CameraFX.js">
<DependentUpon>CameraFX.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="components\ScrollRegion.ts" />
<Content Include="components\sprite\Texture.js">
<DependentUpon>Texture.ts</DependentUpon>
</Content>
<Content Include="core\Point.js">
<DependentUpon>Point.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="core\Polygon.ts" />
<Content Include="core\Polygon.js">
<DependentUpon>Polygon.ts</DependentUpon>
</Content>
<Content Include="core\Rectangle.js">
<DependentUpon>Rectangle.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="core\Vec2.ts" />
<Content Include="core\Vec2.js">
<DependentUpon>Vec2.ts</DependentUpon>
</Content>
<Content Include="gameobjects\DynamicTexture.js">
<DependentUpon>DynamicTexture.ts</DependentUpon>
</Content>
@@ -122,6 +110,22 @@
<Content Include="gameobjects\Tilemap.js">
<DependentUpon>Tilemap.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="geom\Circle.ts" />
<Content Include="geom\Circle.js">
<DependentUpon>Circle.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="geom\Line.ts" />
<Content Include="geom\Line.js">
<DependentUpon>Line.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="geom\Point.ts" />
<Content Include="geom\Point.js">
<DependentUpon>Point.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="geom\Rectangle.ts" />
<Content Include="geom\Rectangle.js">
<DependentUpon>Rectangle.ts</DependentUpon>
</Content>
<Content Include="math\GameMath.js">
<DependentUpon>GameMath.ts</DependentUpon>
</Content>
@@ -140,6 +144,14 @@
<TypeScriptCompile Include="physics\PhysicsManager.ts" />
<TypeScriptCompile Include="physics\Body.ts" />
<TypeScriptCompile Include="math\QuadTree.ts" />
<TypeScriptCompile Include="math\Mat3.ts" />
<Content Include="math\Mat3.js">
<DependentUpon>Mat3.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="math\Mat3Utils.ts" />
<Content Include="math\Mat3Utils.js">
<DependentUpon>Mat3Utils.ts</DependentUpon>
</Content>
<Content Include="math\QuadTree.js">
<DependentUpon>QuadTree.ts</DependentUpon>
</Content>
@@ -148,6 +160,10 @@
<DependentUpon>LinkedList.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="Motion.ts" />
<TypeScriptCompile Include="math\Vec2.ts" />
<Content Include="math\Vec2.js">
<DependentUpon>Vec2.ts</DependentUpon>
</Content>
<Content Include="Motion.js">
<DependentUpon>Motion.ts</DependentUpon>
</Content>
@@ -196,15 +212,9 @@
<Content Include="utils\RectangleUtils.js">
<DependentUpon>RectangleUtils.ts</DependentUpon>
</Content>
<Content Include="core\Circle.js">
<DependentUpon>Circle.ts</DependentUpon>
</Content>
<Content Include="math\IntersectResult.js">
<DependentUpon>IntersectResult.ts</DependentUpon>
</Content>
<Content Include="core\Line.js">
<DependentUpon>Line.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="math\Vec2Utils.ts" />
<Content Include="math\Vec2Utils.js">
<DependentUpon>Vec2Utils.ts</DependentUpon>
@@ -337,9 +347,7 @@
<TypeScriptCompile Include="components\animation\Frame.ts" />
<TypeScriptCompile Include="loader\AnimationLoader.ts" />
<TypeScriptCompile Include="components\animation\Animation.ts" />
<TypeScriptCompile Include="core\Line.ts" />
<TypeScriptCompile Include="math\IntersectResult.ts" />
<TypeScriptCompile Include="core\Circle.ts" />
<Content Include="core\Group.js">
<DependentUpon>Group.ts</DependentUpon>
</Content>
+10 -1
View File
@@ -53,7 +53,7 @@ module Phaser {
this.context = this.canvas.getContext('2d');
this.scaleMode = StageScaleMode.NO_SCALE;
this.scale = new StageScaleMode(this._game);
this.scale = new StageScaleMode(this._game, width, height);
this.getOffset(this.canvas);
this.bounds = new Rectangle(this.offset.x, this.offset.y, width, height);
@@ -167,6 +167,8 @@ module Phaser {
this.pauseScreen = new PauseScreen(this._game, this.width, this.height);
this.orientationScreen = new OrientationScreen(this._game);
this.scale.setScreenSize(true);
}
/**
@@ -253,6 +255,13 @@ module Phaser {
}
public setImageRenderingCrisp() {
this.canvas.style['image-rendering'] = 'crisp-edges';
this.canvas.style['image-rendering'] = '-moz-crisp-edges';
this.canvas.style['image-rendering'] = '-webkit-optimize-contrast';
this.canvas.style['-ms-interpolation-mode'] = 'nearest-neighbor';
}
public pauseGame() {
if (this.disablePauseScreen == false && this.pauseScreen)
+1 -1
View File
@@ -20,7 +20,7 @@ module Phaser {
static GEOM_POINT: number = 0;
static GEOM_CIRCLE: number = 1;
static GEOM_RECTANGLE: number = 2;
static GEOM_Rectangle: number = 2;
static GEOM_LINE: number = 3;
static GEOM_POLYGON: number = 4;
+12 -1
View File
@@ -1,7 +1,7 @@
/// <reference path="Game.ts" />
/// <reference path="cameras/CameraManager.ts" />
/// <reference path="core/Group.ts" />
/// <reference path="core/Rectangle.ts" />
/// <reference path="geom/Rectangle.ts" />
/// <reference path="physics/PhysicsManager.ts" />
/**
@@ -96,6 +96,17 @@ module Phaser {
}
/**
* This is called automatically every frame, and is where main logic happens.
*/
public postUpdate() {
//this.physics.postUpdate();
this.group.postUpdate();
this.cameras.postUpdate();
}
/**
* Clean up memory.
*/
+173 -267
View File
@@ -1,9 +1,11 @@
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Vec2.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../components/camera/CameraFX.ts" />
/// <reference path="../components/Texture.ts" />
/// <reference path="../components/Transform.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/**
* Phaser - Camera
@@ -29,37 +31,45 @@ module Phaser {
*/
constructor(game: Game, id: number, x: number, y: number, width: number, height: number) {
this._game = game;
this.game = game;
this.ID = id;
this._stageX = x;
this._stageY = y;
this.scaledX = x;
this.scaledY = y;
this.fx = new CameraFX(this._game, this);
this.z = id;
// The view into the world canvas we wish to render
// The view into the world we wish to render (by default the full game world size)
// The size of this Rect is the same as screenView, but the values are all in world coordinates instead of screen coordinates
this.worldView = new Rectangle(0, 0, width, height);
// The rect of the area being rendered in stage/screen coordinates
this.screenView = new Rectangle(x, y, width, height);
this.fx = new CameraFX(this.game, this);
this.transform = new Phaser.Components.Transform(this);
this.texture = new Phaser.Components.Texture(this);
this.texture.opaque = false;
this.checkClip();
}
private _target: Sprite = null;
/**
* Local private reference to Game.
*/
private _game: Game;
public game: Game;
private _clip: bool = false;
private _stageX: number;
private _stageY: number;
private _rotation: number = 0;
private _target: Sprite = null;
//private _sx: number = 0;
//private _sy: number = 0;
/**
* Optional texture used in the background of the Camera.
*/
public texture: Phaser.Components.Texture;
public scaledX: number;
public scaledY: number;
/**
* The transform component.
*/
public transform: Phaser.Components.Transform;
/**
* Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.
@@ -91,31 +101,35 @@ module Phaser {
public ID: number;
/**
* Camera view rectangle in world coordinate.
* Controls if this camera is clipped or not when rendering. You shouldn't usually set this value directly.
*/
public clip: bool = false;
/**
* Camera view Rectangle in world coordinate.
* @type {Rectangle}
*/
public worldView: Rectangle;
/**
* Scale factor of the camera.
* @type {Vec2}
*/
public scale: Vec2 = new Vec2(1, 1);
/**
* Scrolling factor.
* @type {MicroPoint}
*/
public scroll: Vec2 = new Vec2(0, 0);
/**
* Camera bounds.
* Visible / renderable area (changes if the camera resizes/moves around the stage)
* @type {Rectangle}
*/
public bounds: Rectangle = null;
public screenView: Rectangle;
/**
* Sprite moving inside this rectangle will not cause camera moving.
* Camera worldBounds.
* @type {Rectangle}
*/
public worldBounds: Rectangle = null;
/**
* A boolean representing if the Camera has been modified in any way via a scale, rotate, flip or skew.
*/
public modified: bool = false;
/**
* Sprite moving inside this Rectangle will not cause camera moving.
* @type {Rectangle}
*/
public deadzone: Rectangle = null;
@@ -127,44 +141,15 @@ module Phaser {
public disableClipping: bool = false;
/**
* Whether the camera background is opaque or not. If set to true the Camera is filled with
* the value of Camera.backgroundColor every frame. Normally you wouldn't enable this if the
* Camera is the full Stage size, as the Stage.backgroundColor has the same effect. But for
* multiple or mini cameras it can be very useful.
* @type {boolean}
*/
public opaque: bool = false;
/**
* The Background Color of the camera in css color string format, i.e. 'rgb(0,0,0)' or '#ff0000'.
* Not used if the Camera.opaque property is false.
* @type {string}
*/
public backgroundColor: string = 'rgb(0,0,0)';
/**
* Whether this camera visible or not. (default is true)
* Whether this camera is visible or not. (default is true)
* @type {boolean}
*/
public visible: bool = true;
/**
* Alpha of the camera. (everything rendered to this camera will be affected)
* @type {number}
* The z value of this Camera. Cameras are rendered in z-index order by the Renderer.
*/
public alpha: number = 1;
/**
* The x position of the current input event in world coordinates.
* @type {number}
*/
public inputX: number = 0;
/**
* The y position of the current input event in world coordinates.
* @type {number}
*/
public inputY: number = 0;
public z: number = -1;
/**
* Effects manager.
@@ -182,7 +167,7 @@ module Phaser {
if (this.isHidden(object) == false)
{
object['cameraBlacklist'].push(this.ID);
object.texture['cameraBlacklist'].push(this.ID);
}
}
@@ -193,9 +178,7 @@ module Phaser {
* @param object {Sprite/Group} The object to check.
*/
public isHidden(object): bool {
return (object['cameraBlacklist'] && object['cameraBlacklist'].length > 0 && object['cameraBlacklist'].indexOf(this.ID) == -1);
return (object.texture['cameraBlacklist'] && object.texture['cameraBlacklist'].length > 0 && object.texture['cameraBlacklist'].indexOf(this.ID) == -1);
}
/**
@@ -208,7 +191,7 @@ module Phaser {
if (this.isHidden(object) == true)
{
object['cameraBlacklist'].slice(object['cameraBlacklist'].indexOf(this.ID), 1);
object.texture['cameraBlacklist'].slice(object.texture['cameraBlacklist'].indexOf(this.ID), 1);
}
}
@@ -257,8 +240,8 @@ module Phaser {
x += (x > 0) ? 0.0000001 : -0.0000001;
y += (y > 0) ? 0.0000001 : -0.0000001;
this.scroll.x = Math.round(x - this.worldView.halfWidth);
this.scroll.y = Math.round(y - this.worldView.halfHeight);
this.worldView.x = Math.round(x - this.worldView.halfWidth);
this.worldView.y = Math.round(y - this.worldView.halfHeight);
}
@@ -271,8 +254,8 @@ module Phaser {
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
this.scroll.x = Math.round(point.x - this.worldView.halfWidth);
this.scroll.y = Math.round(point.y - this.worldView.halfHeight);
this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
}
@@ -286,14 +269,15 @@ module Phaser {
*/
public setBounds(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
if (this.bounds == null)
if (this.worldBounds == null)
{
this.bounds = new Rectangle();
this.worldBounds = new Rectangle;
}
this.bounds.setTo(x, y, width, height);
this.worldBounds.setTo(x, y, width, height);
this.scroll.setTo(0, 0);
this.worldView.x = x;
this.worldView.y = y;
this.update();
}
@@ -303,6 +287,11 @@ module Phaser {
*/
public update() {
if (this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
{
this.modified = true;
}
this.fx.preUpdate();
if (this._target !== null)
@@ -319,206 +308,116 @@ module Phaser {
edge = targetX - this.deadzone.x;
if (this.scroll.x > edge)
if (this.worldView.x > edge)
{
this.scroll.x = edge;
this.worldView.x = edge;
}
edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
if (this.scroll.x < edge)
if (this.worldView.x < edge)
{
this.scroll.x = edge;
this.worldView.x = edge;
}
edge = targetY - this.deadzone.y;
if (this.scroll.y > edge)
if (this.worldView.y > edge)
{
this.scroll.y = edge;
this.worldView.y = edge;
}
edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
if (this.scroll.y < edge)
if (this.worldView.y < edge)
{
this.scroll.y = edge;
this.worldView.y = edge;
}
}
}
// Make sure we didn't go outside the cameras bounds
if (this.bounds !== null)
// Make sure we didn't go outside the cameras worldBounds
if (this.worldBounds !== null)
{
if (this.scroll.x < this.bounds.left)
if (this.worldView.x < this.worldBounds.left)
{
this.scroll.x = this.bounds.left;
this.worldView.x = this.worldBounds.left;
}
if (this.scroll.x > this.bounds.right - this.width)
if (this.worldView.x > this.worldBounds.right - this.width)
{
this.scroll.x = (this.bounds.right - this.width) + 1;
this.worldView.x = (this.worldBounds.right - this.width) + 1;
}
if (this.scroll.y < this.bounds.top)
if (this.worldView.y < this.worldBounds.top)
{
this.scroll.y = this.bounds.top;
this.worldView.y = this.worldBounds.top;
}
if (this.scroll.y > this.bounds.bottom - this.height)
if (this.worldView.y > this.worldBounds.bottom - this.height)
{
this.scroll.y = (this.bounds.bottom - this.height) + 1;
this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
}
}
this.worldView.x = this.scroll.x;
this.worldView.y = this.scroll.y;
}
// Input values
this.inputX = this.worldView.x + this._game.input.x;
this.inputY = this.worldView.y + this._game.input.y;
/**
* Update focusing and scrolling.
*/
public postUpdate() {
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
{
this.modified = false;
}
// Make sure we didn't go outside the cameras worldBounds
if (this.worldBounds !== null)
{
if (this.worldView.x < this.worldBounds.left)
{
this.worldView.x = this.worldBounds.left;
}
if (this.worldView.x > this.worldBounds.right - this.width)
{
this.worldView.x = (this.worldBounds.right - this.width) + 1;
}
if (this.worldView.y < this.worldBounds.top)
{
this.worldView.y = this.worldBounds.top;
}
if (this.worldView.y > this.worldBounds.bottom - this.height)
{
this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
}
}
this.fx.postUpdate();
}
/**
* Camera preRender
*/
public preRender() {
if (this.visible === false || this.alpha < 0.1)
{
return;
}
if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.save();
}
this.fx.preRender(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
if (this.alpha !== 1)
{
this._game.stage.context.globalAlpha = this.alpha;
}
this.scaledX = this._stageX;
this.scaledY = this._stageY;
// Scale on
if (this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.scale(this.scale.x, this.scale.y);
this.scaledX = this.scaledX / this.scale.x;
this.scaledY = this.scaledY / this.scale.y;
}
// Rotation - translate to the mid-point of the camera
if (this._rotation !== 0)
{
this._game.stage.context.translate(this.scaledX + this.worldView.halfWidth, this.scaledY + this.worldView.halfHeight);
this._game.stage.context.rotate(this._rotation * (Math.PI / 180));
// now shift back to where that should actually render
this._game.stage.context.translate(-(this.scaledX + this.worldView.halfWidth), -(this.scaledY + this.worldView.halfHeight));
}
// Background
if (this.opaque)
{
this._game.stage.context.fillStyle = this.backgroundColor;
this._game.stage.context.fillRect(this.scaledX, this.scaledY, this.worldView.width, this.worldView.height);
}
this.fx.render(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
// Clip the camera so we don't get sprites appearing outside the edges
if (this._clip == true && this.disableClipping == false)
{
this._game.stage.context.beginPath();
this._game.stage.context.rect(this.scaledX, this.scaledY, this.worldView.width, this.worldView.height);
this._game.stage.context.closePath();
this._game.stage.context.clip();
}
}
/**
* Camera postRender
*/
public postRender() {
// Scale off
if (this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.scale(1, 1);
}
this.fx.postRender(this, this.scaledX, this.scaledY, this.worldView.width, this.worldView.height);
if (this._rotation !== 0 || (this._clip && this.disableClipping == false))
{
this._game.stage.context.translate(0, 0);
}
if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.restore();
}
if (this.alpha !== 1)
{
this._game.stage.context.globalAlpha = 1;
}
}
/**
* Set position of this camera.
* @param x {number} X position.
* @param y {number} Y position.
*/
public setPosition(x: number, y: number) {
this._stageX = x;
this._stageY = y;
this.checkClip();
}
/**
* Give this camera a new size.
* @param width {number} Width of new size.
* @param height {number} Height of new size.
*/
public setSize(width: number, height: number) {
this.worldView.width = width;
this.worldView.height = height;
this.checkClip();
}
/**
* Render debug infos. (including id, position, rotation, scrolling factor, bounds and some other properties)
* Render debug infos. (including id, position, rotation, scrolling factor, worldBounds and some other properties)
* @param x {number} X position of the debug info to be rendered.
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Camera ID: ' + this.ID + ' (' + this.worldView.width + ' x ' + this.worldView.height + ')', x, y);
this._game.stage.context.fillText('X: ' + this._stageX + ' Y: ' + this._stageY + ' Rotation: ' + this._rotation, x, y + 14);
this._game.stage.context.fillText('World X: ' + this.scroll.x.toFixed(1) + ' World Y: ' + this.scroll.y.toFixed(1), x, y + 28);
this.game.stage.context.fillStyle = color;
this.game.stage.context.fillText('Camera ID: ' + this.ID + ' (' + this.screenView.width + ' x ' + this.screenView.height + ')', x, y);
this.game.stage.context.fillText('X: ' + this.screenView.x + ' Y: ' + this.screenView.y + ' rotation: ' + this.transform.rotation, x, y + 14);
this.game.stage.context.fillText('World X: ' + this.worldView.x + ' World Y: ' + this.worldView.y + ' W: ' + this.worldView.width + ' H: ' + this.worldView.height + ' R: ' + this.worldView.right + ' B: ' + this.worldView.bottom, x, y + 28);
this.game.stage.context.fillText('ScreenView X: ' + this.screenView.x + ' Y: ' + this.screenView.y + ' W: ' + this.screenView.width + ' H: ' + this.screenView.height, x, y + 42);
if (this.bounds)
if (this.worldBounds)
{
this._game.stage.context.fillText('Bounds: ' + this.bounds.width + ' x ' + this.bounds.height, x, y + 42);
this.game.stage.context.fillText('Bounds: ' + this.worldBounds.width + ' x ' + this.worldBounds.height, x, y + 56);
}
}
@@ -528,75 +427,82 @@ module Phaser {
*/
public destroy() {
this._game.world.cameras.removeCamera(this.ID);
this.game.world.cameras.removeCamera(this.ID);
this.fx.destroy();
}
public get x(): number {
return this._stageX;
}
public set x(value: number) {
this._stageX = value;
this.checkClip();
return this.worldView.x;
}
public get y(): number {
return this._stageY;
return this.worldView.y;
}
public set x(value: number) {
this.worldView.x = value;
}
public set y(value: number) {
this._stageY = value;
this.checkClip();
this.worldView.y = value;
}
public get width(): number {
return this.worldView.width;
}
public set width(value: number) {
if (value > this._game.stage.width)
{
value = this._game.stage.width;
}
this.worldView.width = value;
this.checkClip();
return this.screenView.width;
}
public get height(): number {
return this.worldView.height;
return this.screenView.height;
}
public set width(value: number) {
this.screenView.width = value;
this.worldView.width = value;
}
public set height(value: number) {
if (value > this._game.stage.height)
{
value = this._game.stage.height;
}
this.screenView.height = value;
this.worldView.height = value;
}
public setPosition(x: number, y: number) {
this.screenView.x = x;
this.screenView.y = y;
this.checkClip();
}
public get rotation(): number {
return this._rotation;
public setSize(width: number, height: number) {
this.screenView.width = width * this.transform.scale.x;
this.screenView.height = height * this.transform.scale.y;
this.worldView.width = width;
this.worldView.height = height;
this.checkClip();
}
/**
* The angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
*/
public get rotation(): number {
return this.transform.rotation;
}
/**
* Set the angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* The value is automatically wrapped to be between 0 and 360.
*/
public set rotation(value: number) {
this._rotation = this._game.math.wrap(value, 360, 0);
this.transform.rotation = this.game.math.wrap(value, 360, 0);
}
private checkClip() {
if (this._stageX !== 0 || this._stageY !== 0 || this.worldView.width < this._game.stage.width || this.worldView.height < this._game.stage.height)
if (this.screenView.x != 0 || this.screenView.y != 0 || this.screenView.width < this.game.stage.width || this.screenView.height < this.game.stage.height)
{
this._clip = true;
this.clip = true;
}
else
{
this._clip = false;
this.clip = false;
}
}
+87 -1
View File
@@ -47,6 +47,16 @@ module Phaser {
*/
private _cameraInstance: number = 0;
/**
* Helper for sort.
*/
private _sortIndex: string = '';
/**
* Helper for sort.
*/
private _sortOrder: number;
public static CAMERA_TYPE_ORTHOGRAPHIC: number = 0;
public static CAMERA_TYPE_ISOMETRIC: number = 1;
@@ -73,7 +83,24 @@ module Phaser {
* Update cameras.
*/
public update() {
this._cameras.forEach((camera) => camera.update());
for (var i = 0; i < this._cameras.length; i++)
{
this._cameras[i].update();
}
}
/**
* postUpdate cameras.
*/
public postUpdate() {
for (var i = 0; i < this._cameras.length; i++)
{
this._cameras[i].postUpdate();
}
}
/**
@@ -124,6 +151,65 @@ module Phaser {
}
public swap(camera1: Camera, camera2: Camera, sort?: bool = true): bool {
if (camera1.ID == camera2.ID)
{
return false;
}
var tempZ: number = camera1.z;
camera1.z = camera2.z;
camera2.z = tempZ;
if (sort)
{
this.sort();
}
return true;
}
/**
* Call this function to sort the Cameras according to a particular value and order (default is their Z value).
* The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first.
*
* @param {string} index The <code>string</code> name of the Camera variable you want to sort on. Default value is "z".
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
*/
public sort(index: string = 'z', order: number = Group.ASCENDING) {
this._sortIndex = index;
this._sortOrder = order;
this._cameras.sort((a, b) => this.sortHandler(a, b));
}
/**
* Helper function for the sort process.
*
* @param {Basic} Obj1 The first object being sorted.
* @param {Basic} Obj2 The second object being sorted.
*
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
*/
public sortHandler(obj1, obj2): number {
if (obj1[this._sortIndex] < obj2[this._sortIndex])
{
return this._sortOrder;
}
else if (obj1[this._sortIndex] > obj2[this._sortIndex])
{
return -this._sortOrder;
}
return 0;
}
/**
* Clean up memory.
*/
+2 -2
View File
@@ -1,6 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Vec2.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../math/Vec2.ts" />
/**
* Phaser - ScrollRegion
@@ -1,11 +1,11 @@
/// <reference path="../../Game.ts" />
/// <reference path="../../gameobjects/DynamicTexture.ts" />
/// <reference path="../../utils/SpriteUtils.ts" />
/// <reference path="../Game.ts" />
/// <reference path="../gameobjects/DynamicTexture.ts" />
/// <reference path="../utils/SpriteUtils.ts" />
/**
* Phaser - Components - Texture
*
* The Texture being used to render the Sprite. Either Image based on a DynamicTexture.
* The Texture being used to render the object (Sprite, Group background, etc). Either Image based on a DynamicTexture.
*/
module Phaser.Components {
@@ -13,14 +13,14 @@ module Phaser.Components {
export class Texture {
/**
* Creates a new Sprite Texture component
* @param parent The Sprite using this Texture to render
* Creates a new Texture component
* @param parent The object using this Texture to render.
* @param key An optional Game.Cache key to load an image from
*/
constructor(parent: Sprite, key?: string = '') {
constructor(parent) {
this.game = parent.game;
this._sprite = parent;
this.parent = parent;
this.canvas = parent.game.stage.canvas;
this.context = parent.game.stage.context;
@@ -28,14 +28,22 @@ module Phaser.Components {
this.flippedX = false;
this.flippedY = false;
if (key !== null)
{
this.cacheKey = key;
this.loadImage(key);
}
this._width = 16;
this._height = 16;
this.cameraBlacklist = [];
}
/**
* Private _width - use the width getter/setter instead
*/
private _width: number;
/**
* Private _height - use the height getter/setter instead
*/
private _height: number;
/**
* Reference to Phaser.Game
@@ -43,9 +51,9 @@ module Phaser.Components {
public game: Game;
/**
* Reference to the parent Sprite
* Reference to the parent object (Sprite, Group, etc)
*/
private _sprite: Sprite;
public parent;
/**
* Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
@@ -65,11 +73,40 @@ module Phaser.Components {
public loaded: bool = false;
/**
* Opacity of the Sprite texture where 1 is opaque and 0 is fully transparent.
* An Array of Cameras to which this texture won't render
* @type {Array}
*/
public cameraBlacklist: number[];
/**
* Whether the Sprite background is opaque or not. If set to true the Sprite is filled with
* the value of Texture.backgroundColor every frame. Normally you wouldn't enable this but
* for some effects it can be handy.
* @type {boolean}
*/
public opaque: bool = false;
/**
* Opacity of the Sprite texture where 1 is opaque (default) and 0 is fully transparent.
* @type {number}
*/
public alpha: number;
/**
* The Background Color of the Sprite if Texture.opaque is set to true.
* Given in css color string format, i.e. 'rgb(0,0,0)' or '#ff0000'.
* @type {string}
*/
public backgroundColor: string = 'rgb(255,255,255)';
/**
* You can set a globalCompositeOperation that will be applied before the render method is called on this Sprite.
* This is useful if you wish to apply an effect like 'lighten'.
* If this value is set it will call a canvas context save and restore before and after the render pass, so use it sparingly.
* Set to null to disable.
*/
public globalCompositeOperation: string = null;
/**
* A reference to the Canvas this Sprite renders to.
* @type {HTMLCanvasElement}
@@ -121,7 +158,7 @@ module Phaser.Components {
* Updates the texture being used to render the Sprite.
* Called automatically by SpriteUtils.loadTexture and SpriteUtils.loadDynamicTexture.
*/
public setTo(image = null, dynamic?: DynamicTexture = null): Sprite {
public setTo(image = null, dynamic?: DynamicTexture = null) {
if (dynamic)
{
@@ -134,11 +171,13 @@ module Phaser.Components {
this.isDynamic = false;
this.imageTexture = image;
this.texture = this.imageTexture;
this._width = image.width;
this._height = image.height;
}
this.loaded = true;
return this._sprite;
return this.parent;
}
@@ -147,32 +186,31 @@ module Phaser.Components {
* The graphic can be SpriteSheet or Texture Atlas. If you need to use a DynamicTexture see loadDynamicTexture.
* @param key {string} Key of the graphic you want to load for this sprite.
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
* @param updateBody {boolean} Update the physics body dimensions to match the newly loaded texture/frame?
*/
public loadImage(key: string, clearAnimations?: bool = true, updateBody?: bool = true) {
if (clearAnimations && this._sprite.animations.frameData !== null)
if (clearAnimations && this.parent['animations'] && this.parent['animations'].frameData !== null)
{
this._sprite.animations.destroy();
this.parent.animations.destroy();
}
if (this.game.cache.getImage(key) !== null)
{
this.setTo(this.game.cache.getImage(key), null);
this.cacheKey = key;
if (this.game.cache.isSpriteSheet(key))
if (this.game.cache.isSpriteSheet(key) && this.parent['animations'])
{
this._sprite.animations.loadFrameData(this._sprite.game.cache.getFrameData(key));
this.parent.animations.loadFrameData(this.parent.game.cache.getFrameData(key));
}
else
{
this._sprite.frameBounds.width = this.width;
this._sprite.frameBounds.height = this.height;
}
if (updateBody)
{
this._sprite.body.bounds.width = this.width;
this._sprite.body.bounds.height = this.height;
if (updateBody && this.parent['body'])
{
this.parent.body.bounds.width = this.width;
this.parent.body.bounds.height = this.height;
}
}
}
@@ -184,19 +222,28 @@ module Phaser.Components {
*/
public loadDynamicTexture(texture: DynamicTexture) {
if (this._sprite.animations.frameData !== null)
if (this.parent.animations.frameData !== null)
{
this._sprite.animations.destroy();
this.parent.animations.destroy();
}
this.setTo(null, texture);
this._sprite.frameBounds.width = this.width;
this._sprite.frameBounds.height = this.height;
this.parent.texture.width = this.width;
this.parent.texture.height = this.height;
}
public set width(value: number) {
this._width = value;
}
public set height(value: number) {
this._height = value;
}
/**
* Getter only. The width of the texture.
* The width of the texture. If an animation it will be the frame width, not the width of the sprite sheet.
* If using a DynamicTexture it will be the width of the dynamic texture itself.
* @type {number}
*/
public get width(): number {
@@ -207,12 +254,13 @@ module Phaser.Components {
}
else
{
return this.imageTexture.width;
return this._width;
}
}
/**
* Getter only. The height of the texture.
* The height of the texture. If an animation it will be the frame height, not the height of the sprite sheet.
* If using a DynamicTexture it will be the height of the dynamic texture itself.
* @type {number}
*/
public get height(): number {
@@ -223,7 +271,7 @@ module Phaser.Components {
}
else
{
return this.imageTexture.height;
return this._height;
}
}
+4 -4
View File
@@ -219,10 +219,10 @@ module Phaser {
* Swap tiles with 2 kinds of indexes.
* @param tileA {number} First tile index.
* @param tileB {number} Second tile index.
* @param [x] {number} specify a rectangle of tiles to operate. The x position in tiles of rectangle's left-top corner.
* @param [y] {number} specify a rectangle of tiles to operate. The y position in tiles of rectangle's left-top corner.
* @param [width] {number} specify a rectangle of tiles to operate. The width in tiles.
* @param [height] {number} specify a rectangle of tiles to operate. The height in tiles.
* @param [x] {number} specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
* @param [y] {number} specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
* @param [width] {number} specify a Rectangle of tiles to operate. The width in tiles.
* @param [height] {number} specify a Rectangle of tiles to operate. The height in tiles.
*/
public swapTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
+331
View File
@@ -0,0 +1,331 @@
/// <reference path="../Game.ts" />
/// <reference path="../math/Mat3.ts" />
/**
* Phaser - Components - Transform
*/
module Phaser.Components {
export class Transform {
/**
* Creates a new Transform component
* @param parent The game object using this transform
*/
constructor(parent) {
this.game = parent.game;
this.parent = parent;
this.local = new Mat3;
this.scrollFactor = new Phaser.Vec2(1, 1);
this.origin = new Phaser.Vec2;
this.scale = new Phaser.Vec2(1, 1);
this.skew = new Phaser.Vec2;
this.center = new Phaser.Point;
this.upperLeft = new Phaser.Point;
this.upperRight = new Phaser.Point;
this.bottomLeft = new Phaser.Point;
this.bottomRight = new Phaser.Point;
this._pos = new Phaser.Point;
this._scale = new Phaser.Point;
this._size = new Phaser.Point;
this._halfSize = new Phaser.Point;
this._offset = new Phaser.Point;
this._origin = new Phaser.Point;
this._sc = new Phaser.Point;
this._scA = new Phaser.Point;
}
private _rotation: number;
// Cache vars
private _pos: Phaser.Point;
private _scale: Phaser.Point;
private _size: Phaser.Point;
private _halfSize: Phaser.Point;
private _offset: Phaser.Point;
private _origin: Phaser.Point;
private _sc: Phaser.Point;
private _scA: Phaser.Point;
private _angle: number;
private _distance: number;
private _prevRotation: number;
/**
* The center of the Sprite in world coordinates, after taking scaling and rotation into consideration
*/
public center: Phaser.Point;
/**
* The upper-left corner of the Sprite in world coordinates, after taking scaling and rotation into consideration
*/
public upperLeft: Phaser.Point;
/**
* The upper-right corner of the Sprite in world coordinates, after taking scaling and rotation into consideration
*/
public upperRight: Phaser.Point;
/**
* The bottom-left corner of the Sprite in world coordinates, after taking scaling and rotation into consideration
*/
public bottomLeft: Phaser.Point;
/**
* The bottom-right corner of the Sprite in world coordinates, after taking scaling and rotation into consideration
*/
public bottomRight: Phaser.Point;
/**
* The local transform matrix
*/
public local: Mat3;
/**
* Populates the transform cache. Called by the parent object on creation.
*/
public setCache() {
this._pos.x = this.parent.x;
this._pos.y = this.parent.y;
this._halfSize.x = this.parent.width / 2;
this._halfSize.y = this.parent.height / 2;
this._offset.x = this.origin.x * this.parent.width;
this._offset.y = this.origin.y * this.parent.height;
this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
this._size.x = this.parent.width;
this._size.y = this.parent.height;
this._origin.x = this.origin.x;
this._origin.y = this.origin.y;
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
this._scA.y = Math.cos((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD + this._angle);
this._scA.x = Math.sin((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD + this._angle);
this._prevRotation = this.rotation;
if (this.parent.texture && this.parent.texture.renderRotation)
{
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
}
else
{
this._sc.x = 0;
this._sc.y = 1;
}
this.center.x = this.parent.x + this._distance * this._scA.y;
this.center.y = this.parent.y + this._distance * this._scA.x;
this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
this._pos.x = this.parent.x;
this._pos.y = this.parent.y;
}
/**
* Updates the local transform matrix and the cache values if anything has changed in the parent.
*/
public update() {
// Check cache
var dirty: bool = false;
// 1) Height or Width change (also triggered by a change in scale) or an Origin change
if (this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x|| this.origin.y !== this._origin.y)
{
this._halfSize.x = this.parent.width / 2;
this._halfSize.y = this.parent.height / 2;
this._offset.x = this.origin.x * this.parent.width;
this._offset.y = this.origin.y * this.parent.height;
this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
// Store
this._size.x = this.parent.width;
this._size.y = this.parent.height;
this._origin.x = this.origin.x;
this._origin.y = this.origin.y;
dirty = true;
}
// 2) Rotation change
if (this.rotation != this._prevRotation)
{
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
this._scA.y = Math.cos((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD + this._angle);
this._scA.x = Math.sin((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD + this._angle);
if (this.parent.texture.renderRotation)
{
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * GameMath.DEG_TO_RAD);
}
else
{
this._sc.x = 0;
this._sc.y = 1;
}
// Store
this._prevRotation = this.rotation;
dirty = true;
}
// If it has moved, updated the edges and center
if (dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y)
{
this.center.x = this.parent.x + this._distance * this._scA.y;
this.center.y = this.parent.y + this._distance * this._scA.x;
this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
this._pos.x = this.parent.x;
this._pos.y = this.parent.y;
}
// Scale and Skew
if (this.parent.texture.flippedX)
{
this.local.data[0] = this._sc.y * -this.scale.x;
this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
}
else
{
this.local.data[0] = this._sc.y * this.scale.x;
this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
}
if (this.parent.texture.flippedY)
{
this.local.data[4] = this._sc.y * -this.scale.y;
this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
}
else
{
this.local.data[4] = this._sc.y * this.scale.y;
this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
}
// Translate
this.local.data[2] = this.parent.x;
this.local.data[5] = this.parent.y;
}
/**
* Reference to Phaser.Game
*/
public game: Game;
/**
* Reference to the parent object (Sprite, Group, etc)
*/
public parent: Phaser.Sprite;
/**
* Scale of the object. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
*/
public scale: Phaser.Vec2;
/**
* Skew the object along the x and y axis. A skew value of 0 is no skew.
*/
public skew: Phaser.Vec2;
/**
* The influence of camera movement upon the object, if supported.
*/
public scrollFactor: Phaser.Vec2;
/**
* The origin is the point around which scale and rotation takes place and defaults to the top-left of the sprite.
*/
public origin: Phaser.Vec2;
/**
* This value is added to the rotation of the object.
* For example if you had a texture drawn facing straight up then you could set
* rotationOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
* @type {number}
*/
public rotationOffset: number = 0;
/**
* The rotation of the object in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
*/
public rotation: number = 0;
/**
* The distance from the center of the transform to the rotation origin.
*/
public get distance(): number {
return this._distance;
}
/**
* The angle between the center of the transform to the rotation origin.
*/
public get angleToCenter(): number {
return this._angle;
}
/**
* The offset on the X axis of the origin
*/
public get offsetX(): number {
return this._offset.x;
}
/**
* The offset on the Y axis of the origin
*/
public get offsetY(): number {
return this._offset.y;
}
/**
* Half the width of the parent sprite, taking into consideration scaling
*/
public get halfWidth(): number {
return this._halfSize.x;
}
/**
* Half the height of the parent sprite, taking into consideration scaling
*/
public get halfHeight(): number {
return this._halfSize.y;
}
/**
* The equivalent of Math.sin(rotation + rotationOffset)
*/
public get sin(): number {
return this._sc.x;
}
/**
* The equivalent of Math.cos(rotation + rotationOffset)
*/
public get cos(): number {
return this._sc.y;
}
}
}
+2 -2
View File
@@ -140,8 +140,8 @@ module Phaser {
if (this.currentFrame !== null)
{
this._parent.frameBounds.width = this.currentFrame.width;
this._parent.frameBounds.height = this.currentFrame.height;
this._parent.texture.width = this.currentFrame.width;
this._parent.texture.height = this.currentFrame.height;
this._frameIndex = value;
}
+24 -10
View File
@@ -22,7 +22,7 @@ module Phaser.Components {
*
* @param parent {Sprite} Owner sprite of this manager.
*/
constructor(parent: Sprite) {
constructor(parent: Phaser.Sprite) {
this._parent = parent;
this._game = parent.game;
@@ -38,7 +38,7 @@ module Phaser.Components {
/**
* Local private reference to its owner sprite.
*/
private _parent: Sprite;
private _parent: Phaser.Sprite;
/**
* Animation key-value container.
@@ -57,6 +57,14 @@ module Phaser.Components {
*/
private _frameData: FrameData = null;
/**
* When an animation frame changes you can choose to automatically update the physics bounds of the parent Sprite
* to the width and height of the new frame. If you've set a specific physics bounds that you don't want changed during
* animation then set this to false, otherwise leave it set to true.
* @type {boolean}
*/
public autoUpdateBounds: bool = true;
/**
* Keeps track of the current animation being played.
*/
@@ -200,8 +208,8 @@ module Phaser.Components {
if (this.currentAnim && this.currentAnim.update() == true)
{
this.currentFrame = this.currentAnim.currentFrame;
this._parent.frameBounds.width = this.currentFrame.width;
this._parent.frameBounds.height = this.currentFrame.height;
this._parent.texture.width = this.currentFrame.width;
this._parent.texture.height = this.currentFrame.height;
}
}
@@ -232,8 +240,15 @@ module Phaser.Components {
{
this.currentFrame = this._frameData.getFrame(value);
this._parent.frameBounds.width = this.currentFrame.width;
this._parent.frameBounds.height = this.currentFrame.height;
this._parent.texture.width = this.currentFrame.width;
this._parent.texture.height = this.currentFrame.height;
if (this.autoUpdateBounds && this._parent['body'])
{
this._parent.body.bounds.width = this.currentFrame.width;
this._parent.body.bounds.height = this.currentFrame.height;
}
this._frameIndex = value;
}
@@ -249,10 +264,9 @@ module Phaser.Components {
{
this.currentFrame = this._frameData.getFrameByName(value);
this._parent.frameBounds.width = this.currentFrame.width;
this._parent.frameBounds.height = this.currentFrame.height;
//this._parent.frameBounds.width = this.currentFrame.sourceSizeW;
//this._parent.frameBounds.height = this.currentFrame.sourceSizeH;
this._parent.texture.width = this.currentFrame.width;
this._parent.texture.height = this.currentFrame.height;
this._frameIndex = this.currentFrame.index;
}
+13 -6
View File
@@ -143,14 +143,21 @@ module Phaser {
*/
public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number) {
//console.log('setTrim', trimmed, 'aw', actualWidth, 'ah', actualHeight, 'dx', destX, 'dy', destY, 'dw', destWidth, 'dh', destHeight);
this.trimmed = trimmed;
this.sourceSizeW = actualWidth;
this.sourceSizeH = actualHeight;
this.spriteSourceSizeX = destX;
this.spriteSourceSizeY = destY;
this.spriteSourceSizeW = destWidth;
this.spriteSourceSizeH = destHeight;
if (trimmed)
{
this.width = actualWidth;
this.height = actualHeight;
this.sourceSizeW = actualWidth;
this.sourceSizeH = actualHeight;
this.spriteSourceSizeX = destX;
this.spriteSourceSizeY = destY;
this.spriteSourceSizeW = destWidth;
this.spriteSourceSizeH = destHeight;
}
}
+4 -4
View File
@@ -6,7 +6,7 @@
* Signals that are dispatched by the Sprite and its various components
*/
module Phaser.Components {
module Phaser.Components.Sprite {
export class Events {
@@ -14,10 +14,10 @@ module Phaser.Components {
* The Events component is a collection of events fired by the parent Sprite and its other components.
* @param parent The Sprite using this Input component
*/
constructor(parent: Sprite) {
constructor(parent: Phaser.Sprite) {
this.game = parent.game;
this._sprite = parent;
this.sprite = parent;
this.onAddedToGroup = new Phaser.Signal;
this.onRemovedFromGroup = new Phaser.Signal;
@@ -39,7 +39,7 @@ module Phaser.Components {
/**
* Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
*/
private _sprite: Sprite;
private sprite: Phaser.Sprite;
/**
* Dispatched by the Group this Sprite is added to.
+86 -53
View File
@@ -9,7 +9,7 @@
* Input detection component
*/
module Phaser.Components {
module Phaser.Components.Sprite {
export class Input {
@@ -17,10 +17,10 @@ module Phaser.Components {
* Sprite Input component constructor
* @param parent The Sprite using this Input component
*/
constructor(parent: Sprite) {
constructor(parent: Phaser.Sprite) {
this.game = parent.game;
this._sprite = parent;
this.sprite = parent;
this.enabled = false;
}
@@ -33,7 +33,7 @@ module Phaser.Components {
/**
* Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
*/
private _sprite: Sprite;
private sprite: Phaser.Sprite;
private _pointerData;
@@ -48,6 +48,11 @@ module Phaser.Components {
*/
public priorityID:number = 0;
/**
* The index of this Input component entry in the Game.Input manager.
*/
public indexID:number = 0;
private _dragPoint: Point;
private _draggedPointerID: number;
public dragOffset: Point;
@@ -58,6 +63,7 @@ module Phaser.Components {
public allowHorizontalDrag: bool = true;
public allowVerticalDrag: bool = true;
public bringToTop: bool = false;
public snapOnDrag: bool = false;
public snapOnRelease: bool = false;
@@ -82,7 +88,7 @@ module Phaser.Components {
* An Sprite the bounds of which this sprite is restricted during drag
* @default null
*/
public boundsSprite: Sprite = null;
public boundsSprite: Phaser.Sprite = null;
/**
* The Input component can monitor either the physics body of the Sprite or the frameBounds
@@ -196,7 +202,7 @@ module Phaser.Components {
return this._pointerData[pointer].isDragged;
}
public start(priority:number = 0, checkBody?:bool = false, useHandCursor?:bool = false): Sprite {
public start(priority:number = 0, checkBody?:bool = false, useHandCursor?:bool = false): Phaser.Sprite {
// Turning on
if (this.enabled == false)
@@ -216,10 +222,10 @@ module Phaser.Components {
this.snapOffset = new Point;
this.enabled = true;
this.game.input.addGameObject(this._sprite);
this.game.input.addGameObject(this.sprite);
}
return this._sprite;
return this.sprite;
}
@@ -245,20 +251,35 @@ module Phaser.Components {
{
// De-register, etc
this.enabled = false;
this.game.input.removeGameObject(this._sprite);
this.game.input.removeGameObject(this.indexID);
}
}
/**
* Clean up memory.
*/
public destroy() {
if (this.enabled)
{
this.game.input.removeGameObject(this.indexID);
}
}
/**
* Checks if the given pointer is over this Sprite. All checks are done in world coordinates.
*/
public checkPointerOver(pointer: Phaser.Pointer): bool {
if (this.enabled == false || this._sprite.visible == false)
if (this.enabled == false || this.sprite.visible == false)
{
return false;
}
else
{
return RectangleUtils.contains(this._sprite.frameBounds, pointer.scaledX, pointer.scaledY);
return SpriteUtils.overlapsXY(this.sprite, pointer.worldX(), pointer.worldY());
}
}
@@ -268,7 +289,7 @@ module Phaser.Components {
*/
public update(pointer: Phaser.Pointer): bool {
if (this.enabled == false || this._sprite.visible == false)
if (this.enabled == false || this.sprite.visible == false)
{
return false;
}
@@ -279,10 +300,10 @@ module Phaser.Components {
}
else if (this._pointerData[pointer.id].isOver == true)
{
if (RectangleUtils.contains(this._sprite.frameBounds, pointer.scaledX, pointer.scaledY))
if (SpriteUtils.overlapsXY(this.sprite, pointer.worldX(), pointer.worldY()))
{
this._pointerData[pointer.id].x = pointer.scaledX - this._sprite.x;
this._pointerData[pointer.id].y = pointer.scaledY - this._sprite.y;
this._pointerData[pointer.id].x = pointer.x - this.sprite.x;
this._pointerData[pointer.id].y = pointer.y - this.sprite.y;
return true;
}
else
@@ -303,15 +324,15 @@ module Phaser.Components {
this._pointerData[pointer.id].isOver = true;
this._pointerData[pointer.id].isOut = false;
this._pointerData[pointer.id].timeOver = this.game.time.now;
this._pointerData[pointer.id].x = pointer.x - this._sprite.x;
this._pointerData[pointer.id].y = pointer.y - this._sprite.y;
this._pointerData[pointer.id].x = pointer.x - this.sprite.x;
this._pointerData[pointer.id].y = pointer.y - this.sprite.y;
if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false)
{
this.game.stage.canvas.style.cursor = "pointer";
}
this._sprite.events.onInputOver.dispatch(this._sprite, pointer);
this.sprite.events.onInputOver.dispatch(this.sprite, pointer);
}
}
@@ -327,7 +348,7 @@ module Phaser.Components {
this.game.stage.canvas.style.cursor = "default";
}
this._sprite.events.onInputOut.dispatch(this._sprite, pointer);
this.sprite.events.onInputOut.dispatch(this.sprite, pointer);
}
@@ -341,7 +362,7 @@ module Phaser.Components {
this._pointerData[pointer.id].isUp = false;
this._pointerData[pointer.id].timeDown = this.game.time.now;
this._sprite.events.onInputDown.dispatch(this._sprite, pointer);
this.sprite.events.onInputDown.dispatch(this.sprite, pointer);
// Start drag
//if (this.draggable && this.isDragged == false && pointer.targetObject == null)
@@ -350,6 +371,11 @@ module Phaser.Components {
this.startDrag(pointer);
}
if (this.bringToTop)
{
this.sprite.group.bringToTop(this.sprite);
}
}
// Consume the event?
@@ -367,7 +393,7 @@ module Phaser.Components {
this._pointerData[pointer.id].timeUp = this.game.time.now;
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
this._sprite.events.onInputUp.dispatch(this._sprite, pointer);
this.sprite.events.onInputUp.dispatch(this.sprite, pointer);
// Stop drag
if (this.draggable && this.isDragged && this._draggedPointerID == pointer.id)
@@ -396,12 +422,12 @@ module Phaser.Components {
if (this.allowHorizontalDrag)
{
this._sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
this.sprite.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
}
if (this.allowVerticalDrag)
{
this._sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
this.sprite.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
}
if (this.boundsRect)
@@ -416,8 +442,8 @@ module Phaser.Components {
if (this.snapOnDrag)
{
this._sprite.x = Math.floor(this._sprite.x / this.snapX) * this.snapX;
this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY;
this.sprite.x = Math.floor(this.sprite.x / this.snapX) * this.snapX;
this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY;
}
return true;
@@ -493,16 +519,18 @@ module Phaser.Components {
* Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
*
* @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
* @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group.
* @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
* @param alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255)
* @param boundsRect If you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere
* @param boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here
*/
public enableDrag(lockCenter:bool = false, pixelPerfect:bool = false, alphaThreshold:number = 255, boundsRect:Rectangle = null, boundsSprite:Sprite = null):void
public enableDrag(lockCenter:bool = false, bringToTop:bool = false, pixelPerfect:bool = false, alphaThreshold:number = 255, boundsRect:Rectangle = null, boundsSprite:Phaser.Sprite = null):void
{
this._dragPoint = new Point;
this.draggable = true;
this.bringToTop = bringToTop;
this.dragOffset = new Point;
this.dragFromCenter = lockCenter;
@@ -550,15 +578,20 @@ module Phaser.Components {
if (this.dragFromCenter)
{
// Move the sprite to the middle of the pointer
this._dragPoint.setTo(-this._sprite.frameBounds.halfWidth, -this._sprite.frameBounds.halfHeight);
this._dragPoint.setTo(-this.sprite.worldView.halfWidth, -this.sprite.worldView.halfHeight);
}
else
{
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y);
}
this.updateDrag(pointer);
if (this.bringToTop)
{
this.sprite.group.bringToTop(this.sprite);
}
}
/**
@@ -572,8 +605,8 @@ module Phaser.Components {
if (this.snapOnRelease)
{
this._sprite.x = Math.floor(this._sprite.x / this.snapX) * this.snapX;
this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY;
this.sprite.x = Math.floor(this.sprite.x / this.snapX) * this.snapX;
this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY;
}
//pointer.draggedObject = null;
@@ -622,22 +655,22 @@ module Phaser.Components {
*/
private checkBoundsRect():void
{
if (this._sprite.x < this.boundsRect.left)
if (this.sprite.x < this.boundsRect.left)
{
this._sprite.x = this.boundsRect.x;
this.sprite.x = this.boundsRect.x;
}
else if ((this._sprite.x + this._sprite.width) > this.boundsRect.right)
else if ((this.sprite.x + this.sprite.width) > this.boundsRect.right)
{
this._sprite.x = this.boundsRect.right - this._sprite.width;
this.sprite.x = this.boundsRect.right - this.sprite.width;
}
if (this._sprite.y < this.boundsRect.top)
if (this.sprite.y < this.boundsRect.top)
{
this._sprite.y = this.boundsRect.top;
this.sprite.y = this.boundsRect.top;
}
else if ((this._sprite.y + this._sprite.height) > this.boundsRect.bottom)
else if ((this.sprite.y + this.sprite.height) > this.boundsRect.bottom)
{
this._sprite.y = this.boundsRect.bottom - this._sprite.height;
this.sprite.y = this.boundsRect.bottom - this.sprite.height;
}
}
@@ -646,22 +679,22 @@ module Phaser.Components {
*/
private checkBoundsSprite():void
{
if (this._sprite.x < this.boundsSprite.x)
if (this.sprite.x < this.boundsSprite.x)
{
this._sprite.x = this.boundsSprite.x;
this.sprite.x = this.boundsSprite.x;
}
else if ((this._sprite.x + this._sprite.width) > (this.boundsSprite.x + this.boundsSprite.width))
else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width))
{
this._sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this._sprite.width;
this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width;
}
if (this._sprite.y < this.boundsSprite.y)
if (this.sprite.y < this.boundsSprite.y)
{
this._sprite.y = this.boundsSprite.y;
this.sprite.y = this.boundsSprite.y;
}
else if ((this._sprite.y + this._sprite.height) > (this.boundsSprite.y + this.boundsSprite.height))
else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height))
{
this._sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this._sprite.height;
this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height;
}
}
@@ -673,13 +706,13 @@ module Phaser.Components {
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._sprite.texture.context.font = '14px Courier';
this._sprite.texture.context.fillStyle = color;
this._sprite.texture.context.fillText('Sprite Input: (' + this._sprite.frameBounds.width + ' x ' + this._sprite.frameBounds.height + ')', x, y);
this._sprite.texture.context.fillText('x: ' + this.pointerX().toFixed(1) + ' y: ' + this.pointerY().toFixed(1), x, y + 14);
this._sprite.texture.context.fillText('over: ' + this.pointerOver() + ' duration: ' + this.overDuration().toFixed(0), x, y + 28);
this._sprite.texture.context.fillText('down: ' + this.pointerDown() + ' duration: ' + this.downDuration().toFixed(0), x, y + 42);
this._sprite.texture.context.fillText('just over: ' + this.justOver() + ' just out: ' + this.justOut(), x, y + 56);
this.sprite.texture.context.font = '14px Courier';
this.sprite.texture.context.fillStyle = color;
this.sprite.texture.context.fillText('Sprite Input: (' + this.sprite.worldView.width + ' x ' + this.sprite.worldView.height + ')', x, y);
this.sprite.texture.context.fillText('x: ' + this.pointerX().toFixed(1) + ' y: ' + this.pointerY().toFixed(1), x, y + 14);
this.sprite.texture.context.fillText('over: ' + this.pointerOver() + ' duration: ' + this.overDuration().toFixed(0), x, y + 28);
this.sprite.texture.context.fillText('down: ' + this.pointerDown() + ' duration: ' + this.downDuration().toFixed(0), x, y + 42);
this.sprite.texture.context.fillText('just over: ' + this.justOver() + ' just out: ' + this.justOut(), x, y + 56);
}
+103 -67
View File
@@ -1,5 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../Statics.ts" />
/// <reference path="../components/Texture.ts" />
/// <reference path="../components/Transform.ts" />
/**
* Phaser - Group
@@ -25,10 +27,12 @@ module Phaser {
this._marker = 0;
this._sortIndex = null;
this.cameraBlacklist = [];
this.ID = this.game.world.getNextGroupID();
this.transform = new Phaser.Components.Transform(this);
this.texture = new Phaser.Components.Texture(this);
this.texture.opaque = false;
}
/**
@@ -91,6 +95,21 @@ module Phaser {
*/
public group: Group = null;
/**
* Optional texture used in the background of the Camera.
*/
public texture: Phaser.Components.Texture;
/**
* The transform component.
*/
public transform: Phaser.Components.Transform;
/**
* A boolean representing if the Group has been modified in any way via a scale, rotate, flip or skew.
*/
public modified: bool = false;
/**
* If this Group exists or not. Can be set to false to skip certain loop checks.
*/
@@ -123,27 +142,6 @@ module Phaser {
*/
public length: number;
/**
* You can set a globalCompositeOperation that will be applied before the render method is called on this Groups children.
* This is useful if you wish to apply an effect like 'lighten' to a whole group of children as it saves doing it one-by-one.
* If this value is set it will call a canvas context save and restore before and after the render pass.
* Set to null to disable.
*/
public globalCompositeOperation: string = null;
/**
* You can set an alpha value on this Group that will be applied before the render method is called on this Groups children.
* This is useful if you wish to alpha a whole group of children as it saves doing it one-by-one.
* Set to 0 to disable.
*/
public alpha: number = 0;
/**
* An Array of Cameras to which this Group, or any of its children, won't render
* @type {Array}
*/
public cameraBlacklist: number[];
/**
* Gets the next z index value for children of this Group
*/
@@ -184,6 +182,11 @@ module Phaser {
*/
public update() {
if (this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
{
this.modified = true;
}
this._i = 0;
while (this._i < this.length)
@@ -194,6 +197,29 @@ module Phaser {
{
this._member.preUpdate();
this._member.update();
}
}
}
/**
* Calls update on all members of this Group who have a status of active=true and exists=true
* You can also call Object.postUpdate directly, which will bypass the active/exists check.
*/
public postUpdate() {
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
{
this.modified = false;
}
this._i = 0;
while (this._i < this.length)
{
this._member = this.members[this._i++];
if (this._member != null && this._member.exists && this._member.active)
{
this._member.postUpdate();
}
}
@@ -210,17 +236,7 @@ module Phaser {
return;
}
if (this.globalCompositeOperation)
{
this.game.stage.context.save();
this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
}
if (this.alpha > 0)
{
this._prevAlpha = this.game.stage.context.globalAlpha;
this.game.stage.context.globalAlpha = this.alpha;
}
this.game.renderer.preRenderGroup(camera, this);
this._i = 0;
@@ -241,15 +257,7 @@ module Phaser {
}
}
if (this.alpha > 0)
{
this.game.stage.context.globalAlpha = this._prevAlpha;
}
if (this.globalCompositeOperation)
{
this.game.stage.context.restore();
}
this.game.renderer.postRenderGroup(camera, this);
}
@@ -259,17 +267,7 @@ module Phaser {
*/
public directRender(camera: Camera) {
if (this.globalCompositeOperation)
{
this.game.stage.context.save();
this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
}
if (this.alpha > 0)
{
this._prevAlpha = this.game.stage.context.globalAlpha;
this.game.stage.context.globalAlpha = this.alpha;
}
this.game.renderer.preRenderGroup(camera, this);
this._i = 0;
@@ -290,15 +288,7 @@ module Phaser {
}
}
if (this.alpha > 0)
{
this.game.stage.context.globalAlpha = this._prevAlpha;
}
if (this.globalCompositeOperation)
{
this.game.stage.context.restore();
}
this.game.renderer.postRenderGroup(camera, this);
}
@@ -426,11 +416,12 @@ module Phaser {
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
* @returns {Sprite} The newly created sprite object.
*/
public addNewSprite(x: number, y: number, key?: string = '', bodyType?: number = Phaser.Types.BODY_DISABLED): Sprite {
return <Sprite> this.add(new Sprite(this.game, x, y, key, bodyType));
public addNewSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC): Sprite {
return <Sprite> this.add(new Sprite(this.game, x, y, key, frame, bodyType));
}
/**
@@ -592,6 +583,14 @@ module Phaser {
}
/**
* Swaps two existing game object in this Group with each other.
*
* @param {Basic} child1 The first object to swap.
* @param {Basic} child2 The second object to swap.
*
* @return {Basic} True if the two objects successfully swapped position.
*/
public swap(child1, child2, sort?: bool = true): bool {
if (child1.group.ID != this.ID || child2.group.ID != this.ID || child1 === child2)
@@ -613,6 +612,43 @@ module Phaser {
}
public bringToTop(child): bool {
// If child not in this group, or is already at the top of the group, return false
if (child.group.ID != this.ID || child.z == this._zCounter)
{
return false;
}
this.sort();
// What's the z index of the top most child?
var tempZ: number = child.z;
var childIndex: number = this._zCounter;
this._i = 0;
while (this._i < this.length)
{
this._member = this.members[this._i++];
if (this._i > childIndex)
{
this._member.z--;
}
else if (this._member.z == child.z)
{
childIndex = this._i;
this._member.z = this._zCounter;
}
}
this.sort();
return true;
}
/**
* Call this function to sort the group according to a particular value and order.
* For example, to sort game objects for Zelda-style overlaps you might call
@@ -620,7 +656,7 @@ module Phaser {
* <code>State.update()</code> override. To sort all existing objects after
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
*
* @param {string} index The <code>string</code> name of the member variable you want to sort on. Default value is "y".
* @param {string} index The <code>string</code> name of the member variable you want to sort on. Default value is "z".
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
*/
public sort(index: string = 'z', order: number = Group.ASCENDING) {
-54
View File
@@ -1,54 +0,0 @@
/// <reference path="../Game.ts" />
/**
* Phaser - Polygon
*
*
*/
module Phaser {
export class Polygon {
/**
*
**/
constructor(game: Game, points: Point[]) {
this.game = game;
this.context = game.stage.context;
this.points = [];
for (var i = 0; i < points.length; i++)
{
this.points.push(new Point().copyFrom(points[i]));
}
}
public points: Point[];
public game: Game;
public context: CanvasRenderingContext2D;
public render() {
this.context.beginPath();
this.context.strokeStyle = 'rgb(255,255,0)';
this.context.moveTo(this.points[0].x, this.points[0].y);
for (var i = 1; i < this.points.length; i++)
{
this.context.lineTo(this.points[i].x, this.points[i].y);
}
this.context.lineTo(this.points[0].x, this.points[0].y);
this.context.stroke();
this.context.closePath();
}
}
}
+7 -7
View File
@@ -110,8 +110,8 @@ module Phaser {
}
/**
* Get pixels in array in a specific rectangle.
* @param rect {Rectangle} The specific rectangle.
* Get pixels in array in a specific Rectangle.
* @param rect {Rectangle} The specific Rectangle.
* @returns {array} CanvasPixelArray.
*/
public getPixels(rect: Rectangle) {
@@ -147,8 +147,8 @@ module Phaser {
}
/**
* Set image data to a specific rectangle.
* @param rect {Rectangle} Target rectangle.
* Set image data to a specific Rectangle.
* @param rect {Rectangle} Target Rectangle.
* @param input {object} Source image data.
*/
public setPixels(rect: Rectangle, input) {
@@ -158,8 +158,8 @@ module Phaser {
}
/**
* Fill a given rectangle with specific color.
* @param rect {Rectangle} Target rectangle you want to fill.
* Fill a given Rectangle with specific color.
* @param rect {Rectangle} Target Rectangle you want to fill.
* @param color {number} A native number with color value. (format: 0xRRGGBB)
*/
public fillRect(rect: Rectangle, color: number) {
@@ -231,7 +231,7 @@ module Phaser {
/**
* Copy pixel from another DynamicTexture to this texture.
* @param sourceTexture {DynamicTexture} Source texture object.
* @param sourceRect {Rectangle} The specific region rectangle to be copied to this in the source.
* @param sourceRect {Rectangle} The specific region Rectangle to be copied to this in the source.
* @param destPoint {Point} Top-left point the target image data will be paste at.
*/
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
+2 -2
View File
@@ -250,7 +250,7 @@ module Phaser {
particle.exists = false;
// Center the origin for rotation assistance
particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
this.add(particle);
@@ -398,7 +398,7 @@ module Phaser {
if (particle.body.angularVelocity != 0)
{
particle.angle = this.game.math.random() * 360 - 180;
particle.rotation = this.game.math.random() * 360 - 180;
}
particle.body.drag.x = this.particleDrag.x;
+3 -2
View File
@@ -68,11 +68,12 @@ module Phaser {
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
* @returns {Sprite} The newly created sprite object.
*/
public sprite(x: number, y: number, key?: string = '', bodyType?: number = Phaser.Types.BODY_DISABLED): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, bodyType));
public sprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType));
}
/**
+5 -10
View File
@@ -30,7 +30,7 @@ module Phaser {
y: number;
/**
* Z-order value of the object.
* z-index value of the object.
*/
z: number;
@@ -45,24 +45,19 @@ module Phaser {
active: bool;
/**
* Controls if this Sprite is rendered or skipped during the core game loop.
* Controls if this is rendered or skipped during the core game loop.
*/
visible: bool;
/**
* The texture used to render the Sprite.
* The texture used to render.
*/
texture: Phaser.Components.Texture;
/**
* Scale of the Sprite. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
* The transform component.
*/
scale: Phaser.Vec2;
/**
* The influence of camera movement upon the Sprite.
*/
scrollFactor: Phaser.Vec2;
transform: Phaser.Components.Transform;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../components/ScrollRegion.ts" />
/**
+93 -86
View File
@@ -1,15 +1,15 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Vec2.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../components/animation/AnimationManager.ts" />
/// <reference path="../components/sprite/Texture.ts" />
/// <reference path="../components/Texture.ts" />
/// <reference path="../components/Transform.ts" />
/// <reference path="../components/sprite/Input.ts" />
/// <reference path="../components/sprite/Events.ts" />
/// <reference path="../physics/Body.ts" />
/**
* Phaser - Sprite
*
*/
module Phaser {
@@ -23,9 +23,9 @@ module Phaser {
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
*/
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, bodyType?: number = Phaser.Types.BODY_DISABLED) {
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC) {
this.game = game;
this.type = Phaser.Types.SPRITE;
@@ -35,30 +35,49 @@ module Phaser {
this.visible = true;
this.alive = true;
// We give it a default size of 16x16 but when the texture loads (if given) it will reset this
this.frameBounds = new Rectangle(x, y, 16, 16);
this.scrollFactor = new Phaser.Vec2(1, 1);
this.x = x;
this.y = y;
this.z = -1;
this.group = null;
this.screen = new Point;
// If a texture has been given the body will be set to that size, otherwise 16x16
this.body = new Phaser.Physics.Body(this, bodyType);
this.animations = new Phaser.Components.AnimationManager(this);
this.texture = new Phaser.Components.Texture(this, key);
this.input = new Phaser.Components.Input(this);
this.events = new Phaser.Components.Events(this);
this.input = new Phaser.Components.Sprite.Input(this);
this.events = new Phaser.Components.Sprite.Events(this);
this.texture = new Phaser.Components.Texture(this);
this.transform = new Phaser.Components.Transform(this);
this.cameraBlacklist = [];
if (key !== null)
{
this.texture.loadImage(key, false);
}
else
{
this.texture.opaque = true;
}
if (frame !== null)
{
if (typeof frame == 'string')
{
this.frameName = frame;
}
else
{
this.frame = frame;
}
}
this.body = new Phaser.Physics.Body(this, bodyType);
this.worldView = new Rectangle(x, y, this.width, this.height);
this.cameraView = new Rectangle(x, y, this.width, this.height);
this.transform.setCache();
// Handy proxies
this.scale = this.transform.scale;
this.alpha = this.texture.alpha;
this.origin = this.transform.origin;
// 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);
}
/**
@@ -92,7 +111,7 @@ module Phaser {
public visible: bool;
/**
*
* A useful state for many game objects. Kill and revive both flip this switch.
*/
public alive: bool;
@@ -106,15 +125,20 @@ module Phaser {
*/
public texture: Phaser.Components.Texture;
/**
* The Sprite transform component.
*/
public transform: Phaser.Components.Transform;
/**
* The Input component
*/
public input: Phaser.Components.Input;
public input: Phaser.Components.Sprite.Input;
/**
* The Events component
*/
public events: Phaser.Components.Events;
public events: Phaser.Components.Sprite.Events;
/**
* This manages animations of the sprite. You can modify animations though it. (see AnimationManager)
@@ -123,50 +147,22 @@ module Phaser {
public animations: Phaser.Components.AnimationManager;
/**
* An Array of Cameras to which this GameObject won't render
* @type {Array}
* A Rectangle that defines the size and placement of the Sprite in the game world,
* after taking into consideration both scrollFactor and scaling.
*/
public cameraBlacklist: number[];
public worldView: Phaser.Rectangle;
/**
* The frame boundary around this Sprite.
* For non-animated sprites this matches the loaded texture dimensions.
* For animated sprites it will be updated as part of the animation loop, changing to the dimensions of the current animation frame.
* A Rectangle that maps to the placement of this sprite with respect to a specific Camera.
* This value is constantly updated and modified during the internal render pass, it is not meant to be accessed directly.
*/
public frameBounds: Phaser.Rectangle;
/**
* Scale of the Sprite. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
*/
public scale: Phaser.Vec2;
/**
* Skew the Sprite along the x and y axis. A skew value of 0 is no skew.
*/
public skew: Phaser.Vec2;
public cameraView: Phaser.Rectangle;
/**
* A boolean representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
*/
public modified: bool = false;
/**
* The influence of camera movement upon the Sprite.
*/
public scrollFactor: Phaser.Vec2;
/**
* The Sprite origin is the point around which scale and rotation takes place.
*/
public origin: Phaser.Vec2;
/**
* A Point holding the x/y coordinate of this Sprite relative to the screen. It uses the default created world
* camera to calculate its values. If you have changed the default camera (i.e. resized it, deleted it) this value
* will be incorrect and should be ignored.
*/
public screen: Point;
/**
* x value of the object.
*/
@@ -183,33 +179,42 @@ module Phaser {
public z: number = 0;
/**
* Render iteration
* Render iteration counter
*/
public renderOrderID: number = 0;
/**
* This value is added to the angle of the Sprite.
* For example if you had a sprite graphic drawn facing straight up then you could set
* angleOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
* @type {number}
*/
public angleOffset: number = 0;
/**
* The angle of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
*/
public get angle(): number {
return this.body.angle;
public get rotation(): number {
return this.transform.rotation;
}
/**
* Set the angle of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* Set the rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* The value is automatically wrapped to be between 0 and 360.
*/
public set angle(value: number) {
this.body.angle = this.game.math.wrap(value, 360, 0);
public set rotation(value: number) {
this.transform.rotation = this.game.math.wrap(value, 360, 0);
}
/**
* The scale of the Sprite. A value of 1 is original scale. 0.5 is half size. 2 is double the size.
* This is a reference to Sprite.transform.scale
*/
public scale: Phaser.Vec2;
/**
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
*/
public alpha: number;
/**
* The origin of the Sprite around which rotation and positioning takes place.
* This is a reference to Sprite.transform.origin
*/
public origin: Phaser.Vec2;
/**
* Set the animation frame by frame number.
*/
@@ -239,19 +244,19 @@ module Phaser {
}
public set width(value: number) {
this.frameBounds.width = value;
this.transform.scale.x = value / this.texture.width;
}
public get width(): number {
return this.frameBounds.width;
return this.texture.width * this.transform.scale.x;
}
public set height(value: number) {
this.frameBounds.height = value;
this.transform.scale.y = value / this.texture.height;
}
public get height(): number {
return this.frameBounds.height;
return this.texture.height * this.transform.scale.y;
}
/**
@@ -259,13 +264,16 @@ module Phaser {
*/
public preUpdate() {
this.frameBounds.x = this.x;
this.frameBounds.y = this.y;
this.transform.update();
this.screen.x = this.x - (this.game.world.cameras.default.worldView.x * this.scrollFactor.x);
this.screen.y = this.y - (this.game.world.cameras.default.worldView.y * this.scrollFactor.y);
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
//this.worldView.x = this.x * this.transform.scrollFactor.x;
//this.worldView.y = this.y * this.transform.scrollFactor.y;
this.worldView.width = this.width;
this.worldView.height = this.height;
if (this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.angle != 0 || this.angleOffset != 0 || this.texture.flippedX || this.texture.flippedY))
if (this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
{
this.modified = true;
}
@@ -319,7 +327,7 @@ module Phaser {
}
*/
if (this.modified == true && this.scale.equals(1) && this.skew.equals(0) && this.angle == 0 && this.angleOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
{
this.modified = false;
}
@@ -331,8 +339,7 @@ module Phaser {
*/
public destroy() {
//this.input.destroy();
this.input.destroy();
}
@@ -14,14 +14,14 @@ module Phaser {
export class Rectangle {
/**
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
* @class Rectangle
* @constructor
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
* @param {Number} width The width of the rectangle in pixels.
* @param {Number} height The height of the rectangle in pixels.
* @return {Rectangle} This rectangle object
* @param {Number} x The x coordinate of the top-left corner of the Rectangle.
* @param {Number} y The y coordinate of the top-left corner of the Rectangle.
* @param {Number} width The width of the Rectangle in pixels.
* @param {Number} height The height of the Rectangle in pixels.
* @return {Rectangle} This Rectangle object
**/
constructor(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
@@ -33,35 +33,35 @@ module Phaser {
}
/**
* The x coordinate of the top-left corner of the rectangle
* The x coordinate of the top-left corner of the Rectangle
* @property x
* @type Number
**/
x: number;
/**
* The y coordinate of the top-left corner of the rectangle
* The y coordinate of the top-left corner of the Rectangle
* @property y
* @type Number
**/
y: number;
/**
* The width of the rectangle in pixels
* The width of the Rectangle in pixels
* @property width
* @type Number
**/
width: number;
/**
* The height of the rectangle in pixels
* The height of the Rectangle in pixels
* @property height
* @type Number
**/
height: number;
/**
* Half of the width of the rectangle
* Half of the width of the Rectangle
* @property halfWidth
* @type Number
**/
@@ -70,7 +70,7 @@ module Phaser {
}
/**
* Half of the height of the rectangle
* Half of the height of the Rectangle
* @property halfHeight
* @type Number
**/
@@ -248,7 +248,7 @@ module Phaser {
/**
* Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
* @method setEmpty
* @return {Rectangle} This rectangle object
* @return {Rectangle} This Rectangle object
**/
set empty(value: bool) {
return this.setTo(0, 0, 0, 0);
@@ -283,11 +283,11 @@ module Phaser {
/**
* Sets the members of Rectangle to the specified values.
* @method setTo
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
* @param {Number} width The width of the rectangle in pixels.
* @param {Number} height The height of the rectangle in pixels.
* @return {Rectangle} This rectangle object
* @param {Number} x The x coordinate of the top-left corner of the Rectangle.
* @param {Number} y The y coordinate of the top-left corner of the Rectangle.
* @param {Number} width The width of the Rectangle in pixels.
* @param {Number} height The height of the Rectangle in pixels.
* @return {Rectangle} This Rectangle object
**/
setTo(x: number, y: number, width: number, height: number): Rectangle {
+81 -53
View File
@@ -42,11 +42,15 @@ module Phaser {
this.onTap = new Phaser.Signal();
this.onHold = new Phaser.Signal();
this.scale = new Vec2(1, 1);
this.speed = new Vec2;
this.position = new Vec2;
this._oldPosition = new Vec2;
this.circle = new Circle(0, 0, 44);
this.camera = this._game.camera;
this.activePointer = this.mousePointer;
this.currentPointers = 0;
}
@@ -63,6 +67,20 @@ module Phaser {
**/
private _oldPosition: Vec2 = null;
/**
* X coordinate of the most recent Pointer event
* @type {Number}
* @private
*/
private _x: number = 0;
/**
* X coordinate of the most recent Pointer event
* @type {Number}
* @private
*/
private _y: number = 0;
/**
* You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
* If you need to disable just one type of input, for example mouse, use Input.mouse.disabled = true instead
@@ -93,6 +111,13 @@ module Phaser {
*/
public static MOUSE_TOUCH_COMBINE: number = 2;
/**
* The camera being used for mouse and touch based pointers to calculate their world coordinates.
* @property camera
* @type {Camera}
**/
public camera: Camera;
/**
* Phaser.Mouse handler
* @type {Mouse}
@@ -147,30 +172,11 @@ module Phaser {
public circle: Circle = null;
/**
* X coordinate of the most recent Pointer event
* @type {Number}
* @private
*/
private _x: number = 0;
/**
* X coordinate of the most recent Pointer event
* @type {Number}
* @private
*/
private _y: number = 0;
/**
*
* @type {Number}
* The scale by which all input coordinates are multiplied, calculated by the StageScaleMode.
* In an un-scaled game the values will be x: 1 and y: 1.
* @type {Vec2}
*/
public scaleX: number = 1;
/**
*
* @type {Number}
*/
public scaleY: number = 1;
public scale: Vec2 = null;
/**
* The maximum number of Pointers allowed to be active at any one time.
@@ -347,37 +353,39 @@ module Phaser {
public pointer10: Pointer = null;
/**
* The screen X coordinate
* The most recently active Pointer object.
* When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.
* @property activePointer
* @type {Pointer}
**/
public activePointer: Pointer = null;
/**
* The X coordinate of the most recently active pointer.
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
* @property x
* @type {Number}
**/
public get x(): number {
return this._x;
}
public set x(value: number) {
this._x = Math.round(value);
}
/**
* The screen Y coordinate
* The Y coordinate of the most recently active pointer.
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
* @property y
* @type {Number}
**/
public get y(): number {
return this._y;
}
public set y(value: number) {
this._y = Math.round(value);
}
/**
@@ -447,29 +455,52 @@ module Phaser {
public inputObjects = [];
public totalTrackedObjects: number = 0;
// Add Input Enabled array + add/remove methods and then iterate and update them during the main update
// Clear down this array on State swap??? Maybe removed from it when Sprite is destroyed
/**
* Adds a new game object to be tracked by the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
* @method addGameObject
**/
public addGameObject(object) {
// Lots more checks here
// Find a spare slot
for (var i = 0; i < this.inputObjects.length; i++)
{
if (this.inputObjects[i] == null)
{
this.inputObjects[i] = object;
object.input.indexID = i;
this.totalTrackedObjects++;
return;
}
}
// If we got this far we need to push a new entry into the array
object.input.indexID = this.inputObjects.length;
this.inputObjects.push(object);
this.totalTrackedObjects++;
}
public removeGameObject(object) {
// TODO
/**
* Removes a game object from the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
* @method removeGameObject
**/
public removeGameObject(index: number) {
if (this.inputObjects[index])
{
this.inputObjects[index] = null;
}
}
/**
* Updates the Input Manager. Called by the core Game loop.
* @method update
**/
public update() {
// Swap for velocity vector - and add it to Pointer?
this.speed.x = this.position.x - this._oldPosition.x;
this.speed.y = this.position.y - this._oldPosition.y;
@@ -488,6 +519,7 @@ module Phaser {
if (this.pointer9) { this.pointer9.update(); }
if (this.pointer10) { this.pointer10.update(); }
}
/**
@@ -513,7 +545,7 @@ module Phaser {
if (this.pointer10) { this.pointer10.reset(); }
this.currentPointers = 0;
this._game.stage.canvas.style.cursor = "default";
if (hard == true)
@@ -610,7 +642,7 @@ module Phaser {
* @param {Any} event The event data from the Touch event
* @return {Pointer} The Pointer object that was started or null if no Pointer object is available
**/
public startPointer(event):Pointer {
public startPointer(event): Pointer {
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers)
{
@@ -669,7 +701,7 @@ module Phaser {
* @param {Any} event The event data from the Touch event
* @return {Pointer} The Pointer object that was updated or null if no Pointer object is available
**/
public updatePointer(event):Pointer {
public updatePointer(event): Pointer {
// Unrolled for speed
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
@@ -723,7 +755,7 @@ module Phaser {
* @param {Any} event The event data from the Touch event
* @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available
**/
public stopPointer(event):Pointer {
public stopPointer(event): Pointer {
// Unrolled for speed
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
@@ -883,18 +915,14 @@ module Phaser {
* @param {Camera} [camera]
*/
public getWorldX(camera?: Camera = this._game.camera) {
return camera.worldView.x + this.x;
}
/**
* @param {Camera} [camera]
*/
public getWorldY(camera?: Camera = this._game.camera) {
return camera.worldView.y + this.y;
}
/**
@@ -904,12 +932,12 @@ module Phaser {
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.font = '14px Courier';
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Input', x, y);
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
this._game.stage.context.fillText('X: ' + this.x + ' Y: ' + this.y, x, y + 14);
this._game.stage.context.fillText('World X: ' + this.getWorldX() + ' World Y: ' + this.getWorldY(), x, y + 28);
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
this._game.stage.context.fillText('Scale X: ' + this.scale.x.toFixed(1) + ' Scale Y: ' + this.scale.x.toFixed(1), x, y + 42);
this._game.stage.context.fillText('Screen X: ' + this.activePointer.screenX + ' Screen Y: ' + this.activePointer.screenY, x, y + 56);
}
+22 -37
View File
@@ -1,5 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Vec2.ts" />
/// <reference path="../math/Vec2.ts" />
/**
* Phaser - Pointer
@@ -170,14 +170,14 @@ module Phaser {
public screenY: number = -1;
/**
* The horizontal coordinate of point relative to the game element
* The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @property x
* @type {Number}
*/
public x: number = -1;
/**
* The vertical coordinate of point relative to the game element
* The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @property y
* @type {Number}
*/
@@ -263,39 +263,19 @@ module Phaser {
public targetObject = null;
/**
* Gets the X value of this Pointer in world coordinate space
* Gets the X value of this Pointer in world coordinates based on the given camera.
* @param {Camera} [camera]
*/
public getWorldX(camera?: Camera = this.game.camera) {
public worldX(camera?: Camera = this.game.input.camera) {
return camera.worldView.x + this.x;
}
/**
* Gets the Y value of this Pointer in world coordinate space
* Gets the Y value of this Pointer in world coordinates based on the given camera.
* @param {Camera} [camera]
*/
public getWorldY(camera?: Camera = this.game.camera) {
public worldY(camera?: Camera = this.game.input.camera) {
return camera.worldView.y + this.y;
}
/**
* Gets the X value of this Pointer in world coordinate space
* @param {Camera} [camera]
*/
public get scaledX():number {
return Math.floor(this.x * this.game.input.scaleX);
}
/**
* Gets the Y value of this Pointer in world coordinate space
* @param {Camera} [camera]
*/
public get scaledY():number {
return Math.floor(this.y * this.game.input.scaleY);
}
/**
@@ -329,14 +309,18 @@ module Phaser {
this.timeDown = this.game.time.now;
this._holdSent = false;
this.positionDown.setTo(this.x, this.y);
// This sets the x/y and other local values
this.move(event);
// x and y are the old values here?
this.positionDown.setTo(this.x, this.y);
if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
this.game.input.x = this.x * this.game.input.scaleX;
this.game.input.y = this.y * this.game.input.scaleY;
//this.game.input.x = this.x * this.game.input.scale.x;
//this.game.input.y = this.y * this.game.input.scale.y;
this.game.input.x = this.x;
this.game.input.y = this.y;
this.game.input.onDown.dispatch(this);
}
@@ -406,8 +390,8 @@ module Phaser {
this.screenX = event.screenX;
this.screenY = event.screenY;
this.x = this.pageX - this.game.stage.offset.x;
this.y = this.pageY - this.game.stage.offset.y;
this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
this.position.setTo(this.x, this.y);
this.circle.x = this.x;
@@ -415,8 +399,9 @@ module Phaser {
if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
this.game.input.x = this.x * this.game.input.scaleX;
this.game.input.y = this.y * this.game.input.scaleY;
this.game.input.activePointer = this;
this.game.input.x = this.x;
this.game.input.y = this.y;
this.game.input.position.setTo(this.game.input.x, this.game.input.y);
this.game.input.circle.x = this.game.input.x;
this.game.input.circle.y = this.game.input.y;
@@ -437,7 +422,7 @@ module Phaser {
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
{
if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
if (this.game.input.inputObjects[i] !== null && this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
{
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
_highestRenderObject = i;
@@ -525,7 +510,7 @@ module Phaser {
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
{
if (this.game.input.inputObjects[i].input.enabled)
if (this.game.input.inputObjects[i] !== null && this.game.input.inputObjects[i].input.enabled)
{
this.game.input.inputObjects[i].input._releasedHandler(this);
}
+1
View File
@@ -81,6 +81,7 @@ module Phaser {
// Malformed?
if (!json['frames'])
{
console.log(json);
throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
}
+51
View File
@@ -261,6 +261,57 @@ module Phaser {
}
/**
* Returns an array containing all of the keys of Images in the Cache.
* @return {Array} The string based keys in the Cache.
*/
public getImageKeys() {
var output = [];
for (var item in this._images)
{
output.push(item);
}
return output;
}
/**
* Returns an array containing all of the keys of Sounds in the Cache.
* @return {Array} The string based keys in the Cache.
*/
public getSoundKeys() {
var output = [];
for (var item in this._sounds)
{
output.push(item);
}
return output;
}
/**
* Returns an array containing all of the keys of Text Files in the Cache.
* @return {Array} The string based keys in the Cache.
*/
public getTextKeys() {
var output = [];
for (var item in this._text)
{
output.push(item);
}
return output;
}
/**
* Clean up cache memory.
*/
+1 -1
View File
@@ -167,7 +167,7 @@ module Phaser {
}
this._queueSize++;
this._fileList[key] = { type: 'textureatlas', key: key, url: textureURL, data: null, atlasURL: null, atlasData: atlasData['frames'], format: format, error: false, loaded: false };
this._fileList[key] = { type: 'textureatlas', key: key, url: textureURL, data: null, atlasURL: null, atlasData: atlasData, format: format, error: false, loaded: false };
this._keys.push(key);
}
else if (format == Loader.TEXTURE_ATLAS_XML_STARLING)
+23 -8
View File
@@ -12,11 +12,26 @@ module Phaser {
export class GameMath {
constructor(game: Game) {
this.game = game;
GameMath.sinA = [];
GameMath.cosA = [];
for (var i = 0; i < 360; i++)
{
GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
}
}
public game: Game;
// Pre-calculated tables containing Math.sin(angle) and Math.cos(angle) from -180 to 180
// So sinA[sprite.rotation] would be the same as Math.sin(sprite.rotation) without a call to Math.sin
static sinA: number[];
static cosA: number[];
static PI: number = 3.141592653589793; //number pi
static PI_2: number = 1.5707963267948965; //PI / 2 OR 90 deg
static PI_4: number = 0.7853981633974483; //PI / 4 OR 45 deg
@@ -308,7 +323,7 @@ module Phaser {
/**
* set an angle with in the bounds of -PI to PI
* set an angle within the bounds of -PI to PI
*/
public normalizeAngle(angle: number, radians: bool = true): number {
var rd: number = (radians) ? GameMath.PI : 180;
@@ -1022,20 +1037,20 @@ module Phaser {
}
/**
* Rotates the point around the x/y coordinates given to the desired angle and distance
* Rotates the point around the x/y coordinates given to the desired rotation and distance
* @param point {Object} Any object with exposed x and y properties
* @param x {number} The x coordinate of the anchor point
* @param y {number} The y coordinate of the anchor point
* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
* @param {Number} rotation The rotation in radians (unless asDegrees is true) to return the point from.
* @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)?
* @param {Number} distance An optional distance constraint between the point and the anchor
* @return The modified point object
*/
public rotatePoint(point, x1: number, y1: number, angle: number, asDegrees: bool = false, distance?:number = null) {
public rotatePoint(point, x1: number, y1: number, rotation: number, asDegrees: bool = false, distance?:number = null) {
if (asDegrees)
{
angle = angle * GameMath.DEG_TO_RAD;
rotation = rotation * GameMath.DEG_TO_RAD;
}
// Get distance from origin to the point
@@ -1044,8 +1059,8 @@ module Phaser {
distance = Math.sqrt(((x1 - point.x) * (x1 - point.x)) + ((y1 - point.y) * (y1 - point.y)));
}
point.x = x1 + distance * Math.cos(angle);
point.y = y1 + distance * Math.sin(angle);
point.x = x1 + distance * Math.cos(rotation);
point.y = y1 + distance * Math.sin(rotation);
return point;
+275
View File
@@ -0,0 +1,275 @@
/// <reference path="../Game.ts" />
/**
* Phaser - Mat3
*
* A 3x3 Matrix
*/
module Phaser {
export class Mat3 {
/**
* Creates a new Mat3 object.
* @class Mat3
* @constructor
* @return {Mat3} This object
**/
constructor() {
this.data = [1, 0, 0, 0, 1, 0, 0, 0, 1];
}
// Temporary vars used for internal calculations
private _a00: number;
private _a01: number;
private _a02: number;
private _a10: number;
private _a11: number;
private _a12: number;
private _a20: number;
private _a21: number;
private _a22: number;
public data: number[];
public get a00(): number {
return this.data[0];
}
public set a00(value: number) {
this.data[0] = value;
}
public get a01(): number {
return this.data[1];
}
public set a01(value: number) {
this.data[1] = value;
}
public get a02(): number {
return this.data[2];
}
public set a02(value: number) {
this.data[2] = value;
}
public get a10(): number {
return this.data[3];
}
public set a10(value: number) {
this.data[3] = value;
}
public get a11(): number {
return this.data[4];
}
public set a11(value: number) {
this.data[4] = value;
}
public get a12(): number {
return this.data[5];
}
public set a12(value: number) {
this.data[5] = value;
}
public get a20(): number {
return this.data[6];
}
public set a20(value: number) {
this.data[6] = value;
}
public get a21(): number {
return this.data[7];
}
public set a21(value: number) {
this.data[7] = value;
}
public get a22(): number {
return this.data[8];
}
public set a22(value: number) {
this.data[8] = value;
}
/**
* Copies the values from one Mat3 into this Mat3.
* @method copyFromMat3
* @param {any} source - The object to copy from.
* @return {Mat3} This Mat3 object.
**/
public copyFromMat3(source: Mat3): Mat3 {
this.data[0] = source.data[0];
this.data[1] = source.data[1];
this.data[2] = source.data[2];
this.data[3] = source.data[3];
this.data[4] = source.data[4];
this.data[5] = source.data[5];
this.data[6] = source.data[6];
this.data[7] = source.data[7];
this.data[8] = source.data[8];
return this;
}
/**
* Copies the upper-left 3x3 values into this Mat3.
* @method copyFromMat4
* @param {any} source - The object to copy from.
* @return {Mat3} This Mat3 object.
**/
public copyFromMat4(source: any): Mat3 {
this.data[0] = source[0];
this.data[1] = source[1];
this.data[2] = source[2];
this.data[3] = source[4];
this.data[4] = source[5];
this.data[5] = source[6];
this.data[6] = source[8];
this.data[7] = source[9];
this.data[8] = source[10];
return this;
}
/**
* Clones this Mat3 into a new Mat3
* @param {Mat3} out The output Mat3, if none is given a new Mat3 object will be created.
* @return {Mat3} The new Mat3
**/
public clone(out?:Mat3 = new Phaser.Mat3): Mat3 {
out[0] = this.data[0];
out[1] = this.data[1];
out[2] = this.data[2];
out[3] = this.data[3];
out[4] = this.data[4];
out[5] = this.data[5];
out[6] = this.data[6];
out[7] = this.data[7];
out[8] = this.data[8];
return out;
}
/**
* Sets this Mat3 to the identity matrix.
* @method identity
* @param {any} source - The object to copy from.
* @return {Mat3} This Mat3 object.
**/
public identity(): Mat3 {
return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
}
/**
* Translates this Mat3 by the given vector
**/
public translate(v:Phaser.Vec2): Mat3 {
this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
return this;
}
private setTemps() {
this._a00 = this.data[0];
this._a01 = this.data[1];
this._a02 = this.data[2];
this._a10 = this.data[3];
this._a11 = this.data[4];
this._a12 = this.data[5];
this._a20 = this.data[6];
this._a21 = this.data[7];
this._a22 = this.data[8];
}
/**
* Rotates this Mat3 by the given angle (given in radians)
**/
public rotate(rad:number): Mat3 {
this.setTemps();
var s = GameMath.sinA[rad];
var c = GameMath.cosA[rad];
this.data[0] = c * this._a00 + s * this._a10;
this.data[1] = c * this._a01 + s * this._a10;
this.data[2] = c * this._a02 + s * this._a12;
this.data[3] = c * this._a10 - s * this._a00;
this.data[4] = c * this._a11 - s * this._a01;
this.data[5] = c * this._a12 - s * this._a02;
return this;
}
/**
* Scales this Mat3 by the given vector
**/
public scale(v: Vec2): Mat3 {
this.data[0] = v.x * this.data[0];
this.data[1] = v.x * this.data[1];
this.data[2] = v.x * this.data[2];
this.data[3] = v.y * this.data[3];
this.data[4] = v.y * this.data[4];
this.data[5] = v.y * this.data[5];
return this;
}
public setTo(a00: number, a01: number, a02: number, a10: number, a11: number, a12: number, a20: number, a21: number, a22: number): Mat3 {
this.data[0] = a00;
this.data[1] = a01;
this.data[2] = a02;
this.data[3] = a10;
this.data[4] = a11;
this.data[5] = a12;
this.data[6] = a20;
this.data[7] = a21;
this.data[8] = a22;
return this;
}
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the object.
**/
public toString(): string {
return '';
//return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
}
}
}
+189
View File
@@ -0,0 +1,189 @@
/// <reference path="../Game.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../math/Mat3.ts" />
/**
* Phaser - Mat3Utils
*
* A collection of methods useful for manipulating and performing operations on Mat3 objects.
*
*/
module Phaser {
export class Mat3Utils {
/**
* Transpose the values of a Mat3
**/
static transpose(source:Phaser.Mat3, dest?:Phaser.Mat3 = null): Mat3 {
if (dest === null)
{
// Transpose ourselves
var a01 = source.data[1];
var a02 = source.data[2];
var a12 = source.data[5];
source.data[1] = source.data[3];
source.data[2] = source.data[6];
source.data[3] = a01;
source.data[5] = source.data[7];
source.data[6] = a02;
source.data[7] = a12;
}
else
{
source.data[0] = dest.data[0];
source.data[1] = dest.data[3];
source.data[2] = dest.data[6];
source.data[3] = dest.data[1];
source.data[4] = dest.data[4];
source.data[5] = dest.data[7];
source.data[6] = dest.data[2];
source.data[7] = dest.data[5];
source.data[8] = dest.data[8];
}
return source;
}
/**
* Inverts a Mat3
**/
static invert(source:Phaser.Mat3): Mat3 {
var a00 = source.data[0];
var a01 = source.data[1];
var a02 = source.data[2];
var a10 = source.data[3];
var a11 = source.data[4];
var a12 = source.data[5];
var a20 = source.data[6];
var a21 = source.data[7];
var a22 = source.data[8];
var b01 = a22 * a11 - a12 * a21;
var b11 = -a22 * a10 + a12 * a20;
var b21 = a21 * a10 - a11 * a20;
// Determinant
var det = a00 * b01 + a01 * b11 + a02 * b21;
if (!det) {
return null;
}
det = 1.0 / det;
source.data[0] = b01 * det;
source.data[1] = (-a22 * a01 + a02 * a21) * det;
source.data[2] = (a12 * a01 - a02 * a11) * det;
source.data[3] = b11 * det;
source.data[4] = (a22 * a00 - a02 * a20) * det;
source.data[5] = (-a12 * a00 + a02 * a10) * det;
source.data[6] = b21 * det;
source.data[7] = (-a21 * a00 + a01 * a20) * det;
source.data[8] = (a11 * a00 - a01 * a10) * det;
return source;
}
/**
* Calculates the adjugate of a Mat3
**/
static adjoint(source:Phaser.Mat3): Mat3 {
var a00 = source.data[0];
var a01 = source.data[1];
var a02 = source.data[2];
var a10 = source.data[3];
var a11 = source.data[4];
var a12 = source.data[5];
var a20 = source.data[6];
var a21 = source.data[7];
var a22 = source.data[8];
source.data[0] = (a11 * a22 - a12 * a21);
source.data[1] = (a02 * a21 - a01 * a22);
source.data[2] = (a01 * a12 - a02 * a11);
source.data[3] = (a12 * a20 - a10 * a22);
source.data[4] = (a00 * a22 - a02 * a20);
source.data[5] = (a02 * a10 - a00 * a12);
source.data[6] = (a10 * a21 - a11 * a20);
source.data[7] = (a01 * a20 - a00 * a21);
source.data[8] = (a00 * a11 - a01 * a10);
return source;
}
/**
* Calculates the adjugate of a Mat3
**/
static determinant(source:Phaser.Mat3): number {
var a00 = source.data[0];
var a01 = source.data[1];
var a02 = source.data[2];
var a10 = source.data[3];
var a11 = source.data[4];
var a12 = source.data[5];
var a20 = source.data[6];
var a21 = source.data[7];
var a22 = source.data[8];
return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
}
/**
* Multiplies two Mat3s
**/
static multiply(source:Phaser.Mat3, b:Phaser.Mat3): Mat3 {
var a00 = source.data[0];
var a01 = source.data[1];
var a02 = source.data[2];
var a10 = source.data[3];
var a11 = source.data[4];
var a12 = source.data[5];
var a20 = source.data[6];
var a21 = source.data[7];
var a22 = source.data[8];
var b00 = b.data[0];
var b01 = b.data[1];
var b02 = b.data[2];
var b10 = b.data[3];
var b11 = b.data[4];
var b12 = b.data[5];
var b20 = b.data[6];
var b21 = b.data[7];
var b22 = b.data[8];
source.data[0] = b00 * a00 + b01 * a10 + b02 * a20;
source.data[1] = b00 * a01 + b01 * a11 + b02 * a21;
source.data[2] = b00 * a02 + b01 * a12 + b02 * a22;
source.data[3] = b10 * a00 + b11 * a10 + b12 * a20;
source.data[4] = b10 * a01 + b11 * a11 + b12 * a21;
source.data[5] = b10 * a02 + b11 * a12 + b12 * a22;
source.data[6] = b20 * a00 + b21 * a10 + b22 * a20;
source.data[7] = b20 * a01 + b21 * a11 + b22 * a21;
source.data[8] = b20 * a02 + b21 * a12 + b22 * a22;
return source;
}
static fromQuaternion() { }
static normalFromMat4() { }
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="LinkedList.ts" />
/**
+1 -1
View File
@@ -3,7 +3,7 @@
/**
* Phaser - Vec2
*
* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
* A Vector 2
*/
module Phaser {
+1 -1
View File
@@ -1,5 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Vec2.ts" />
/// <reference path="../math/Vec2.ts" />
/**
* Phaser - Vec2Utils
+60 -33
View File
@@ -1,5 +1,5 @@
/// <reference path="../core/Vec2.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/**
@@ -10,26 +10,29 @@ module Phaser.Physics {
export class Body {
constructor(parent: Sprite, type: number) {
constructor(sprite: Phaser.Sprite, type: number) {
this.parent = parent;
this.game = parent.game;
this.sprite = sprite;
this.game = sprite.game;
this.type = type;
// Fixture properties
// Will extend into its own class at a later date - can move the fixture defs there and add shape support, but this will do for 1.0 release
this.bounds = new Rectangle(parent.x + Math.round(parent.width / 2), parent.y + Math.round(parent.height / 2), parent.width, parent.height);
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
this.bounds = new Rectangle;
this._width = sprite.width;
this._height = sprite.height;
// Body properties
this.gravity = Vec2Utils.clone(this.game.world.physics.gravity);
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
this.velocity = new Vec2;
this.acceleration = new Vec2;
this.drag = Vec2Utils.clone(this.game.world.physics.drag);
this.maxVelocity = new Vec2(10000, 10000);
this.angle = 0;
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.angularDrag = 0;
@@ -38,14 +41,21 @@ module Phaser.Physics {
this.wasTouching = Types.NONE;
this.allowCollisions = Types.ANY;
this.position = new Vec2(parent.x + this.bounds.halfWidth, parent.y + this.bounds.halfHeight);
this.oldPosition = new Vec2(parent.x + this.bounds.halfWidth, parent.y + this.bounds.halfHeight);
this.position = new Vec2(sprite.x + this.bounds.halfWidth, sprite.y + this.bounds.halfHeight);
this.oldPosition = new Vec2(sprite.x + this.bounds.halfWidth, sprite.y + this.bounds.halfHeight);
this.offset = new Vec2;
}
/**
* Reference to Phaser.Game
*/
public game: Game;
public parent: Sprite;
/**
* Reference to the parent Sprite
*/
public sprite: Phaser.Sprite;
/**
* The type of Body (disabled, dynamic, static or kinematic)
@@ -70,12 +80,6 @@ module Phaser.Physics {
public angularDrag: number = 0;
public maxAngular: number = 10000;
/**
* Angle of rotation of this body.
* @type {number}
*/
public angle: number;
/**
* Orientation of the object.
* @type {number}
@@ -94,17 +98,41 @@ module Phaser.Physics {
private _width: number = 0;
private _height: number = 0;
public get x(): number {
return this.sprite.x + this.offset.x;
}
public get y(): number {
return this.sprite.y + this.offset.y;
}
public set width(value: number) {
this._width = value;
}
public set height(value: number) {
this._height = value;
}
public get width(): number {
return this._width * this.sprite.transform.scale.x;
}
public get height(): number {
return this._height * this.sprite.transform.scale.y;
}
public preUpdate() {
this.oldPosition.copyFrom(this.position);
this.bounds.x = this.position.x - this.bounds.halfWidth;
this.bounds.y = this.position.y - this.bounds.halfHeight;
if (this.parent.scale.equals(1) == false)
{
}
this.bounds.x = this.x;
this.bounds.y = this.y;
this.bounds.width = this.width;
this.bounds.height = this.height;
}
@@ -117,14 +145,13 @@ module Phaser.Physics {
{
this.game.world.physics.updateMotion(this);
this.parent.x = (this.position.x - this.bounds.halfWidth) - this.offset.x;
this.parent.y = (this.position.y - this.bounds.halfHeight) - this.offset.y;
this.wasTouching = this.touching;
this.touching = Phaser.Types.NONE;
}
this.position.setTo(this.x, this.y);
}
public get hullWidth(): number {
@@ -267,13 +294,13 @@ module Phaser.Physics {
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this.parent.texture.context.fillStyle = color;
this.parent.texture.context.fillText('Sprite: (' + this.parent.frameBounds.width + ' x ' + this.parent.frameBounds.height + ')', x, y);
//this.parent.texture.context.fillText('x: ' + this._parent.frameBounds.x.toFixed(1) + ' y: ' + this._parent.frameBounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(0), x, y + 14);
this.parent.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
this.parent.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
this.parent.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
this.sprite.texture.context.fillStyle = color;
this.sprite.texture.context.fillText('Sprite: (' + this.sprite.width + ' x ' + this.sprite.height + ')', x, y);
//this.sprite.texture.context.fillText('x: ' + this._sprite.frameBounds.x.toFixed(1) + ' y: ' + this._sprite.frameBounds.y.toFixed(1) + ' rotation: ' + this._sprite.rotation.toFixed(1), x, y + 14);
this.sprite.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.sprite.transform.rotation.toFixed(0), x, y + 14);
this.sprite.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
this.sprite.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
this.sprite.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
}
+9 -8
View File
@@ -62,9 +62,6 @@ module Phaser.Physics {
private _quadTree: QuadTree;
private _quadTreeResult: bool;
public bounds: Rectangle;
public gravity: Vec2;
@@ -141,20 +138,22 @@ module Phaser.Physics {
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
body.angularVelocity += this._velocityDelta;
body.angle += body.angularVelocity * this.game.time.elapsed;
body.sprite.transform.rotation += body.angularVelocity * this.game.time.elapsed;
body.angularVelocity += this._velocityDelta;
this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
body.velocity.x += this._velocityDelta;
this._delta = body.velocity.x * this.game.time.elapsed;
body.velocity.x += this._velocityDelta;
body.position.x += this._delta;
//body.position.x += this._delta;
body.sprite.x += this._delta;
this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
body.velocity.y += this._velocityDelta;
this._delta = body.velocity.y * this.game.time.elapsed;
body.velocity.y += this._velocityDelta;
body.position.y += this._delta;
//body.position.y += this._delta;
body.sprite.y += this._delta;
}
@@ -424,7 +423,7 @@ module Phaser.Physics {
body1.velocity.y = this._obj2Velocity - this._obj1Velocity * body1.bounce.y;
// This is special case code that handles things like horizontal moving platforms you can ride
//if (body2.parent.active && body2.moves && (body1.deltaY > body2.deltaY))
if (body2.parent.active && (body1.deltaY > body2.deltaY))
if (body2.sprite.active && (body1.deltaY > body2.deltaY))
{
body1.position.x += body2.position.x - body2.oldPosition.x;
}
@@ -436,7 +435,7 @@ module Phaser.Physics {
body2.velocity.y = this._obj1Velocity - this._obj2Velocity * body2.bounce.y;
// This is special case code that handles things like horizontal moving platforms you can ride
//if (object1.active && body1.moves && (body1.deltaY < body2.deltaY))
if (body1.parent.active && (body1.deltaY < body2.deltaY))
if (body1.sprite.active && (body1.deltaY < body2.deltaY))
{
body2.position.x += body1.position.x - body1.oldPosition.x;
}
@@ -748,6 +747,8 @@ module Phaser.Physics {
this._quadTreeResult = this._quadTree.execute();
console.log('over', this._quadTreeResult);
this._quadTree.destroy();
this._quadTree = null;
+354 -89
View File
@@ -53,11 +53,11 @@ module Phaser {
{
this._camera = this._cameraList[c];
this._camera.preRender();
this.preRenderCamera(this._camera);
this._game.world.group.render(this._camera);
this._camera.postRender();
this.postRenderCamera(this._camera);
}
this.renderTotal = this._count;
@@ -77,25 +77,304 @@ module Phaser {
}
public preRenderGroup(camera: Camera, group: Group) {
if (camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1 || this.inScreen(camera) == false)
{
return false;
}
// Reset our temp vars
this._ga = -1;
this._sx = 0;
this._sy = 0;
this._sw = group.texture.width;
this._sh = group.texture.height;
this._fx = group.transform.scale.x;
this._fy = group.transform.scale.y;
this._sin = 0;
this._cos = 1;
//this._dx = (camera.screenView.x * camera.scrollFactor.x) + camera.frameBounds.x - (camera.worldView.x * camera.scrollFactor.x);
//this._dy = (camera.screenView.y * camera.scrollFactor.y) + camera.frameBounds.y - (camera.worldView.y * camera.scrollFactor.y);
this._dx = 0;
this._dy = 0;
this._dw = group.texture.width;
this._dh = group.texture.height;
// Global Composite Ops
if (group.texture.globalCompositeOperation)
{
group.texture.context.save();
group.texture.context.globalCompositeOperation = group.texture.globalCompositeOperation;
}
// Alpha
if (group.texture.alpha !== 1 && group.texture.context.globalAlpha !== group.texture.alpha)
{
this._ga = group.texture.context.globalAlpha;
group.texture.context.globalAlpha = group.texture.alpha;
}
// Flip X
if (group.texture.flippedX)
{
this._fx = -group.transform.scale.x;
}
// Flip Y
if (group.texture.flippedY)
{
this._fy = -group.transform.scale.y;
}
// Rotation and Flipped
if (group.modified)
{
if (group.transform.rotation !== 0 || group.transform.rotationOffset !== 0)
{
this._sin = Math.sin(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
this._cos = Math.cos(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
}
// setTransform(a, b, c, d, e, f);
// a = scale x
// b = skew x
// c = skew y
// d = scale y
// e = translate x
// f = translate y
group.texture.context.save();
group.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + group.transform.skew.x, -(this._sin * this._fy) + group.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
this._dx = -group.transform.origin.x;
this._dy = -group.transform.origin.y;
}
else
{
if (!group.transform.origin.equals(0))
{
this._dx -= group.transform.origin.x;
this._dy -= group.transform.origin.y;
}
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
if (group.texture.opaque)
{
group.texture.context.fillStyle = group.texture.backgroundColor;
group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
if (group.texture.loaded)
{
group.texture.context.drawImage(
group.texture.texture, // Source Image
this._sx, // Source X (location within the source image)
this._sy, // Source Y
this._sw, // Source Width
this._sh, // Source Height
this._dx, // Destination X (where on the canvas it'll be drawn)
this._dy, // Destination Y
this._dw, // Destination Width (always same as Source Width unless scaled)
this._dh // Destination Height (always same as Source Height unless scaled)
);
}
return true;
}
public postRenderGroup(camera: Camera, group: Group) {
if (group.modified || group.texture.globalCompositeOperation)
{
group.texture.context.restore();
}
// This could have been over-written by a sprite, need to store elsewhere
if (this._ga > -1)
{
group.texture.context.globalAlpha = this._ga;
}
}
/**
* Check whether this object is visible in a specific camera rectangle.
* @param camera {Rectangle} The rectangle you want to check.
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
* Check whether this object is visible in a specific camera Rectangle.
* @param camera {Rectangle} The Rectangle you want to check.
* @return {boolean} Return true if bounds of this sprite intersects the given Rectangle, otherwise return false.
*/
public inCamera(camera: Camera, sprite: Sprite): bool {
// Object fixed in place regardless of the camera scrolling? Then it's always visible
if (sprite.scrollFactor.x == 0 && sprite.scrollFactor.y == 0)
if (sprite.transform.scrollFactor.equals(0))
{
return true;
}
this._dx = sprite.frameBounds.x - (camera.worldView.x * sprite.scrollFactor.x);
this._dy = sprite.frameBounds.y - (camera.worldView.y * sprite.scrollFactor.y);
this._dw = sprite.frameBounds.width * sprite.scale.x;
this._dh = sprite.frameBounds.height * sprite.scale.y;
return RectangleUtils.intersects(sprite.cameraView, camera.screenView);
return (camera.scaledX + camera.worldView.width > this._dx) && (camera.scaledX < this._dx + this._dw) && (camera.scaledY + camera.worldView.height > this._dy) && (camera.scaledY < this._dy + this._dh);
}
public inScreen(camera: Camera): bool {
return true;
}
/**
* Render this sprite to specific camera. Called by game loop after update().
* @param camera {Camera} Camera this sprite will be rendered to.
* @return {boolean} Return false if not rendered, otherwise return true.
*/
public preRenderCamera(camera: Camera): bool {
if (camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1 || this.inScreen(camera) == false)
{
return false;
}
// Reset our temp vars
this._ga = -1;
this._sx = 0;
this._sy = 0;
this._sw = camera.width;
this._sh = camera.height;
this._fx = camera.transform.scale.x;
this._fy = camera.transform.scale.y;
this._sin = 0;
this._cos = 1;
this._dx = camera.screenView.x;
this._dy = camera.screenView.y;
this._dw = camera.width;
this._dh = camera.height;
// Global Composite Ops
if (camera.texture.globalCompositeOperation)
{
camera.texture.context.save();
camera.texture.context.globalCompositeOperation = camera.texture.globalCompositeOperation;
}
// Alpha
if (camera.texture.alpha !== 1 && camera.texture.context.globalAlpha != camera.texture.alpha)
{
this._ga = camera.texture.context.globalAlpha;
camera.texture.context.globalAlpha = camera.texture.alpha;
}
// Sprite Flip X
if (camera.texture.flippedX)
{
this._fx = -camera.transform.scale.x;
}
// Sprite Flip Y
if (camera.texture.flippedY)
{
this._fy = -camera.transform.scale.y;
}
// Rotation and Flipped
if (camera.modified)
{
if (camera.transform.rotation !== 0 || camera.transform.rotationOffset !== 0)
{
this._sin = Math.sin(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
this._cos = Math.cos(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
}
// setTransform(a, b, c, d, e, f);
// a = scale x
// b = skew x
// c = skew y
// d = scale y
// e = translate x
// f = translate y
camera.texture.context.save();
camera.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + camera.transform.skew.x, -(this._sin * this._fy) + camera.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
this._dx = -camera.transform.origin.x;
this._dy = -camera.transform.origin.y;
}
else
{
if (!camera.transform.origin.equals(0))
{
this._dx -= camera.transform.origin.x;
this._dy -= camera.transform.origin.y;
}
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
// Clip the camera so we don't get sprites appearing outside the edges
if (camera.clip == true && camera.disableClipping == false)
{
camera.texture.context.beginPath();
camera.texture.context.rect(camera.screenView.x, camera.screenView.x, camera.screenView.width, camera.screenView.height);
camera.texture.context.closePath();
camera.texture.context.clip();
}
if (camera.texture.opaque)
{
camera.texture.context.fillStyle = camera.texture.backgroundColor;
camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
//camera.fx.render(camera);
if (camera.texture.loaded)
{
camera.texture.context.drawImage(
camera.texture.texture, // Source Image
this._sx, // Source X (location within the source image)
this._sy, // Source Y
this._sw, // Source Width
this._sh, // Source Height
this._dx, // Destination X (where on the canvas it'll be drawn)
this._dy, // Destination Y
this._dw, // Destination Width (always same as Source Width unless scaled)
this._dh // Destination Height (always same as Source Height unless scaled)
);
}
return true;
}
public postRenderCamera(camera: Camera) {
//camera.fx.postRender(camera);
if (camera.modified || camera.texture.globalCompositeOperation)
{
camera.texture.context.restore();
}
// This could have been over-written by a sprite, need to store elsewhere
if (this._ga > -1)
{
camera.texture.context.globalAlpha = this._ga;
}
}
@@ -112,8 +391,8 @@ module Phaser {
this._fy = 1;
this._sin = 0;
this._cos = 1;
this._dx = camera.scaledX + circle.x - camera.worldView.x;
this._dy = camera.scaledY + circle.y - camera.worldView.y;
this._dx = camera.screenView.x + circle.x - camera.worldView.x;
this._dy = camera.screenView.y + circle.y - camera.worldView.y;
this._dw = circle.diameter;
this._dh = circle.diameter;
@@ -162,49 +441,41 @@ module Phaser {
*/
public renderSprite(camera: Camera, sprite: Sprite): bool {
if (sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false)
Phaser.SpriteUtils.updateCameraView(camera, sprite);
if (sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false)
{
return false;
}
sprite.renderOrderID = this._count;
this._count++;
// Reset our temp vars
this._ga = -1;
this._sx = 0;
this._sy = 0;
this._sw = sprite.frameBounds.width;
this._sh = sprite.frameBounds.height;
this._fx = sprite.scale.x;
this._fy = sprite.scale.y;
this._sin = 0;
this._cos = 1;
this._dx = (camera.scaledX * sprite.scrollFactor.x) + sprite.frameBounds.x - (camera.worldView.x * sprite.scrollFactor.x);
this._dy = (camera.scaledY * sprite.scrollFactor.y) + sprite.frameBounds.y - (camera.worldView.y * sprite.scrollFactor.y);
this._dw = sprite.frameBounds.width;
this._dh = sprite.frameBounds.height;
this._sw = sprite.texture.width;
this._sh = sprite.texture.height;
this._dx = camera.screenView.x + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
this._dy = camera.screenView.y + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
this._dw = sprite.texture.width;
this._dh = sprite.texture.height;
// Global Composite Ops
if (sprite.texture.globalCompositeOperation)
{
sprite.texture.context.save();
sprite.texture.context.globalCompositeOperation = sprite.texture.globalCompositeOperation;
}
// Alpha
if (sprite.texture.alpha !== 1)
if (sprite.texture.alpha !== 1 && sprite.texture.context.globalAlpha != sprite.texture.alpha)
{
this._ga = sprite.texture.context.globalAlpha;
sprite.texture.context.globalAlpha = sprite.texture.alpha;
}
// Sprite Flip X
if (sprite.texture.flippedX)
{
this._fx = -sprite.scale.x;
}
// Sprite Flip Y
if (sprite.texture.flippedY)
{
this._fy = -sprite.scale.y;
}
if (sprite.animations.currentFrame !== null)
{
this._sx = sprite.animations.currentFrame.x;
@@ -214,39 +485,33 @@ module Phaser {
{
this._dx += sprite.animations.currentFrame.spriteSourceSizeX;
this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
this._sw = sprite.animations.currentFrame.spriteSourceSizeW;
this._sh = sprite.animations.currentFrame.spriteSourceSizeH;
this._dw = sprite.animations.currentFrame.spriteSourceSizeW;
this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
}
}
// Rotation and Flipped
if (sprite.modified)
{
if (sprite.texture.renderRotation == true && (sprite.angle !== 0 || sprite.angleOffset !== 0))
{
this._sin = Math.sin(sprite.game.math.degreesToRadians(sprite.angleOffset + sprite.angle));
this._cos = Math.cos(sprite.game.math.degreesToRadians(sprite.angleOffset + sprite.angle));
}
// setTransform(a, b, c, d, e, f);
// a = scale x
// b = skew x
// c = skew y
// d = scale y
// e = translate x
// f = translate y
sprite.texture.context.save();
sprite.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + sprite.skew.x, -(this._sin * this._fy) + sprite.skew.y, this._cos * this._fy, this._dx, this._dy);
this._dx = -sprite.origin.x;
this._dy = -sprite.origin.y;
sprite.texture.context.setTransform(
sprite.transform.local.data[0], // scale x
sprite.transform.local.data[3], // skew x
sprite.transform.local.data[1], // skew y
sprite.transform.local.data[4], // scale y
this._dx, // translate x
this._dy // translate y
);
this._dx = sprite.transform.origin.x * -this._dw;
this._dy = sprite.transform.origin.y * -this._dh;
}
else
{
if (!sprite.origin.equals(0))
{
this._dx -= sprite.origin.x;
this._dy -= sprite.origin.y;
}
this._dx -= (this._dw * sprite.transform.origin.x);
this._dy -= (this._dh * sprite.transform.origin.y);
}
this._sx = Math.round(this._sx);
@@ -258,6 +523,12 @@ module Phaser {
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
if (sprite.texture.opaque)
{
sprite.texture.context.fillStyle = sprite.texture.backgroundColor;
sprite.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
if (sprite.texture.loaded)
{
sprite.texture.context.drawImage(
@@ -272,14 +543,8 @@ module Phaser {
this._dh // Destination Height (always same as Source Height unless scaled)
);
}
else
{
//sprite.texture.context.fillStyle = this.fillColor;
sprite.texture.context.fillStyle = 'rgb(255,255,255)';
sprite.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
if (sprite.modified)
if (sprite.modified || sprite.texture.globalCompositeOperation)
{
sprite.texture.context.restore();
}
@@ -295,7 +560,7 @@ module Phaser {
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool {
if (scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false)
if (scrollZone.transform.scale.x == 0 || scrollZone.transform.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false)
{
return false;
}
@@ -306,16 +571,16 @@ module Phaser {
this._ga = -1;
this._sx = 0;
this._sy = 0;
this._sw = scrollZone.frameBounds.width;
this._sh = scrollZone.frameBounds.height;
this._fx = scrollZone.scale.x;
this._fy = scrollZone.scale.y;
this._sw = scrollZone.width;
this._sh = scrollZone.height;
this._fx = scrollZone.transform.scale.x;
this._fy = scrollZone.transform.scale.y;
this._sin = 0;
this._cos = 1;
this._dx = (camera.scaledX * scrollZone.scrollFactor.x) + scrollZone.frameBounds.x - (camera.worldView.x * scrollZone.scrollFactor.x);
this._dy = (camera.scaledY * scrollZone.scrollFactor.y) + scrollZone.frameBounds.y - (camera.worldView.y * scrollZone.scrollFactor.y);
this._dw = scrollZone.frameBounds.width;
this._dh = scrollZone.frameBounds.height;
this._dx = (camera.screenView.x * scrollZone.transform.scrollFactor.x) + scrollZone.x - (camera.worldView.x * scrollZone.transform.scrollFactor.x);
this._dy = (camera.screenView.y * scrollZone.transform.scrollFactor.y) + scrollZone.y - (camera.worldView.y * scrollZone.transform.scrollFactor.y);
this._dw = scrollZone.width;
this._dh = scrollZone.height;
// Alpha
if (scrollZone.texture.alpha !== 1)
@@ -327,22 +592,22 @@ module Phaser {
// Sprite Flip X
if (scrollZone.texture.flippedX)
{
this._fx = -scrollZone.scale.x;
this._fx = -scrollZone.transform.scale.x;
}
// Sprite Flip Y
if (scrollZone.texture.flippedY)
{
this._fy = -scrollZone.scale.y;
this._fy = -scrollZone.transform.scale.y;
}
// Rotation and Flipped
if (scrollZone.modified)
{
if (scrollZone.texture.renderRotation == true && (scrollZone.angle !== 0 || scrollZone.angleOffset !== 0))
if (scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.transform.rotationOffset !== 0))
{
this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.angleOffset + scrollZone.angle));
this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.angleOffset + scrollZone.angle));
this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
}
// setTransform(a, b, c, d, e, f);
@@ -354,17 +619,17 @@ module Phaser {
// f = translate y
scrollZone.texture.context.save();
scrollZone.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + scrollZone.skew.x, -(this._sin * this._fy) + scrollZone.skew.y, this._cos * this._fy, this._dx, this._dy);
scrollZone.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + scrollZone.transform.skew.x, -(this._sin * this._fy) + scrollZone.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
this._dx = -scrollZone.origin.x;
this._dy = -scrollZone.origin.y;
this._dx = -scrollZone.transform.origin.x;
this._dy = -scrollZone.transform.origin.y;
}
else
{
if (!scrollZone.origin.equals(0))
if (!scrollZone.transform.origin.equals(0))
{
this._dx -= scrollZone.origin.x;
this._dy -= scrollZone.origin.y;
this._dx -= scrollZone.transform.origin.x;
this._dy -= scrollZone.transform.origin.y;
}
}
+13 -11
View File
@@ -10,28 +10,30 @@ module Phaser {
this._game = game;
}
/**
* The essential reference to the main game object
*/
private _game: Phaser.Game;
public render() {}
public renderGameObject(object) {
}
public inCamera(camera: Camera, sprite: Sprite): bool { return true; }
public renderSprite(camera: Camera, sprite: Sprite): bool {
return true;
}
public renderGameObject(object) {}
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool {
return true;
}
public renderSprite(camera: Camera, sprite: Sprite): bool { return true; }
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool { return true; }
public renderCircle(camera: Camera, circle: Circle, context, outline?: bool = true, fill?: bool = true, lineColor?: string = 'rgb(0,255,0)', fillColor?: string = 'rgba(0,100,0.0.3)', lineWidth?: number = 1): bool {
return true;
}
public preRenderCamera(camera: Camera) { }
public postRenderCamera(camera: Camera) { }
public preRenderGroup(camera: Camera, group: Group) { }
public postRenderGroup(camera: Camera, group: Group) { }
}
}
+6 -1
View File
@@ -8,8 +8,13 @@ module Phaser {
renderGameObject(object);
renderSprite(camera: Camera, sprite: Sprite): bool;
renderScrollZone(camera: Camera, sprite: ScrollZone): bool;
renderCircle(camera: Camera, circle: Circle, context, outline?: bool, fill?: bool, lineColor?: string, fillColor?: string, lineWidth?: number);
preRenderGroup(camera: Camera, group: Group);
postRenderGroup(camera: Camera, group: Group);
preRenderCamera(camera: Camera);
postRenderCamera(camera: Camera);
inCamera(camera: Camera, sprite: Sprite): bool;
}
+65 -21
View File
@@ -15,7 +15,7 @@ module Phaser {
/**
* StageScaleMode constructor
*/
constructor(game: Game) {
constructor(game: Game, width: number, height: number) {
this._game = game;
@@ -40,6 +40,10 @@ module Phaser {
this.scaleFactor = new Vec2(1, 1);
this.aspectRatio = 0;
this.minWidth = width;
this.minHeight = height;
this.maxWidth = width;
this.maxHeight = height;
window.addEventListener('orientationchange', (event) => this.checkOrientation(event), false);
window.addEventListener('resize', (event) => this.checkResize(event), false);
@@ -95,6 +99,22 @@ module Phaser {
*/
public incorrectOrientation: bool = false;
/**
* If you wish to align your game in the middle of the page then you can set this value to true.
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
* @type {Boolean}
*/
public pageAlignHorizontally: bool = false;
/**
* If you wish to align your game in the middle of the page then you can set this value to true.
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
* @type {Boolean}
*/
public pageAlignVeritcally: bool = false;
/**
* Minimum width the canvas should be scaled to (in pixels)
* @type {number}
@@ -354,7 +374,7 @@ module Phaser {
/**
* Set screen size automatically based on the scaleMode.
*/
private setScreenSize() {
public setScreenSize(force: bool = false) {
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
{
@@ -370,7 +390,7 @@ module Phaser {
this._iterations--;
if (window.innerHeight > this._startHeight || this._iterations < 0)
if (force || window.innerHeight > this._startHeight || this._iterations < 0)
{
// Set minimum height of content to new window height
document.documentElement.style.minHeight = window.innerHeight + 'px';
@@ -400,39 +420,63 @@ module Phaser {
private setSize() {
if (this.maxWidth && this.width > this.maxWidth)
if (this.incorrectOrientation == false)
{
this.width = this.maxWidth;
}
if (this.maxWidth && this.width > this.maxWidth)
{
this.width = this.maxWidth;
}
if (this.maxHeight && this.height > this.maxHeight)
{
this.height = this.maxHeight;
}
if (this.maxHeight && this.height > this.maxHeight)
{
this.height = this.maxHeight;
}
if (this.minWidth && this.width < this.minWidth)
{
this.width = this.minWidth;
}
if (this.minWidth && this.width < this.minWidth)
{
this.width = this.minWidth;
}
if (this.minHeight && this.height < this.minHeight)
{
this.height = this.minHeight;
if (this.minHeight && this.height < this.minHeight)
{
this.height = this.minHeight;
}
}
this._game.stage.canvas.style.width = this.width + 'px';
this._game.stage.canvas.style.height = this.height + 'px';
this._game.input.scaleX = this._game.stage.width / this.width;
this._game.input.scaleY = this._game.stage.height / this.height;
this._game.input.scale.setTo(this._game.stage.width / this.width, this._game.stage.height / this.height);
if (this.pageAlignHorizontally)
{
if (this.width < window.innerWidth && this.incorrectOrientation == false)
{
this._game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
}
else
{
this._game.stage.canvas.style.marginLeft = '0px';
}
}
if (this.pageAlignVeritcally)
{
if (this.height < window.innerHeight && this.incorrectOrientation == false)
{
this._game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
}
else
{
this._game.stage.canvas.style.marginTop = '0px';
}
}
this._game.stage.getOffset(this._game.stage.canvas);
this.aspectRatio = this.width / this.height;
this.scaleFactor.x = this._game.stage.width / this.width;
this.scaleFactor.y = this._game.stage.height / this.height;
//this.scaleFactor.x = this.width / this._game.stage.width;
//this.scaleFactor.y = this.height / this._game.stage.height;
}
+3 -3
View File
@@ -1,7 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Circle.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/**
* Phaser - CircleUtils
+3 -3
View File
@@ -1,7 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Circle.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/**
* Phaser - ColorUtils
+42 -7
View File
@@ -1,7 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Circle.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="RectangleUtils.ts" />
@@ -26,10 +26,45 @@ module Phaser {
static renderSpriteInfo(sprite: Sprite, x: number, y: number, color?: string = 'rgb(255,255,255)') {
DebugUtils.game.stage.context.fillStyle = color;
DebugUtils.game.stage.context.fillText('Sprite: ' + ' (' + sprite.frameBounds.width + ' x ' + sprite.frameBounds.height + ')', x, y);
DebugUtils.game.stage.context.fillText('x: ' + sprite.frameBounds.x.toFixed(1) + ' y: ' + sprite.frameBounds.y.toFixed(1) + ' angle: ' + sprite.angle.toFixed(1), x, y + 14);
//DebugUtils.game.stage.context.fillText('dx: ' + this._dx.toFixed(1) + ' dy: ' + this._dy.toFixed(1) + ' dw: ' + this._dw.toFixed(1) + ' dh: ' + this._dh.toFixed(1), x, y + 28);
//DebugUtils.game.stage.context.fillText('sx: ' + this._sx.toFixed(1) + ' sy: ' + this._sy.toFixed(1) + ' sw: ' + this._sw.toFixed(1) + ' sh: ' + this._sh.toFixed(1), x, y + 42);
DebugUtils.game.stage.context.fillText('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y, x, y);
DebugUtils.game.stage.context.fillText('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1), x, y + 14);
DebugUtils.game.stage.context.fillText('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right, x, y + 28);
DebugUtils.game.stage.context.fillText('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1), x, y + 42);
DebugUtils.game.stage.context.fillText('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1), x, y + 56);
DebugUtils.game.stage.context.fillText('cx: ' + sprite.cameraView.x + ' cy: ' + sprite.cameraView.y + ' cw: ' + sprite.cameraView.width + ' ch: ' + sprite.cameraView.height + ' cb: ' + sprite.cameraView.bottom + ' cr: ' + sprite.cameraView.right, x, y + 70);
DebugUtils.game.stage.context.fillText('inCamera: ' + DebugUtils.game.renderer.inCamera(DebugUtils.game.camera, sprite), x, y + 84);
}
static renderSpriteBounds(sprite: Sprite, camera?: Camera = null, color?: string = 'rgba(0,255,0,0.2)') {
if (camera == null)
{
camera = DebugUtils.game.camera;
}
//var dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
//var dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
var dx = sprite.worldView.x;
var dy = sprite.worldView.y;
DebugUtils.game.stage.context.fillStyle = color;
DebugUtils.game.stage.context.fillRect(dx, dy, sprite.width, sprite.height);
}
static renderSpritePhysicsBody(sprite: Sprite, camera?: Camera = null, color?: string = 'rgba(255,0,0,0.2)') {
if (camera == null)
{
camera = DebugUtils.game.camera;
}
var dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.body.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
var dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.body.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
DebugUtils.game.stage.context.fillStyle = color;
DebugUtils.game.stage.context.fillRect(dx, dy, sprite.body.width, sprite.body.height);
}
+3 -3
View File
@@ -1,7 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Circle.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/**
* Phaser - PixelUtils
+3 -3
View File
@@ -1,5 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../geom/Point.ts" />
/**
* Phaser - PointUtils
@@ -180,7 +180,7 @@ module Phaser {
* @param x {number} The x coordinate of the anchor point
* @param y {number} The y coordinate of the anchor point
* @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to.
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
* @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)?
* @param {Number} distance An optional distance constraint between the Point and the anchor.
* @return The modified point object
*/
@@ -208,7 +208,7 @@ module Phaser {
* @param x {number} The x coordinate of the anchor point
* @param y {number} The y coordinate of the anchor point
* @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to.
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
* @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)?
* @param {Number} distance An optional distance constraint between the Point and the anchor.
* @return The modified point object
*/
+6 -6
View File
@@ -1,6 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/**
* Phaser - RectangleUtils
@@ -145,12 +145,12 @@ module Phaser {
}
/**
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
* @method intersection
* @param {Rectangle} a - The first Rectangle object.
* @param {Rectangle} b - The second Rectangle object.
* @param {Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return {Rectangle} A Rectangle object that equals the area of intersection. If the rectangles do not intersect, this method returns an empty Rectangle object; that is, a rectangle with its x, y, width, and height properties set to 0.
* @return {Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
**/
static intersection(a: Rectangle, b: Rectangle, out?: Rectangle = new Rectangle): Rectangle {
@@ -194,12 +194,12 @@ module Phaser {
}
/**
* Adds two rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two rectangles.
* Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
* @method union
* @param {Rectangle} a - The first Rectangle object.
* @param {Rectangle} b - The second Rectangle object.
* @param {Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return {Rectangle} A Rectangle object that is the union of the two rectangles.
* @return {Rectangle} A Rectangle object that is the union of the two Rectangles.
**/
static union(a: Rectangle, b: Rectangle, out?: Rectangle = new Rectangle): Rectangle {
return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
+88 -101
View File
@@ -1,7 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../core/Circle.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="RectangleUtils.ts" />
@@ -16,26 +16,58 @@ module Phaser {
export class SpriteUtils {
static _tempPoint: Point;
static _sin: number;
static _cos: number;
/**
* Check whether this object is visible in a specific camera rectangle.
* @param camera {Rectangle} The rectangle you want to check.
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
* Updates a Sprites cameraView Rectangle based on the given camera, sprite world position and rotation
* @param camera {Camera} The Camera to use in the view
* @param sprite {Sprite} The Sprite that will have its cameraView property modified
* @return {Rectangle} A reference to the Sprite.cameraView property
*/
static inCamera(camera: Camera, sprite: Sprite): bool {
static updateCameraView(camera: Camera, sprite: Sprite): Rectangle {
// Object fixed in place regardless of the camera scrolling? Then it's always visible
if (sprite.scrollFactor.x == 0 && sprite.scrollFactor.y == 0)
if (sprite.rotation == 0 || sprite.texture.renderRotation == false)
{
return true;
// Easy out
sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.width * sprite.transform.origin.x));
sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.height * sprite.transform.origin.y));
sprite.cameraView.width = sprite.width;
sprite.cameraView.height = sprite.height;
}
else
{
// If the sprite is rotated around its center we can use this quicker method:
if (sprite.transform.origin.x == 0.5 && sprite.transform.origin.y == 0.5)
{
SpriteUtils._sin = sprite.transform.sin;
SpriteUtils._cos = sprite.transform.cos;
if (SpriteUtils._sin < 0)
{
SpriteUtils._sin = -SpriteUtils._sin;
}
if (SpriteUtils._cos < 0)
{
SpriteUtils._cos = -SpriteUtils._cos;
}
sprite.cameraView.width = Math.round(sprite.height * SpriteUtils._sin + sprite.width * SpriteUtils._cos);
sprite.cameraView.height = Math.round(sprite.height * SpriteUtils._cos + sprite.width * SpriteUtils._sin);
sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.cameraView.width * sprite.transform.origin.x));
sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.cameraView.height * sprite.transform.origin.y));
}
else
{
sprite.cameraView.x = Math.min(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x);
sprite.cameraView.y = Math.min(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y);
sprite.cameraView.width = Math.max(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x) - sprite.cameraView.x;
sprite.cameraView.height = Math.max(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y) - sprite.cameraView.y;
}
}
var dx = sprite.frameBounds.x - (camera.worldView.x * sprite.scrollFactor.x);
var dy = sprite.frameBounds.y - (camera.worldView.y * sprite.scrollFactor.y);
var dw = sprite.frameBounds.width * sprite.scale.x;
var dh = sprite.frameBounds.height * sprite.scale.y;
return (camera.scaledX + camera.worldView.width > this._dx) && (camera.scaledX < this._dx + this._dw) && (camera.scaledY + camera.worldView.height > this._dy) && (camera.scaledY < this._dy + this._dh);
return sprite.cameraView;
}
@@ -111,92 +143,60 @@ module Phaser {
}
*/
/**
* Checks to see if this <code>GameObject</code> were located at the given position, would it overlap the <code>GameObject</code> or <code>Group</code>?
* This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size numbero account.
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
*
* @param X {number} The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
* @param Y {number} The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.
* @param objectOrGroup {object} The object or group being tested.
* @param inScreenSpace {boolean} Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
*
* @return {boolean} Whether or not the two objects overlap.
*/
/*
static overlapsAt(X: number, Y: number, objectOrGroup, inScreenSpace: bool = false, camera: Camera = null): bool {
if (objectOrGroup.isGroup)
{
var results: bool = false;
var basic;
var i: number = 0;
var members = objectOrGroup.members;
while (i < length)
{
if (this.overlapsAt(X, Y, members[i++], inScreenSpace, camera))
{
results = true;
}
}
return results;
}
if (!inScreenSpace)
{
return (objectOrGroup.x + objectOrGroup.width > X) && (objectOrGroup.x < X + this.width) &&
(objectOrGroup.y + objectOrGroup.height > Y) && (objectOrGroup.y < Y + this.height);
}
if (camera == null)
{
camera = this._game.camera;
}
var objectScreenPos: Point = objectOrGroup.getScreenXY(null, Camera);
this._point.x = X - camera.scroll.x * this.scrollFactor.x; //copied from getScreenXY()
this._point.y = Y - camera.scroll.y * this.scrollFactor.y;
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
this._point.y += (this._point.y > 0) ? 0.0000001 : -0.0000001;
return (objectScreenPos.x + objectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
(objectScreenPos.y + objectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
}
*/
/**
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
* Checks to see if the given x and y coordinates overlaps this <code>Sprite</code>, taking scaling and rotation into account.
* The coordinates must be given in world space, not local or camera space.
*
* @param point {Point} The point in world space you want to check.
* @param inScreenSpace {boolean} Whether to take scroll factors into account when checking for overlap.
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
* @param sprite {Sprite} The Sprite to check. It will take scaling and rotation into account.
* @param x {Number} The x coordinate in world space.
* @param y {Number} The y coordinate in world space.
*
* @return Whether or not the point overlaps this object.
*/
static overlapsPoint(sprite: Sprite, point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
static overlapsXY(sprite: Phaser.Sprite, x: number, y: number): bool {
if (!inScreenSpace)
// if rotation == 0 then just do a rect check instead!
if (sprite.transform.rotation == 0)
{
return Phaser.RectangleUtils.containsPoint(sprite.body.bounds, point);
//return (point.x > sprite.x) && (point.x < sprite.x + sprite.width) && (point.y > sprite.y) && (point.y < sprite.y + sprite.height);
return Phaser.RectangleUtils.contains(sprite.cameraView, x, y);
}
if (camera == null)
if ((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0)
{
camera = sprite.game.camera;
return false;
}
//var x: number = point.x - camera.scroll.x;
//var y: number = point.y - camera.scroll.y;
if ((x - sprite.transform.upperRight.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperRight.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) > 0)
{
return false;
}
//this.getScreenXY(this._point, camera);
if ((x - sprite.transform.upperLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) < 0)
{
return false;
}
//return (x > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
if ((x - sprite.transform.bottomLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.bottomLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) > 0)
{
return false;
}
return true;
}
/**
* Checks to see if the given point overlaps this <code>Sprite</code>, taking scaling and rotation into account.
* The point must be given in world space, not local or camera space.
*
* @param sprite {Sprite} The Sprite to check. It will take scaling and rotation into account.
* @param point {Point} The point in world space you want to check.
*
* @return Whether or not the point overlaps this object.
*/
static overlapsPoint(sprite: Sprite, point: Point): bool {
return overlapsXY(sprite, point.x, point.y);
}
/**
@@ -239,8 +239,8 @@ module Phaser {
camera = this._game.camera;
}
point.x = sprite.x - camera.scroll.x * sprite.scrollFactor.x;
point.y = sprite.y - camera.scroll.y * sprite.scrollFactor.y;
point.x = sprite.x - camera.x * sprite.transform.scrollFactor.x;
point.y = sprite.y - camera.y * sprite.transform.scrollFactor.y;
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
@@ -283,19 +283,6 @@ module Phaser {
}
static setOriginToCenter(sprite: Sprite, fromFrameBounds: bool = true, fromBody?: bool = false) {
if (fromFrameBounds)
{
sprite.origin.setTo(sprite.frameBounds.halfWidth, sprite.frameBounds.halfHeight);
}
else if (fromBody)
{
sprite.origin.setTo(sprite.body.bounds.halfWidth, sprite.body.bounds.halfHeight);
}
}
/**
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
+33 -12
View File
@@ -25,27 +25,26 @@ TODO:
* Dispatch world resize event
* Investigate why tweens don't restart after the game pauses
* Fix bug in Tween yoyo + loop combo
* Copy the setTransform from Sprite to Camera
* Move Camera.scroll.x to just Camera.x/y
* Apply Sprite scaling to Body.bounds
* When you modify the sprite x/y directly the body position doesn't update, which leads to weird results. Need to work out who controls who.
* Check that tween pausing works with the new performance.now
* Game.Time should monitor pause duration
* Investigate bug re: tilemap collision and animation frames
* Update tests that use arrow keys and include touch/mouse support (FlxControlHandler style)
* Polygon geom primitive
* If the Camera is larger than the Stage size then the rotation offset isn't correct
* Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
* Bug: Sprite x/y gets shifted if dynamic from the original value
* Input CSS cursor those little 4-way arrows on drag?
* Stage CSS3 transforms!!! Color tints, sepia, greyscale, all of those cool things :)
* Cameras should have option to be input disabled + Pointers should check which camera they are over before doing Sprite selection
* Can Cameras be positioned within the world?
* Added JSON Texture Atlas object support.
* Bug in AnimationManager set frame/frameName - the width/height are trimmed and wrong
* RenderOrderID won't work across cameras - but then neither do Pointers yet anyway
* Add JSON Texture Atlas object support.
* Swap to using time based motion (like the tweens) rather than delta timer - it just doesn't work well on slow phones
* Bug in World drag
* Pointer.getWorldX(camera) needs to take camera scale into consideration
* If stage.clear set to false and game pauses, when it unpauses you still see the pause arrow - resolve this
* Add clip support + shape options to Texture Component.
* Make sure I'm using Point and not Vec2 when it's not a directional vector I need
* Bug with setting scale or anything on a Sprite inside a Group, or maybe group.addNewSprite issue
* Sprite collision events
* See which functions in the input component can move elsewhere (utils)
* Move all of the renderDebugInfo methods to the DebugUtils class
V1.0.0
@@ -91,6 +90,28 @@ V1.0.0
* Vastly improved orientation detection and response speed.
* Added custom callback support for all Touch and Mouse Events so you can easily hook events to custom APIs.
* Updated Game.loader and its methods. You now load images by: game.load.image() and also: game.load.atlas, game.load.audio, game.load.spritesheet, game.load.text. And you start it with game.load.start().
* Added optional frame parameter to Phaser.Sprite (and game.add.sprite) so you can set a frame ID or frame name on construction.
* Fixed bug where passing a texture atlas string would incorrectly skip the frames array.
* Added AnimationManager.autoUpdateBounds to control if a new frame should change the physics bounds of a sprite body or not.
* Added StageScaleMode.pageAlignHorizontally and pageAlignVertically booleans. When true Phaser will set the margin-left and top of the canvas element so that it is positioned in the middle of the page (based only on window.innerWidth).
* Added support for globalCompositeOperation, opaque and backgroundColor to the Sprite.Texture and Camera.Texture components.
* Added ability for a Camera to skew and rotate around an origin.
* Moved the Camera rendering into CanvasRenderer to keep things consistent.
* Added Stage.setImageRenderingCrisp to quickly set the canvas image-rendering to crisp-edges (note: poor browser support atm)
* Sprite.width / height now report the scaled width height, setting them adjusts the scale as it does so.
* Created a Transform component containing scale, skew, rotation, scrollFactor, origin and rotationOffset. Added to Sprite, Camera, Group.
* Created a Texture component containing image data, alpha, flippedX, flippedY, etc. Added to Sprite, Camera, Group.
* Added CameraManager.swap and CameraManager.sort methods and added a z-index property to Camera to control render order.
* Added World.postUpdate loop + Group and Camera postUpdate methods.
* Fixed issue stopping Pointer from working in world coordinates and fixed the world drag example.
* For consistency renamed input.scaledX/Y to input.scale.
* Added input.activePointer which contains a reference to the most recently active pointer.
* Sprite.Transform now has upperLeft, upperRight, bottomLeft and bottomRight Point properties and lots of useful coordinate related methods.
* Camera.inCamera check now uses the Sprite.worldView which finally accurately updates regardless of scale, rotation or rotation origin.
* Added Math.Mat3 for Matrix3 operations (which Sprite.Transform uses) and Math.Mat3Utils for lots of use Mat3 related methods.
* Added SpriteUtils.overlapsXY and overlapsPoint to check if a point is within a sprite, taking scale and rotation into account.
* Added Cache.getImageKeys (and similar) to return an array of all the keys for all currently cached objects.
* Added Group.bringToTop feature. Will sort the Group, move the given sprites z-index to the top and shift the rest down by one.
@@ -169,7 +190,7 @@ V0.9.6
* Added Point.rotate to allow you to rotate a point around another point, with optional distance clamping. Also created test cases.
* Added Group.alpha to apply a globalAlpha before the groups children are rendered. Useful to save on alpha calls.
* Added Group.globalCompositeOperation to apply a composite operation before all of the groups children are rendered.
* Added Camera black list support to Group along with Group.showToCamera, Group.hideFromCamera and Group.clearCameraList
* Added Camera black list support to Sprite and Group along with Camera.show, Camera.hide and Camera.isHidden methods to populate them.
* Added GameMath.rotatePoint to allow for point rotation at any angle around a given anchor and distance
* Updated World.setSize() to optionally update the VerletManager dimensions as well
* Added GameObject.setPosition(x, y)
+47 -27
View File
@@ -69,33 +69,9 @@
<TypeScriptCompile Include="particles\graphic emitter.ts" />
<TypeScriptCompile Include="input\over sprite 1.ts" />
<TypeScriptCompile Include="groups\create group 1.ts" />
<TypeScriptCompile Include="demoscene\ballmover.ts" />
<Content Include="demoscene\ballmover.js">
<DependentUpon>ballmover.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="demoscene\scroller1.ts" />
<TypeScriptCompile Include="demoscene\colorwhirl.ts" />
<Content Include="demoscene\colorwhirl.js">
<DependentUpon>colorwhirl.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="demoscene\fujiboink.ts" />
<TypeScriptCompile Include="demoscene\fruitfall.ts" />
<Content Include="demoscene\fruitfall.js">
<DependentUpon>fruitfall.ts</DependentUpon>
</Content>
<Content Include="demoscene\fujiboink.js">
<DependentUpon>fujiboink.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="demoscene\metalslug.ts" />
<Content Include="demoscene\metalslug.js">
<DependentUpon>metalslug.ts</DependentUpon>
</Content>
<Content Include="demoscene\scroller1.js">
<DependentUpon>scroller1.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="demoscene\starray.ts" />
<Content Include="demoscene\starray.js">
<DependentUpon>starray.ts</DependentUpon>
<TypeScriptCompile Include="cameras\world sprite.ts" />
<Content Include="cameras\world sprite.js">
<DependentUpon>world sprite.ts</DependentUpon>
</Content>
<Content Include="groups\create group 1.js">
<DependentUpon>create group 1.ts</DependentUpon>
@@ -109,6 +85,10 @@
<DependentUpon>swap children.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="input\drag sprite 1.ts" />
<TypeScriptCompile Include="input\bring to top.ts" />
<Content Include="input\bring to top.js">
<DependentUpon>bring to top.ts</DependentUpon>
</Content>
<Content Include="input\drag sprite 1.js">
<DependentUpon>drag sprite 1.ts</DependentUpon>
</Content>
@@ -118,12 +98,20 @@
</Content>
<TypeScriptCompile Include="input\motion lock.ts" />
<TypeScriptCompile Include="input\motion lock 2.ts" />
<TypeScriptCompile Include="input\game scale 1.ts" />
<Content Include="input\game scale 1.js">
<DependentUpon>game scale 1.ts</DependentUpon>
</Content>
<Content Include="input\motion lock 2.js">
<DependentUpon>motion lock 2.ts</DependentUpon>
</Content>
<Content Include="input\motion lock.js">
<DependentUpon>motion lock.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="input\multitouch.ts" />
<Content Include="input\multitouch.js">
<DependentUpon>multitouch.ts</DependentUpon>
</Content>
<Content Include="input\over sprite 1.js">
<DependentUpon>over sprite 1.ts</DependentUpon>
</Content>
@@ -133,6 +121,14 @@
</Content>
<TypeScriptCompile Include="input\touch priority.ts" />
<TypeScriptCompile Include="input\snap 1.ts" />
<TypeScriptCompile Include="input\point in rotated sprite.ts" />
<Content Include="input\point in rotated sprite.js">
<DependentUpon>point in rotated sprite.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="input\rotated sprites.ts" />
<Content Include="input\rotated sprites.js">
<DependentUpon>rotated sprites.ts</DependentUpon>
</Content>
<Content Include="input\snap 1.js">
<DependentUpon>snap 1.ts</DependentUpon>
</Content>
@@ -144,6 +140,18 @@
<DependentUpon>world drag.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="mobile\sprite test 1.ts" />
<TypeScriptCompile Include="misc\point1.ts" />
<Content Include="misc\point1.js">
<DependentUpon>point1.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="misc\point2.ts" />
<Content Include="misc\point2.js">
<DependentUpon>point2.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="misc\point3.ts" />
<Content Include="misc\point3.js">
<DependentUpon>point3.ts</DependentUpon>
</Content>
<Content Include="mobile\sprite test 1.js">
<DependentUpon>sprite test 1.ts</DependentUpon>
</Content>
@@ -201,6 +209,18 @@
<Content Include="scrollzones\skewed scroller.js">
<DependentUpon>skewed scroller.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="sprites\atlas 1.ts" />
<Content Include="sprites\atlas 1.js">
<DependentUpon>atlas 1.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="sprites\atlas 2.ts" />
<Content Include="sprites\atlas 2.js">
<DependentUpon>atlas 2.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="sprites\origin 5.ts" />
<Content Include="sprites\origin 5.js">
<DependentUpon>origin 5.ts</DependentUpon>
</Content>
<Content Include="tweens\tween loop 1.js">
<DependentUpon>tween loop 1.ts</DependentUpon>
</Content>
+28
View File
@@ -0,0 +1,28 @@
{"frames": [
{
"filename": "invader1",
"frame": {"x":0,"y":0,"w":128,"h":104},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":36,"y":73,"w":128,"h":104},
"sourceSize": {"w":200,"h":250}
},
{
"filename": "tennyson",
"frame": {"x":128,"y":0,"w":120,"h":104},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":0,"y":24,"w":120,"h":104},
"sourceSize": {"w":120,"h":128}
}],
"meta": {
"app": "http://www.texturepacker.com",
"version": "1.0",
"image": "invaderpig.png",
"format": "RGBA8888",
"size": {"w":248,"h":104},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:aaccbd2de0ca8112964651683164d103$"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

+4 -4
View File
@@ -15,14 +15,14 @@
}
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.scroll.x -= 4;
game.camera.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
game.camera.scroll.y -= 4;
game.camera.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
function render() {
+4 -4
View File
@@ -30,20 +30,20 @@
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.scroll.x -= 4;
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.scroll.y -= 4;
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
+5 -5
View File
@@ -11,19 +11,19 @@
game.add.sprite(0, 0, 'backdrop');
for(var i = 0; i < 400; i++) {
var tempBall = game.add.sprite(game.world.randomX * 2, game.world.randomY * 2, 'ball');
tempBall.scrollFactor.setTo(2, 2);
tempBall.transform.scrollFactor.setTo(2, 2);
}
}
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.scroll.x -= 4;
game.camera.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
game.camera.scroll.y -= 4;
game.camera.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
function render() {
+5 -5
View File
@@ -22,7 +22,7 @@
for (var i = 0; i < 400; i++)
{
var tempBall:Phaser.Sprite = game.add.sprite(game.world.randomX * 2, game.world.randomY * 2, 'ball');
tempBall.scrollFactor.setTo(2, 2);
tempBall.transform.scrollFactor.setTo(2, 2);
}
}
@@ -31,20 +31,20 @@
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.scroll.x -= 4;
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.scroll.y -= 4;
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
+5 -5
View File
@@ -9,19 +9,19 @@
function create() {
for(var i = 0; i < 10; i++) {
var temp = game.add.sprite(600 + (10 * i), 200 + (10 * i), 'disk');
temp.scrollFactor.setTo(i / 2, i / 2);
temp.transform.scrollFactor.setTo(i / 2, i / 2);
}
}
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.scroll.x -= 4;
game.camera.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
game.camera.scroll.y -= 4;
game.camera.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
function render() {
+5 -5
View File
@@ -19,7 +19,7 @@
for (var i = 0; i < 10; i++)
{
var temp:Phaser.Sprite = game.add.sprite(600 + (10 * i), 200 + (10 * i), 'disk');
temp.scrollFactor.setTo(i / 2, i / 2);
temp.transform.scrollFactor.setTo(i / 2, i / 2);
}
}
@@ -28,20 +28,20 @@
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.scroll.x -= 4;
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.scroll.y -= 4;
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
+62
View File
@@ -0,0 +1,62 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/utils/DebugUtils.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
game.world.setSize(1920, 1200, true);
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('ball', 'assets/sprites/mana_card.png');
game.load.start();
}
var ball;
function create() {
game.add.sprite(0, 0, 'backdrop');
ball = game.add.sprite(200, 200, 'ball');
ball.body.offset.setTo(-16, -16);
ball.body.width = 100;
ball.body.height = 100;
ball.body.velocity.x = 50;
ball.transform.scale.setTo(2, 2);
}
function update() {
/*
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
//ball.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
//ball.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
//ball.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
//ball.y += 4;
}
*/
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
ball.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
ball.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
ball.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
ball.y += 4;
}
}
function render() {
game.camera.renderDebugInfo(32, 32);
Phaser.DebugUtils.renderSpriteInfo(ball, 32, 200);
//Phaser.DebugUtils.renderSpriteBounds(ball);
Phaser.DebugUtils.renderSpritePhysicsBody(ball);
}
})();
+91
View File
@@ -0,0 +1,91 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/utils/DebugUtils.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
game.world.setSize(1920, 1200, true);
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('ball', 'assets/sprites/mana_card.png');
game.load.start();
}
var ball: Phaser.Sprite;
function create() {
game.add.sprite(0, 0, 'backdrop');
ball = game.add.sprite(200, 200, 'ball');
ball.body.offset.setTo(-16, -16);
ball.body.width = 100;
ball.body.height = 100;
ball.body.velocity.x = 50;
ball.transform.scale.setTo(2, 2);
}
function update() {
/*
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
//ball.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
//ball.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
//ball.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
//ball.y += 4;
}
*/
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
ball.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
ball.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
ball.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
ball.y += 4;
}
}
function render() {
game.camera.renderDebugInfo(32, 32);
Phaser.DebugUtils.renderSpriteInfo(ball, 32, 200);
//Phaser.DebugUtils.renderSpriteBounds(ball);
Phaser.DebugUtils.renderSpritePhysicsBody(ball);
}
})();
-18
View File
@@ -1,18 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
(function () {
var game = new Phaser.Game(this, 'demo1', 320, 200, init, create, update);
function init() {
game.load.image('balls', 'assets/sprites/balls.png');
game.load.start();
}
var scroller;
function create() {
scroller = game.add.scrollZone('balls', 0, 0, 800, 612);
game.math.sinCosGenerator(256, 4, 4, 2);
}
function update() {
scroller.currentRegion.scrollSpeed.x = game.math.shiftSinTable();
scroller.currentRegion.scrollSpeed.y = game.math.shiftCosTable();
}
})();
-31
View File
@@ -1,31 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
(function () {
var game = new Phaser.Game(this, 'demo1', 320, 200, init, create, update);
function init() {
game.load.image('balls', 'assets/sprites/balls.png');
game.load.start();
}
var scroller: Phaser.ScrollZone;
function create() {
scroller = game.add.scrollZone('balls', 0, 0, 800, 612);
game.math.sinCosGenerator(256, 4, 4, 2);
}
function update() {
scroller.currentRegion.scrollSpeed.x = game.math.shiftSinTable();
scroller.currentRegion.scrollSpeed.y = game.math.shiftCosTable();
}
})();
-22
View File
@@ -1,22 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('swirl', 'assets/pics/color_wheel_swirl.png');
game.load.start();
}
var swirl;
function create() {
// Here we'll assign the new sprite to the local swirl variable
swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl');
// Increase the size of the sprite a little so it covers the edges of the stage
swirl.scale.setTo(1.4, 1.4);
// Set the origin to the middle of the Sprite to get the effect we need
swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight);
// Create a tween that rotates a full 306 degrees and then repeats (loop set to true)
game.add.tween(swirl).to({
angle: 360
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
}
})();
-33
View File
@@ -1,33 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('swirl', '../assets/pics/color_wheel_swirl.png');
game.load.start();
}
var swirl: Phaser.Sprite;
function create() {
// Here we'll assign the new sprite to the local swirl variable
swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl');
// Increase the size of the sprite a little so it covers the edges of the stage
swirl.scale.setTo(1.4, 1.4);
// Set the origin to the middle of the Sprite to get the effect we need
swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight);
// Create a tween that rotates a full 306 degrees and then repeats (loop set to true)
game.add.tween(swirl).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
}
})();
-44
View File
@@ -1,44 +0,0 @@
var __extends = this.__extends || function (d, b) {
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/Particle.ts" />
/// <reference path="../../Phaser/gameobjects/Emitter.ts" />
var fruitParticle = (function (_super) {
__extends(fruitParticle, _super);
function fruitParticle(game) {
_super.call(this, game);
var s = [
'carrot',
'melon',
'eggplant',
'mushroom',
'pineapple'
];
this.texture.loadImage(game.math.getRandom(s));
}
return fruitParticle;
})(Phaser.Particle);
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
var emitter;
function init() {
game.load.image('carrot', '../assets/sprites/carrot.png');
game.load.image('melon', '../assets/sprites/melon.png');
game.load.image('eggplant', '../assets/sprites/eggplant.png');
game.load.image('mushroom', '../assets/sprites/mushroom.png');
game.load.image('pineapple', '../assets/sprites/pineapple.png');
game.load.start();
}
function create() {
emitter = game.add.emitter(game.stage.centerX, 50);
emitter.gravity = 100;
// Here we tell the emitter to use our customParticle class
// The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird
emitter.particleClass = fruitParticle;
emitter.makeParticles(null, 50, false, 0);
emitter.start(false, 10, 0.05);
}
})();
-50
View File
@@ -1,50 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/Particle.ts" />
/// <reference path="../../Phaser/gameobjects/Emitter.ts" />
class fruitParticle extends Phaser.Particle {
constructor(game:Phaser.Game) {
super(game);
var s = ['carrot', 'melon', 'eggplant', 'mushroom', 'pineapple'];
this.texture.loadImage(game.math.getRandom(s));
}
}
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
var emitter: Phaser.Emitter;
function init() {
game.load.image('carrot', '../assets/sprites/carrot.png');
game.load.image('melon', '../assets/sprites/melon.png');
game.load.image('eggplant', '../assets/sprites/eggplant.png');
game.load.image('mushroom', '../assets/sprites/mushroom.png');
game.load.image('pineapple', '../assets/sprites/pineapple.png');
game.load.start();
}
function create() {
emitter = game.add.emitter(game.stage.centerX, 50);
emitter.gravity = 100;
// Here we tell the emitter to use our customParticle class
// The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird
emitter.particleClass = fruitParticle;
emitter.makeParticles(null, 50, false, 0);
emitter.start(false, 10, 0.05);
}
})();
-42
View File
@@ -1,42 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('fuji', '../assets/pics/atari_fujilogo.png');
game.load.start();
}
var fuji;
var tweenUp;
var tweenDown;
function create() {
game.stage.backgroundColor = 'rgb(0,0,100)';
// Here we'll assign the new sprite to the local fuji variable
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
// The sprite is 320 x 200 pixels in size
// Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time
fuji.origin.setTo(160, 100);
game.add.tween(fuji).to({
angle: 360
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
tweenUp = game.add.tween(fuji.scale);
tweenUp.onComplete.add(scaleDown, this);
tweenDown = game.add.tween(fuji.scale);
tweenDown.onComplete.add(scaleUp, this);
scaleUp();
}
function scaleUp() {
tweenUp.to({
x: 2,
y: 2
}, 1000, Phaser.Easing.Elastic.Out);
tweenUp.start();
}
function scaleDown() {
tweenDown.to({
x: 0.5,
y: 0.5
}, 1000, Phaser.Easing.Elastic.Out);
tweenDown.start();
}
})();
-56
View File
@@ -1,56 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('fuji', '../assets/pics/atari_fujilogo.png');
game.load.start();
}
var fuji: Phaser.Sprite;
var tweenUp: Phaser.Tween;
var tweenDown: Phaser.Tween;
function create() {
game.stage.backgroundColor = 'rgb(0,0,100)';
// Here we'll assign the new sprite to the local fuji variable
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
// The sprite is 320 x 200 pixels in size
// Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time
fuji.origin.setTo(160, 100);
game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
tweenUp = game.add.tween(fuji.scale);
tweenUp.onComplete.add(scaleDown, this);
tweenDown = game.add.tween(fuji.scale);
tweenDown.onComplete.add(scaleUp, this);
scaleUp();
}
function scaleUp() {
tweenUp.to({ x: 2, y: 2 }, 1000, Phaser.Easing.Elastic.Out);
tweenUp.start();
}
function scaleDown() {
tweenDown.to({ x: 0.5, y: 0.5 }, 1000, Phaser.Easing.Elastic.Out);
tweenDown.start();
}
})();
-32
View File
@@ -1,32 +0,0 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1 maximum-scale=1 user-scalable=0" />
<title>Phaser does DemoScene</title>
<style>
body {
padding: 0;
margin: 0;
}
canvas {
float: left;
}
</style>
<script>
var PhaserGlobal = { disableAudio: true }
</script>
<script src="../phaser.js"></script>
<script src="ballmover.js"></script>
<script src="scroller1.js"></script>
<script src="starray.js"></script>
<script src="colorwhirl.js"></script>
<script src="fujiboink.js"></script>
<script src="metalslug.js"></script>
<script src="fruitfall.js"></script>
</head>
<body>
</body>
</html>
-22
View File
@@ -1,22 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.spritesheet('monster', '../assets/sprites/metalslug_monster39x40.png', 39, 40);
game.load.start();
}
var monster;
function create() {
game.stage.backgroundColor = 'rgb(50,10,10)';
// Notice the use of 'stage.centerX' - this places the sprite in the middle of the stage without needing to do any extra math
monster = game.add.sprite(100, 50, 'monster');
// For this animation we pass 'null' for the frames, because we're going to use them all
// And we set the frame rate (30) and loop status (true) when we add the animation
// If the frame rate and looping is never going to change then it's easier to do it here
monster.animations.add('walk', null, 30, true);
// Then you can just call 'play' on its own with no other values to start things going
monster.animations.play('walk');
monster.scale.setTo(3, 3);
}
})();
-36
View File
@@ -1,36 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.spritesheet('monster', '../assets/sprites/metalslug_monster39x40.png', 39, 40);
game.load.start();
}
var monster: Phaser.Sprite;
function create() {
game.stage.backgroundColor = 'rgb(50,10,10)';
// Notice the use of 'stage.centerX' - this places the sprite in the middle of the stage without needing to do any extra math
monster = game.add.sprite(100, 50, 'monster');
// For this animation we pass 'null' for the frames, because we're going to use them all
// And we set the frame rate (30) and loop status (true) when we add the animation
// If the frame rate and looping is never going to change then it's easier to do it here
monster.animations.add('walk', null, 30, true);
// Then you can just call 'play' on its own with no other values to start things going
monster.animations.play('walk');
monster.scale.setTo(3, 3);
}
})();
-12
View File
@@ -1,12 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
game.load.image('crystal', '../assets/pics/jim_sachs_time_crystal.png');
game.load.start();
}
function create() {
game.add.scrollZone('crystal').setSpeed(4, 2);
}
})();
-21
View File
@@ -1,21 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
game.load.image('crystal', '../assets/pics/jim_sachs_time_crystal.png');
game.load.start();
}
function create() {
game.add.scrollZone('crystal').setSpeed(4, 2);
}
})();
-31
View File
@@ -1,31 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
game.load.image('starray', '../assets/pics/auto_scroll_landscape.png');
game.load.start();
}
function create() {
var zone = game.add.scrollZone('starray');
// Hide the default region (the full image)
zone.currentRegion.visible = false;
var y = 0;
var speed = 16;
// The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down)
for(var z = 0; z < 32; z++) {
zone.addRegion(0, y, 640, 10, speed);
if(z <= 15) {
speed -= 1;
} else {
speed += 1;
}
if(z == 15) {
y = 240;
speed += 1;
} else {
y += 10;
}
}
}
})();
-53
View File
@@ -1,53 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/gameobjects/ScrollZone.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 320, 200, init, create);
function init() {
game.load.image('starray', '../assets/pics/auto_scroll_landscape.png');
game.load.start();
}
function create() {
var zone: Phaser.ScrollZone = game.add.scrollZone('starray');
// Hide the default region (the full image)
zone.currentRegion.visible = false;
var y:number = 0;
var speed:number = 16;
// The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down)
for (var z:number = 0; z < 32; z++)
{
zone.addRegion(0, y, 640, 10, speed);
if (z <= 15)
{
speed -= 1;
}
else
{
speed += 1;
}
if (z == 15)
{
y = 240;
speed += 1;
}
else
{
y += 10;
}
}
}
})();
-1
View File
@@ -93,7 +93,6 @@ if (isset($_GET['m']))
<a href="<?php echo $js?>" class="button play">View JavaScript</a>
<a href="<?php echo $ts?>" class="button play">View TypeScript</a>
<div id="game"></div>
<p>You'll learn best from these Tests by viewing the source code.<br />
+28
View File
@@ -0,0 +1,28 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('atari4', 'assets/sprites/atari800.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
game.load.image('firstaid', 'assets/sprites/firstaid.png');
game.load.image('diamond', 'assets/sprites/diamond.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.start();
}
function create() {
// This returns an array of all the image keys in the cache
var images = game.cache.getImageKeys();
// Now let's create some random sprites and enable them all for drag and 'bring to top'
for(var i = 0; i < 20; i++) {
var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, game.rnd.pick(images));
tempSprite.input.start(i, false, true);
tempSprite.input.enableDrag(false, true);
}
}
function render() {
game.input.renderDebugInfo(32, 32);
}
})();
+40
View File
@@ -0,0 +1,40 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('atari4', 'assets/sprites/atari800.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
game.load.image('firstaid', 'assets/sprites/firstaid.png');
game.load.image('diamond', 'assets/sprites/diamond.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.start();
}
function create() {
// This returns an array of all the image keys in the cache
var images = game.cache.getImageKeys()
// Now let's create some random sprites and enable them all for drag and 'bring to top'
for (var i = 0; i < 20; i++)
{
var tempSprite: Phaser.Sprite = game.add.sprite(game.stage.randomX, game.stage.randomY, game.rnd.pick(images));
tempSprite.input.start(i, false, true);
tempSprite.input.enableDrag(false, true);
}
}
function render() {
game.input.renderDebugInfo(32, 32);
}
})();
+1
View File
@@ -18,6 +18,7 @@
}
function render() {
game.input.renderDebugInfo(32, 32);
//game.input.mousePointer.renderDebug(32, 32);
sprite.input.renderDebugInfo(300, 32);
}
})();
+35
View File
@@ -0,0 +1,35 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
// Here we create a tiny game (320x240 in size)
var game = new Phaser.Game(this, 'game', 320, 240, init, create, update, render);
function init() {
// This sets a limit on the up-scale
game.stage.scale.maxWidth = 800;
game.stage.scale.maxHeight = 600;
// Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally
game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
game.load.image('melon', 'assets/sprites/melon.png');
game.load.start();
}
function create() {
game.world.setSize(2000, 2000);
for(var i = 0; i < 1000; i++) {
game.add.sprite(game.world.randomX, game.world.randomY, 'melon');
}
}
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
game.camera.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
game.camera.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
game.camera.y += 4;
}
}
function render() {
game.input.renderDebugInfo(16, 16);
}
})();
+62
View File
@@ -0,0 +1,62 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
// Here we create a tiny game (320x240 in size)
var game = new Phaser.Game(this, 'game', 320, 240, init, create, update, render);
function init() {
// This sets a limit on the up-scale
game.stage.scale.maxWidth = 800;
game.stage.scale.maxHeight = 600;
// Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally
game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
game.load.image('melon', 'assets/sprites/melon.png');
game.load.start();
}
function create() {
game.world.setSize(2000, 2000);
for (var i = 0; i < 1000; i++)
{
game.add.sprite(game.world.randomX, game.world.randomY, 'melon');
}
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
}
}
function render() {
game.input.renderDebugInfo(16, 16);
}
})();
+10
View File
@@ -0,0 +1,10 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, null, null, null, render);
function render() {
game.input.pointer1.renderDebug();
game.input.pointer2.renderDebug();
game.input.pointer3.renderDebug();
game.input.pointer4.renderDebug();
}
})();
+16
View File
@@ -0,0 +1,16 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, null, null, null, render);
function render() {
game.input.pointer1.renderDebug();
game.input.pointer2.renderDebug();
game.input.pointer3.renderDebug();
game.input.pointer4.renderDebug();
}
})();
+2 -2
View File
@@ -10,8 +10,8 @@
function create() {
// Create a load of sprites
for(var i = 0; i < 26; i++) {
var tempSprite = game.add.sprite(i * 32, 100, 'sprite', Phaser.Types.BODY_DYNAMIC);
tempSprite.input.enabled = true;
var tempSprite = game.add.sprite(i * 32, 100, 'sprite');
tempSprite.input.start(0, false, true);
tempSprite.events.onInputOver.add(dropSprite, this);
}
}
+2 -2
View File
@@ -19,8 +19,8 @@
// Create a load of sprites
for (var i = 0; i < 26; i++)
{
var tempSprite: Phaser.Sprite = game.add.sprite(i * 32, 100, 'sprite', Phaser.Types.BODY_DYNAMIC);
tempSprite.input.enabled = true;
var tempSprite: Phaser.Sprite = game.add.sprite(i * 32, 100, 'sprite');
tempSprite.input.start(0, false, true);
tempSprite.events.onInputOver.add(dropSprite, this);
}
+39
View File
@@ -0,0 +1,39 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
game.load.image('sprite', 'assets/sprites/atari130xe.png');
game.load.start();
}
var sprite;
var rotate = false;
function create() {
sprite = game.add.sprite(200, 200, 'sprite');
game.input.onTap.add(rotateIt, this);
}
function rotateIt() {
if(rotate == false) {
rotate = true;
} else {
rotate = false;
}
}
var inPoint = false;
function update() {
if(rotate) {
sprite.rotation++;
}
inPoint = Phaser.SpriteUtils.overlapsXY(sprite, game.input.x, game.input.y);
}
function render() {
game.stage.context.save();
game.stage.context.fillStyle = 'rgb(255,0,255)';
game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
game.input.renderDebugInfo(32, 32);
game.stage.context.fillText('in: ' + inPoint, 300, 32);
game.stage.context.restore();
}
})();
+60
View File
@@ -0,0 +1,60 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
game.load.image('sprite', 'assets/sprites/atari130xe.png');
game.load.start();
}
var sprite: Phaser.Sprite;
var rotate: bool = false;
function create() {
sprite = game.add.sprite(200, 200, 'sprite');
game.input.onTap.add(rotateIt, this);
}
function rotateIt() {
if (rotate == false) { rotate = true; } else { rotate = false; }
}
var inPoint: bool = false;
function update() {
if (rotate)
{
sprite.rotation++;
}
inPoint = Phaser.SpriteUtils.overlapsXY(sprite, game.input.x, game.input.y);
}
function render() {
game.stage.context.save();
game.stage.context.fillStyle = 'rgb(255,0,255)';
game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
game.input.renderDebugInfo(32, 32);
game.stage.context.fillText('in: ' + inPoint, 300, 32);
game.stage.context.restore();
}
})();
+33
View File
@@ -0,0 +1,33 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.start();
}
var atari1;
var atari2;
var sonic;
function create() {
atari1 = game.add.sprite(200, 200, 'atari1');
atari2 = game.add.sprite(500, 400, 'atari2');
sonic = game.add.sprite(400, 500, 'sonic');
atari1.origin.setTo(0.5, 0.5);
atari1.rotation = 35;
atari2.origin.setTo(1, 1);
atari2.rotation = 80;
sonic.rotation = 140;
atari1.input.start(0, false, true);
atari2.input.start(1, false, true);
sonic.input.start(2, false, true);
atari1.input.enableDrag();
atari2.input.enableDrag();
sonic.input.enableDrag();
}
function render() {
game.input.renderDebugInfo(32, 32);
}
})();
+49
View File
@@ -0,0 +1,49 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.start();
}
var atari1: Phaser.Sprite;
var atari2: Phaser.Sprite;
var sonic: Phaser.Sprite;
function create() {
atari1 = game.add.sprite(200, 200, 'atari1');
atari2 = game.add.sprite(500, 400, 'atari2');
sonic = game.add.sprite(400, 500, 'sonic');
atari1.origin.setTo(0.5, 0.5);
atari1.rotation = 35;
atari2.origin.setTo(1, 1);
atari2.rotation = 80;
sonic.rotation = 140;
atari1.input.start(0, false, true);
atari2.input.start(1, false, true);
sonic.input.start(2, false, true);
atari1.input.enableDrag();
atari2.input.enableDrag();
sonic.input.enableDrag();
}
function render() {
game.input.renderDebugInfo(32, 32);
}
})();
+5 -4
View File
@@ -21,19 +21,20 @@
}
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.scroll.x -= 4;
game.camera.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
game.camera.scroll.y -= 4;
game.camera.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
function render() {
game.camera.renderDebugInfo(32, 32);
test.body.renderDebugInfo(300, 32);
Phaser.DebugUtils.renderSpriteInfo(test, 32, 200);
game.input.renderDebugInfo(300, 200);
}
})();
+6 -4
View File
@@ -40,20 +40,20 @@
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.scroll.x -= 4;
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.scroll.x += 4;
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.scroll.y -= 4;
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.scroll.y += 4;
game.camera.y += 4;
}
}
@@ -66,6 +66,8 @@
Phaser.DebugUtils.renderSpriteInfo(test, 32, 200);
game.input.renderDebugInfo(300, 200);
}
})();

Some files were not shown because too many files have changed in this diff Show More