mirror of
https://github.com/wassname/phaser.git
synced 2026-08-04 13:14:14 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ef0750c07 | ||
|
|
67bf221073 | ||
|
|
94add2ea6e | ||
|
|
c7485301ca | ||
|
|
c5ace72180 | ||
|
|
bd54460e80 | ||
|
|
e2141c91a6 | ||
|
|
0b2d818ba8 | ||
|
|
05cc32fbc9 | ||
|
|
53aa43566e | ||
|
|
55568592b5 | ||
|
|
a6e8436e6d | ||
|
|
3cdd2baff0 | ||
|
|
ce7bfd1fc2 | ||
|
|
8fc31ed83b | ||
|
|
1c311a73df | ||
|
|
0adbf1d92f | ||
|
|
aaaaf7ede3 | ||
|
|
77582fb1ed | ||
|
|
2a8447f64e | ||
|
|
deb37e9a90 | ||
|
|
ca932038fb | ||
|
|
00ef200914 | ||
|
|
e88c48641d | ||
|
|
1052df6660 | ||
|
|
4be5a10e44 | ||
|
|
5cf8b846f8 | ||
|
|
9da64e6baf | ||
|
|
98693cb418 | ||
|
|
b1a33cc593 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 204 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
+82
-36
@@ -3,6 +3,42 @@ module.exports = function (grunt) {
|
|||||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||||
|
|
||||||
|
var wrapPhaserInUmd = function(content, isAddon) {
|
||||||
|
var replacement = [
|
||||||
|
'(function (root, factory) {',
|
||||||
|
' if (typeof exports === \'object\') {',
|
||||||
|
' module.exports = factory();',
|
||||||
|
' } else if (typeof define === \'function\' && define.amd) {',
|
||||||
|
' define(factory);',
|
||||||
|
' } else {',
|
||||||
|
' root.Phaser = factory();',
|
||||||
|
' }',
|
||||||
|
'}(this, function () {',
|
||||||
|
content,
|
||||||
|
'return Phaser;',
|
||||||
|
'}));'
|
||||||
|
];
|
||||||
|
return replacement.join('\n');
|
||||||
|
};
|
||||||
|
|
||||||
|
var wrapAddonInUmd = function(content) {
|
||||||
|
var replacement = [
|
||||||
|
'(function (root, factory) {',
|
||||||
|
' if (typeof exports === \'object\') {',
|
||||||
|
' module.exports = factory(require(\'phaser\'));',
|
||||||
|
' } else if (typeof define === \'function\' && define.amd) {',
|
||||||
|
' define([\'phaser\'], factory);',
|
||||||
|
' } else {',
|
||||||
|
' factory(root.Phaser);',
|
||||||
|
' }',
|
||||||
|
'}(this, function (Phaser) {',
|
||||||
|
content,
|
||||||
|
'return Phaser;',
|
||||||
|
'}));'
|
||||||
|
];
|
||||||
|
return replacement.join('\n');
|
||||||
|
};
|
||||||
|
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
pkg: grunt.file.readJSON('package.json'),
|
||||||
typescript: {
|
typescript: {
|
||||||
@@ -10,49 +46,59 @@ module.exports = function (grunt) {
|
|||||||
src: ['Phaser/**/*.ts'],
|
src: ['Phaser/**/*.ts'],
|
||||||
dest: 'build/phaser.js',
|
dest: 'build/phaser.js',
|
||||||
options: {
|
options: {
|
||||||
target: 'ES5'
|
target: 'ES5',
|
||||||
|
declaration: true,
|
||||||
|
comments: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fx: {
|
||||||
|
src: ['SpecialFX/**/*.ts'],
|
||||||
|
dest: 'build/phaser-fx.js',
|
||||||
|
options: {
|
||||||
|
target: 'ES5',
|
||||||
|
declaration: true,
|
||||||
|
comments: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
main: {
|
main: {
|
||||||
files: [{
|
files: [{
|
||||||
src: 'build/phaser.js',
|
src: 'build/phaser.js',
|
||||||
dest: 'Tests/phaser.js'
|
dest: 'Tests/phaser.js'
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
amd: {
|
fx: {
|
||||||
files: [{
|
files: [{
|
||||||
src: 'build/phaser.js',
|
src: 'build/phaser-fx.js',
|
||||||
dest: 'build/phaser.amd.js'
|
dest: 'Tests/phaser-fx.js'
|
||||||
}],
|
}]
|
||||||
options: {
|
},
|
||||||
processContent: function(content) {
|
mainAmd: {
|
||||||
var replacement = [
|
files: [{
|
||||||
'(function (root, factory) {',
|
src: 'build/phaser.js',
|
||||||
' if (typeof exports === \'object\') {',
|
dest: 'build/phaser.amd.js'
|
||||||
' module.exports = factory();',
|
}],
|
||||||
' } else if (typeof define === \'function\' && define.amd) {',
|
options: {
|
||||||
' define(factory);',
|
processContent: wrapPhaserInUmd
|
||||||
' } else {',
|
}
|
||||||
' root.Phaser = factory();',
|
},
|
||||||
' }',
|
fxAmd: {
|
||||||
'}(this, function () {',
|
files: [{
|
||||||
content,
|
src: 'build/phaser-fx.js',
|
||||||
'return Phaser;',
|
dest: 'build/phaser-fx.amd.js'
|
||||||
'}));'
|
}],
|
||||||
];
|
options: {
|
||||||
return replacement.join('\n');
|
processContent: wrapAddonInUmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
watch: {
|
||||||
watch: {
|
|
||||||
files: '**/*.ts',
|
files: '**/*.ts',
|
||||||
tasks: ['typescript', 'copy']
|
tasks: ['typescript', 'copy']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask('default', ['watch']);
|
grunt.registerTask('default', ['typescript', 'copy', 'watch']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ module Phaser {
|
|||||||
|
|
||||||
export class AnimationManager {
|
export class AnimationManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AnimationManager constructor
|
||||||
|
* Create a new <code>AnimationManager</code>.
|
||||||
|
*
|
||||||
|
* @param parent {Sprite} Owner sprite of this manager.
|
||||||
|
*/
|
||||||
constructor(game: Game, parent: Sprite) {
|
constructor(game: Game, parent: Sprite) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -24,16 +30,47 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to its owner sprite.
|
||||||
|
*/
|
||||||
private _parent: Sprite;
|
private _parent: Sprite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Animation key-value container.
|
||||||
|
*/
|
||||||
private _anims: {};
|
private _anims: {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index of current frame.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _frameIndex: number;
|
private _frameIndex: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data contains animation frames.
|
||||||
|
* @type {FrameData}
|
||||||
|
*/
|
||||||
private _frameData: FrameData = null;
|
private _frameData: FrameData = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps track of the current animation being played.
|
||||||
|
*/
|
||||||
public currentAnim: Animation;
|
public currentAnim: Animation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps track of the current frame of animation.
|
||||||
|
*/
|
||||||
public currentFrame: Frame = null;
|
public currentFrame: Frame = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load animation frame data.
|
||||||
|
* @param frameData Data to be loaded.
|
||||||
|
*/
|
||||||
public loadFrameData(frameData: FrameData) {
|
public loadFrameData(frameData: FrameData) {
|
||||||
|
|
||||||
this._frameData = frameData;
|
this._frameData = frameData;
|
||||||
@@ -42,7 +79,16 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true) {
|
/**
|
||||||
|
* Add a new animation.
|
||||||
|
* @param name {string} What this animation should be called (e.g. "run").
|
||||||
|
* @param frames {any[]} An array of numbers/strings indicating what frames to play in what order (e.g. [1, 2, 3] or ['run0', 'run1', run2]).
|
||||||
|
* @param frameRate {number} The speed in frames per second that the animation should play at (e.g. 60 fps).
|
||||||
|
* @param loop {boolean} Whether or not the animation is looped or just plays once.
|
||||||
|
* @param useNumericIndex {boolean} Use number indexes instead of string indexes?
|
||||||
|
* @return {Animation} The Animation that was created
|
||||||
|
*/
|
||||||
|
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true): Animation {
|
||||||
|
|
||||||
if (this._frameData == null)
|
if (this._frameData == null)
|
||||||
{
|
{
|
||||||
@@ -72,8 +118,16 @@ module Phaser {
|
|||||||
this.currentAnim = this._anims[name];
|
this.currentAnim = this._anims[name];
|
||||||
this.currentFrame = this.currentAnim.currentFrame;
|
this.currentFrame = this.currentAnim.currentFrame;
|
||||||
|
|
||||||
|
return this._anims[name];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the frames is valid.
|
||||||
|
* @param frames {any[]} Frames to be validated.
|
||||||
|
* @param useNumericIndex {boolean} Does these frames use number indexes or string indexes?
|
||||||
|
* @return {boolean} True if they're valid, otherwise return false.
|
||||||
|
*/
|
||||||
private validateFrames(frames: any[], useNumericIndex: bool): bool {
|
private validateFrames(frames: any[], useNumericIndex: bool): bool {
|
||||||
|
|
||||||
for (var i = 0; i < frames.length; i++)
|
for (var i = 0; i < frames.length; i++)
|
||||||
@@ -98,6 +152,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play animation with specific name.
|
||||||
|
* @param name {string} The string name of the animation you want to play.
|
||||||
|
* @param frameRate {number} FrameRate you want to specify instead of using default.
|
||||||
|
* @param loop {boolean} Whether or not the animation is looped or just plays once.
|
||||||
|
*/
|
||||||
public play(name: string, frameRate?: number = null, loop?: bool) {
|
public play(name: string, frameRate?: number = null, loop?: bool) {
|
||||||
|
|
||||||
if (this._anims[name])
|
if (this._anims[name])
|
||||||
@@ -118,6 +178,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop animation by name.
|
||||||
|
* Current animation will be automatically set to the stopped one.
|
||||||
|
*/
|
||||||
public stop(name: string) {
|
public stop(name: string) {
|
||||||
|
|
||||||
if (this._anims[name])
|
if (this._anims[name])
|
||||||
@@ -128,13 +192,16 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update animation and parent sprite's bounds.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
if (this.currentAnim && this.currentAnim.update() == true)
|
if (this.currentAnim && this.currentAnim.update() == true)
|
||||||
{
|
{
|
||||||
this.currentFrame = this.currentAnim.currentFrame;
|
this.currentFrame = this.currentAnim.currentFrame;
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
this._parent.frameBounds.width = this.currentFrame.width;
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
this._parent.frameBounds.height = this.currentFrame.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -144,7 +211,15 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get frameTotal(): number {
|
public get frameTotal(): number {
|
||||||
return this._frameData.total;
|
|
||||||
|
if (this._frameData)
|
||||||
|
{
|
||||||
|
return this._frameData.total;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get frame(): number {
|
public get frame(): number {
|
||||||
@@ -157,8 +232,8 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
this.currentFrame = this._frameData.getFrame(value);
|
this.currentFrame = this._frameData.getFrame(value);
|
||||||
|
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
this._parent.frameBounds.width = this.currentFrame.width;
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
this._parent.frameBounds.height = this.currentFrame.height;
|
||||||
this._frameIndex = value;
|
this._frameIndex = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,13 +249,26 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
this.currentFrame = this._frameData.getFrameByName(value);
|
this.currentFrame = this._frameData.getFrameByName(value);
|
||||||
|
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
this._parent.frameBounds.width = this.currentFrame.width;
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
this._parent.frameBounds.height = this.currentFrame.height;
|
||||||
this._frameIndex = this.currentFrame.index;
|
this._frameIndex = this.currentFrame.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all related references
|
||||||
|
*/
|
||||||
|
public destroy() {
|
||||||
|
|
||||||
|
this._anims = {};
|
||||||
|
this._frameData = null;
|
||||||
|
this._frameIndex = 0;
|
||||||
|
this.currentAnim = null;
|
||||||
|
this.currentFrame = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+14
-2
@@ -23,6 +23,8 @@ module Phaser {
|
|||||||
this.visible = true;
|
this.visible = true;
|
||||||
this.alive = true;
|
this.alive = true;
|
||||||
this.isGroup = false;
|
this.isGroup = false;
|
||||||
|
this.ignoreGlobalUpdate = false;
|
||||||
|
this.ignoreGlobalRender = false;
|
||||||
this.ignoreDrawDebug = false;
|
this.ignoreDrawDebug = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -70,6 +72,16 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
public alive: bool;
|
public alive: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting this to true will prevent the object from being updated during the main game loop (you will have to call update on it yourself)
|
||||||
|
*/
|
||||||
|
public ignoreGlobalUpdate: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting this to true will prevent the object from being rendered during the main game loop (you will have to call render on it yourself)
|
||||||
|
*/
|
||||||
|
public ignoreGlobalRender: bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setting this to true will prevent the object from appearing
|
* Setting this to true will prevent the object from appearing
|
||||||
* when the visual debug mode in the debugger overlay is toggled on.
|
* when the visual debug mode in the debugger overlay is toggled on.
|
||||||
@@ -93,7 +105,7 @@ module Phaser {
|
|||||||
* Override this to update your class's position and appearance.
|
* Override this to update your class's position and appearance.
|
||||||
* This is where most of your game rules and behavioral code will go.
|
* This is where most of your game rules and behavioral code will go.
|
||||||
*/
|
*/
|
||||||
public update() {
|
public update(forceUpdate?: bool = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,7 +114,7 @@ module Phaser {
|
|||||||
public postUpdate() {
|
public postUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+116
-2
@@ -11,6 +11,9 @@ module Phaser {
|
|||||||
|
|
||||||
export class Cache {
|
export class Cache {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache constructor
|
||||||
|
*/
|
||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -22,19 +25,53 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas key-value container.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _canvases;
|
private _canvases;
|
||||||
|
/**
|
||||||
|
* Image key-value container.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _images;
|
private _images;
|
||||||
|
/**
|
||||||
|
* Sound key-value container.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _sounds;
|
private _sounds;
|
||||||
|
/**
|
||||||
|
* Text key-value container.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _text;
|
private _text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new canvas.
|
||||||
|
* @param key {string} Asset key for this canvas.
|
||||||
|
* @param canvas {HTMLCanvasElement} Canvas DOM element.
|
||||||
|
* @param context {CanvasRenderingContext2D} Render context of this canvas.
|
||||||
|
*/
|
||||||
public addCanvas(key: string, canvas: HTMLCanvasElement, context: CanvasRenderingContext2D) {
|
public addCanvas(key: string, canvas: HTMLCanvasElement, context: CanvasRenderingContext2D) {
|
||||||
|
|
||||||
this._canvases[key] = { canvas: canvas, context: context };
|
this._canvases[key] = { canvas: canvas, context: context };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new sprite sheet.
|
||||||
|
* @param key {string} Asset key for the sprite sheet.
|
||||||
|
* @param url {string} URL of this sprite sheet file.
|
||||||
|
* @param data {object} Extra sprite sheet data.
|
||||||
|
* @param frameWidth {number} Width of the sprite sheet.
|
||||||
|
* @param frameHeight {number} Height of the sprite sheet.
|
||||||
|
* @param frameMax {number} How many frames stored in the sprite sheet.
|
||||||
|
*/
|
||||||
public addSpriteSheet(key: string, url: string, data, frameWidth: number, frameHeight: number, frameMax: number) {
|
public addSpriteSheet(key: string, url: string, data, frameWidth: number, frameHeight: number, frameMax: number) {
|
||||||
|
|
||||||
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
|
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
|
||||||
@@ -42,25 +79,58 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTextureAtlas(key: string, url: string, data, jsonData) {
|
/**
|
||||||
|
* Add a new texture atlas.
|
||||||
|
* @param key {string} Asset key for the texture atlas.
|
||||||
|
* @param url {string} URL of this texture atlas file.
|
||||||
|
* @param data {object} Extra texture atlas data.
|
||||||
|
* @param atlasData {object} Texture atlas frames data.
|
||||||
|
*/
|
||||||
|
public addTextureAtlas(key: string, url: string, data, atlasData, format) {
|
||||||
|
|
||||||
this._images[key] = { url: url, data: data, spriteSheet: true };
|
this._images[key] = { url: url, data: data, spriteSheet: true };
|
||||||
this._images[key].frameData = AnimationLoader.parseJSONData(this._game, jsonData);
|
|
||||||
|
if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
|
||||||
|
{
|
||||||
|
this._images[key].frameData = AnimationLoader.parseJSONData(this._game, atlasData);
|
||||||
|
}
|
||||||
|
else if (format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
|
||||||
|
{
|
||||||
|
this._images[key].frameData = AnimationLoader.parseXMLData(this._game, atlasData, format);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new image.
|
||||||
|
* @param key {string} Asset key for the image.
|
||||||
|
* @param url {string} URL of this image file.
|
||||||
|
* @param data {object} Extra image data.
|
||||||
|
*/
|
||||||
public addImage(key: string, url: string, data) {
|
public addImage(key: string, url: string, data) {
|
||||||
|
|
||||||
this._images[key] = { url: url, data: data, spriteSheet: false };
|
this._images[key] = { url: url, data: data, spriteSheet: false };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new sound.
|
||||||
|
* @param key {string} Asset key for the sound.
|
||||||
|
* @param url {string} URL of this sound file.
|
||||||
|
* @param data {object} Extra sound data.
|
||||||
|
*/
|
||||||
public addSound(key: string, url: string, data) {
|
public addSound(key: string, url: string, data) {
|
||||||
|
|
||||||
this._sounds[key] = { url: url, data: data, decoded: false };
|
this._sounds[key] = { url: url, data: data, decoded: false };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new decoded sound.
|
||||||
|
* @param key {string} Asset key for the sound.
|
||||||
|
* @param url {string} URL of this sound file.
|
||||||
|
* @param data {object} Extra sound data.
|
||||||
|
*/
|
||||||
public decodedSound(key: string, data) {
|
public decodedSound(key: string, data) {
|
||||||
|
|
||||||
this._sounds[key].data = data;
|
this._sounds[key].data = data;
|
||||||
@@ -68,12 +138,23 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new text data.
|
||||||
|
* @param key {string} Asset key for the text data.
|
||||||
|
* @param url {string} URL of this text data file.
|
||||||
|
* @param data {object} Extra text data.
|
||||||
|
*/
|
||||||
public addText(key: string, url: string, data) {
|
public addText(key: string, url: string, data) {
|
||||||
|
|
||||||
this._text[key] = { url: url, data: data };
|
this._text[key] = { url: url, data: data };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get canvas by key.
|
||||||
|
* @param key Asset key of the canvas you want.
|
||||||
|
* @return {object} The canvas you want.
|
||||||
|
*/
|
||||||
public getCanvas(key: string) {
|
public getCanvas(key: string) {
|
||||||
|
|
||||||
if (this._canvases[key])
|
if (this._canvases[key])
|
||||||
@@ -85,6 +166,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get image data by key.
|
||||||
|
* @param key Asset key of the image you want.
|
||||||
|
* @return {object} The image data you want.
|
||||||
|
*/
|
||||||
public getImage(key: string) {
|
public getImage(key: string) {
|
||||||
|
|
||||||
if (this._images[key])
|
if (this._images[key])
|
||||||
@@ -96,6 +182,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get frame data by key.
|
||||||
|
* @param key Asset key of the frame data you want.
|
||||||
|
* @return {object} The frame data you want.
|
||||||
|
*/
|
||||||
public getFrameData(key: string): FrameData {
|
public getFrameData(key: string): FrameData {
|
||||||
|
|
||||||
if (this._images[key] && this._images[key].spriteSheet == true)
|
if (this._images[key] && this._images[key].spriteSheet == true)
|
||||||
@@ -107,6 +198,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get sound data by key.
|
||||||
|
* @param key Asset key of the sound you want.
|
||||||
|
* @return {object} The sound data you want.
|
||||||
|
*/
|
||||||
public getSound(key: string) {
|
public getSound(key: string) {
|
||||||
|
|
||||||
if (this._sounds[key])
|
if (this._sounds[key])
|
||||||
@@ -118,6 +214,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether an asset is decoded sound.
|
||||||
|
* @param key Asset key of the sound you want.
|
||||||
|
* @return {object} The sound data you want.
|
||||||
|
*/
|
||||||
public isSoundDecoded(key: string): bool {
|
public isSoundDecoded(key: string): bool {
|
||||||
|
|
||||||
if (this._sounds[key])
|
if (this._sounds[key])
|
||||||
@@ -127,6 +228,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether an asset is sprite sheet.
|
||||||
|
* @param key Asset key of the sprite sheet you want.
|
||||||
|
* @return {object} The sprite sheet data you want.
|
||||||
|
*/
|
||||||
public isSpriteSheet(key: string): bool {
|
public isSpriteSheet(key: string): bool {
|
||||||
|
|
||||||
if (this._images[key])
|
if (this._images[key])
|
||||||
@@ -136,6 +242,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get text data by key.
|
||||||
|
* @param key Asset key of the text data you want.
|
||||||
|
* @return {object} The text data you want.
|
||||||
|
*/
|
||||||
public getText(key: string) {
|
public getText(key: string) {
|
||||||
|
|
||||||
if (this._text[key])
|
if (this._text[key])
|
||||||
@@ -147,6 +258,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up cache memory.
|
||||||
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
|
||||||
for (var item in this._canvases)
|
for (var item in this._canvases)
|
||||||
|
|||||||
+52
-3
@@ -6,15 +6,21 @@
|
|||||||
*
|
*
|
||||||
* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
|
* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
|
||||||
* all of the cameras in the world.
|
* all of the cameras in the world.
|
||||||
*
|
|
||||||
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
|
|
||||||
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
|
|
||||||
export class CameraManager {
|
export class CameraManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CameraManager constructor
|
||||||
|
* This will create a new <code>Camera</code> with position and size.
|
||||||
|
*
|
||||||
|
* @param x {number} X Position of the created camera.
|
||||||
|
* @param y {number} y Position of the created camera.
|
||||||
|
* @param width {number} Width of the created camera.
|
||||||
|
* @param height {number} Height of the created camera.
|
||||||
|
*/
|
||||||
constructor(game: Game, x: number, y: number, width: number, height: number) {
|
constructor(game: Game, x: number, y: number, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -25,24 +31,58 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to Game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local container for storing cameras.
|
||||||
|
*/
|
||||||
private _cameras: Camera[];
|
private _cameras: Camera[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local helper stores index of next created camera.
|
||||||
|
*/
|
||||||
private _cameraInstance: number = 0;
|
private _cameraInstance: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently used camera.
|
||||||
|
*/
|
||||||
public current: Camera;
|
public current: Camera;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the cameras.
|
||||||
|
*
|
||||||
|
* @returns {Camera[]} An array contains all the cameras.
|
||||||
|
*/
|
||||||
public getAll(): Camera[] {
|
public getAll(): Camera[] {
|
||||||
return this._cameras;
|
return this._cameras;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update cameras.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
this._cameras.forEach((camera) => camera.update());
|
this._cameras.forEach((camera) => camera.update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render cameras.
|
||||||
|
*/
|
||||||
public render() {
|
public render() {
|
||||||
this._cameras.forEach((camera) => camera.render());
|
this._cameras.forEach((camera) => camera.render());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new camera with specific position and size.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new camera.
|
||||||
|
* @param y {number} Y position of the new camera.
|
||||||
|
* @param width {number} Width of the new camera.
|
||||||
|
* @param height {number} Height of the new camera.
|
||||||
|
* @returns {Camera} The newly created camera object.
|
||||||
|
*/
|
||||||
public addCamera(x: number, y: number, width: number, height: number): Camera {
|
public addCamera(x: number, y: number, width: number, height: number): Camera {
|
||||||
|
|
||||||
var newCam: Camera = new Camera(this._game, this._cameraInstance, x, y, width, height);
|
var newCam: Camera = new Camera(this._game, this._cameraInstance, x, y, width, height);
|
||||||
@@ -55,6 +95,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a new camera with its id.
|
||||||
|
*
|
||||||
|
* @param id {number} ID of the camera you want to remove.
|
||||||
|
* @returns {boolean} True if successfully removed the camera, otherwise return false.
|
||||||
|
*/
|
||||||
public removeCamera(id: number): bool {
|
public removeCamera(id: number): bool {
|
||||||
|
|
||||||
for (var c = 0; c < this._cameras.length; c++)
|
for (var c = 0; c < this._cameras.length; c++)
|
||||||
@@ -76,6 +122,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up memory.
|
||||||
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
|
||||||
this._cameras.length = 0;
|
this._cameras.length = 0;
|
||||||
|
|||||||
+698
-52
@@ -5,6 +5,8 @@
|
|||||||
/// <reference path="geom/Circle.ts" />
|
/// <reference path="geom/Circle.ts" />
|
||||||
/// <reference path="geom/Line.ts" />
|
/// <reference path="geom/Line.ts" />
|
||||||
/// <reference path="geom/IntersectResult.ts" />
|
/// <reference path="geom/IntersectResult.ts" />
|
||||||
|
/// <reference path="geom/Response.ts" />
|
||||||
|
/// <reference path="geom/Vector2.ts" />
|
||||||
/// <reference path="system/QuadTree.ts" />
|
/// <reference path="system/QuadTree.ts" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,6 +27,20 @@ module Phaser {
|
|||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
|
|
||||||
|
Collision.T_VECTORS = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
Collision.T_VECTORS.push(new Vector2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.T_ARRAYS = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
Collision.T_ARRAYS.push([]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +124,7 @@ module Phaser {
|
|||||||
* Checks for Line to Line intersection and returns an IntersectResult object containing the results of the intersection.
|
* Checks for Line to Line intersection and returns an IntersectResult object containing the results of the intersection.
|
||||||
* @param line1 The first Line object to check
|
* @param line1 The first Line object to check
|
||||||
* @param line2 The second Line object to check
|
* @param line2 The second Line object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineToLine(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineToLine(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -129,7 +145,7 @@ module Phaser {
|
|||||||
* Checks for Line to Line Segment intersection and returns an IntersectResult object containing the results of the intersection.
|
* Checks for Line to Line Segment intersection and returns an IntersectResult object containing the results of the intersection.
|
||||||
* @param line The Line object to check
|
* @param line The Line object to check
|
||||||
* @param seg The Line segment object to check
|
* @param seg The Line segment object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineToLineSegment(line: Line, seg: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineToLineSegment(line: Line, seg: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -164,7 +180,7 @@ module Phaser {
|
|||||||
* @param y1 The start y coordinate of the raw segment
|
* @param y1 The start y coordinate of the raw segment
|
||||||
* @param x2 The end x coordinate of the raw segment
|
* @param x2 The end x coordinate of the raw segment
|
||||||
* @param y2 The end y coordinate of the raw segment
|
* @param y2 The end y coordinate of the raw segment
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineToRawSegment(line: Line, x1: number, y1: number, x2: number, y2: number, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineToRawSegment(line: Line, x1: number, y1: number, x2: number, y2: number, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -196,7 +212,7 @@ module Phaser {
|
|||||||
* Checks for Line to Ray intersection and returns the result in an IntersectResult object.
|
* Checks for Line to Ray intersection and returns the result in an IntersectResult object.
|
||||||
* @param line1 The Line object to check
|
* @param line1 The Line object to check
|
||||||
* @param ray The Ray object to check
|
* @param ray The Ray object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineToRay(line1: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineToRay(line1: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -229,7 +245,7 @@ module Phaser {
|
|||||||
* Check if the Line and Circle objects intersect
|
* Check if the Line and Circle objects intersect
|
||||||
* @param line The Line object to check
|
* @param line The Line object to check
|
||||||
* @param circle The Circle object to check
|
* @param circle The Circle object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineToCircle(line: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineToCircle(line: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -248,7 +264,7 @@ module Phaser {
|
|||||||
* Check if the Line intersects each side of the Rectangle
|
* Check if the Line intersects each side of the Rectangle
|
||||||
* @param line The Line object to check
|
* @param line The Line object to check
|
||||||
* @param rect The Rectangle object to check
|
* @param rect The Rectangle object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineToRectangle(line: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineToRectangle(line: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -288,7 +304,7 @@ module Phaser {
|
|||||||
* Check if the two Line Segments intersect and returns the result in an IntersectResult object.
|
* Check if the two Line Segments intersect and returns the result in an IntersectResult object.
|
||||||
* @param line1 The first Line Segment to check
|
* @param line1 The first Line Segment to check
|
||||||
* @param line2 The second Line Segment to check
|
* @param line2 The second Line Segment to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineSegmentToLineSegment(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineSegmentToLineSegment(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -311,7 +327,7 @@ module Phaser {
|
|||||||
* Check if the Line Segment intersects with the Ray and returns the result in an IntersectResult object.
|
* Check if the Line Segment intersects with the Ray and returns the result in an IntersectResult object.
|
||||||
* @param line The Line Segment to check.
|
* @param line The Line Segment to check.
|
||||||
* @param ray The Ray to check.
|
* @param ray The Ray to check.
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineSegmentToRay(line: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineSegmentToRay(line: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -335,7 +351,7 @@ module Phaser {
|
|||||||
* Check if the Line Segment intersects with the Circle and returns the result in an IntersectResult object.
|
* Check if the Line Segment intersects with the Circle and returns the result in an IntersectResult object.
|
||||||
* @param seg The Line Segment to check.
|
* @param seg The Line Segment to check.
|
||||||
* @param circle The Circle to check
|
* @param circle The Circle to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineSegmentToCircle(seg: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineSegmentToCircle(seg: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -372,7 +388,7 @@ module Phaser {
|
|||||||
* Check if the Line Segment intersects with the Rectangle and returns the result in an IntersectResult object.
|
* Check if the Line Segment intersects with the Rectangle and returns the result in an IntersectResult object.
|
||||||
* @param seg The Line Segment to check.
|
* @param seg The Line Segment to check.
|
||||||
* @param rect The Rectangle to check.
|
* @param rect The Rectangle to check.
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static lineSegmentToRectangle(seg: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static lineSegmentToRectangle(seg: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -422,7 +438,7 @@ module Phaser {
|
|||||||
* Check for Ray to Rectangle intersection and returns the result in an IntersectResult object.
|
* Check for Ray to Rectangle intersection and returns the result in an IntersectResult object.
|
||||||
* @param ray The Ray to check.
|
* @param ray The Ray to check.
|
||||||
* @param rect The Rectangle to check.
|
* @param rect The Rectangle to check.
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static rayToRectangle(ray: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static rayToRectangle(ray: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -445,7 +461,7 @@ module Phaser {
|
|||||||
* @param lineY1
|
* @param lineY1
|
||||||
* @param lineX2
|
* @param lineX2
|
||||||
* @param lineY2
|
* @param lineY2
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static rayToLineSegment(rayX1, rayY1, rayX2, rayY2, lineX1, lineY1, lineX2, lineY2, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static rayToLineSegment(rayX1, rayY1, rayX2, rayY2, lineX1, lineY1, lineX2, lineY2, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -484,7 +500,7 @@ module Phaser {
|
|||||||
* Determines whether the specified point is contained within the rectangular region defined by the Rectangle object and returns the result in an IntersectResult object.
|
* Determines whether the specified point is contained within the rectangular region defined by the Rectangle object and returns the result in an IntersectResult object.
|
||||||
* @param point The Point or MicroPoint object to check, or any object with x and y properties.
|
* @param point The Point or MicroPoint object to check, or any object with x and y properties.
|
||||||
* @param rect The Rectangle object to check the point against
|
* @param rect The Rectangle object to check the point against
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static pointToRectangle(point, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static pointToRectangle(point, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -501,7 +517,7 @@ module Phaser {
|
|||||||
* Check whether two axis aligned Rectangles intersect and returns the intersecting rectangle dimensions in an IntersectResult object if they do.
|
* Check whether two axis aligned Rectangles intersect and returns the intersecting rectangle dimensions in an IntersectResult object if they do.
|
||||||
* @param rect1 The first Rectangle object.
|
* @param rect1 The first Rectangle object.
|
||||||
* @param rect2 The second Rectangle object.
|
* @param rect2 The second Rectangle object.
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static rectangleToRectangle(rect1: Rectangle, rect2: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static rectangleToRectangle(rect1: Rectangle, rect2: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -529,7 +545,7 @@ module Phaser {
|
|||||||
* Checks if the Rectangle and Circle objects intersect and returns the result in an IntersectResult object.
|
* Checks if the Rectangle and Circle objects intersect and returns the result in an IntersectResult object.
|
||||||
* @param rect The Rectangle object to check
|
* @param rect The Rectangle object to check
|
||||||
* @param circle The Circle object to check
|
* @param circle The Circle object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static rectangleToCircle(rect: Rectangle, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static rectangleToCircle(rect: Rectangle, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -542,7 +558,7 @@ module Phaser {
|
|||||||
* Checks if the two Circle objects intersect and returns the result in an IntersectResult object.
|
* Checks if the two Circle objects intersect and returns the result in an IntersectResult object.
|
||||||
* @param circle1 The first Circle object to check
|
* @param circle1 The first Circle object to check
|
||||||
* @param circle2 The second Circle object to check
|
* @param circle2 The second Circle object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static circleToCircle(circle1: Circle, circle2: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static circleToCircle(circle1: Circle, circle2: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -557,7 +573,7 @@ module Phaser {
|
|||||||
* Checks if the Circle object intersects with the Rectangle and returns the result in an IntersectResult object.
|
* Checks if the Circle object intersects with the Rectangle and returns the result in an IntersectResult object.
|
||||||
* @param circle The Circle object to check
|
* @param circle The Circle object to check
|
||||||
* @param rect The Rectangle object to check
|
* @param rect The Rectangle object to check
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static circleToRectangle(circle: Circle, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static circleToRectangle(circle: Circle, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -576,7 +592,7 @@ module Phaser {
|
|||||||
* Checks if the Point object is contained within the Circle and returns the result in an IntersectResult object.
|
* Checks if the Point object is contained within the Circle and returns the result in an IntersectResult object.
|
||||||
* @param circle The Circle object to check
|
* @param circle The Circle object to check
|
||||||
* @param point A Point or MicroPoint object to check, or any object with x and y properties
|
* @param point A Point or MicroPoint object to check, or any object with x and y properties
|
||||||
* @param output An optional IntersectResult object to store the intersection values in. One is created if none given.
|
* @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given.
|
||||||
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
* @returns {IntersectResult=} An IntersectResult object containing the results of the intersection
|
||||||
*/
|
*/
|
||||||
public static circleContainsPoint(circle: Circle, point, output?: IntersectResult = new IntersectResult): IntersectResult {
|
public static circleContainsPoint(circle: Circle, point, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||||
@@ -594,9 +610,10 @@ module Phaser {
|
|||||||
* @param object2 The second GameObject or Group to check.
|
* @param object2 The second GameObject or Group to check.
|
||||||
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
|
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
|
||||||
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
|
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
|
||||||
|
* @param context The context in which the callbacks will be called
|
||||||
* @returns {boolean} true if the objects overlap, otherwise false.
|
* @returns {boolean} true if the objects overlap, otherwise false.
|
||||||
*/
|
*/
|
||||||
public overlap(object1: Basic = null, object2: Basic = null, notifyCallback = null, processCallback = null): bool {
|
public overlap(object1: Basic = null, object2: Basic = null, notifyCallback = null, processCallback = null, context = null): bool {
|
||||||
|
|
||||||
if (object1 == null)
|
if (object1 == null)
|
||||||
{
|
{
|
||||||
@@ -612,7 +629,7 @@ module Phaser {
|
|||||||
|
|
||||||
var quadTree: QuadTree = new QuadTree(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
|
var quadTree: QuadTree = new QuadTree(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
|
||||||
|
|
||||||
quadTree.load(object1, object2, notifyCallback, processCallback);
|
quadTree.load(object1, object2, notifyCallback, processCallback, context);
|
||||||
|
|
||||||
var result: bool = quadTree.execute();
|
var result: bool = quadTree.execute();
|
||||||
|
|
||||||
@@ -632,6 +649,9 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
public static separate(object1, object2): bool {
|
public static separate(object1, object2): bool {
|
||||||
|
|
||||||
|
object1.collisionMask.update();
|
||||||
|
object2.collisionMask.update();
|
||||||
|
|
||||||
var separatedX: bool = Collision.separateX(object1, object2);
|
var separatedX: bool = Collision.separateX(object1, object2);
|
||||||
var separatedY: bool = Collision.separateY(object1, object2);
|
var separatedY: bool = Collision.separateY(object1, object2);
|
||||||
|
|
||||||
@@ -647,6 +667,8 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
public static separateTile(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool, separateX: bool, separateY: bool): bool {
|
public static separateTile(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool, separateX: bool, separateY: bool): bool {
|
||||||
|
|
||||||
|
object.collisionMask.update();
|
||||||
|
|
||||||
var separatedX: bool = Collision.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight, separateX);
|
var separatedX: bool = Collision.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight, separateX);
|
||||||
var separatedY: bool = Collision.separateTileY(object, x, y, width, height, mass, collideUp, collideDown, separateY);
|
var separatedY: bool = Collision.separateTileY(object, x, y, width, height, mass, collideUp, collideDown, separateY);
|
||||||
|
|
||||||
@@ -671,11 +693,13 @@ module Phaser {
|
|||||||
// First, get the object delta
|
// First, get the object delta
|
||||||
var overlap: number = 0;
|
var overlap: number = 0;
|
||||||
var objDelta: number = object.x - object.last.x;
|
var objDelta: number = object.x - object.last.x;
|
||||||
|
//var objDelta: number = object.collisionMask.deltaX;
|
||||||
|
|
||||||
if (objDelta != 0)
|
if (objDelta != 0)
|
||||||
{
|
{
|
||||||
// Check if the X hulls actually overlap
|
// Check if the X hulls actually overlap
|
||||||
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||||
|
//var objDeltaAbs: number = object.collisionMask.deltaXAbs;
|
||||||
var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
||||||
|
|
||||||
if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||||
@@ -719,6 +743,7 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (separate == true)
|
if (separate == true)
|
||||||
{
|
{
|
||||||
|
//console.log('
|
||||||
object.x = object.x - overlap;
|
object.x = object.x - overlap;
|
||||||
object.velocity.x = -(object.velocity.x * object.elasticity);
|
object.velocity.x = -(object.velocity.x * object.elasticity);
|
||||||
}
|
}
|
||||||
@@ -811,6 +836,170 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separates the two objects on their x axis
|
||||||
|
* @param object The GameObject to separate
|
||||||
|
* @param tile The Tile to separate
|
||||||
|
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
|
||||||
|
*/
|
||||||
|
public static NEWseparateTileX(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, separate: bool): bool {
|
||||||
|
|
||||||
|
// Can't separate two immovable objects (tiles are always immovable)
|
||||||
|
if (object.immovable)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, get the object delta
|
||||||
|
var overlap: number = 0;
|
||||||
|
|
||||||
|
if (object.collisionMask.deltaX != 0)
|
||||||
|
{
|
||||||
|
// Check if the X hulls actually overlap
|
||||||
|
//var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||||
|
//var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
||||||
|
|
||||||
|
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||||
|
if (object.collisionMask.intersectsRaw(x, x + width, y, y + height))
|
||||||
|
{
|
||||||
|
var maxOverlap: number = object.collisionMask.deltaXAbs + Collision.OVERLAP_BIAS;
|
||||||
|
|
||||||
|
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||||
|
if (object.collisionMask.deltaX > 0)
|
||||||
|
{
|
||||||
|
//overlap = object.x + object.width - x;
|
||||||
|
overlap = object.collisionMask.right - x;
|
||||||
|
|
||||||
|
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false)
|
||||||
|
{
|
||||||
|
overlap = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
object.touching |= Collision.RIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (object.collisionMask.deltaX < 0)
|
||||||
|
{
|
||||||
|
//overlap = object.x - width - x;
|
||||||
|
overlap = object.collisionMask.x - width - x;
|
||||||
|
|
||||||
|
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false)
|
||||||
|
{
|
||||||
|
overlap = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
object.touching |= Collision.LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
|
if (overlap != 0)
|
||||||
|
{
|
||||||
|
if (separate == true)
|
||||||
|
{
|
||||||
|
object.x = object.x - overlap;
|
||||||
|
object.velocity.x = -(object.velocity.x * object.elasticity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.TILE_OVERLAP = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separates the two objects on their y axis
|
||||||
|
* @param object The first GameObject to separate
|
||||||
|
* @param tile The second GameObject to separate
|
||||||
|
* @returns {boolean} Whether the objects in fact touched and were separated along the Y axis.
|
||||||
|
*/
|
||||||
|
public static NEWseparateTileY(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool, separate: bool): bool {
|
||||||
|
|
||||||
|
// Can't separate two immovable objects (tiles are always immovable)
|
||||||
|
if (object.immovable)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, get the two object deltas
|
||||||
|
var overlap: number = 0;
|
||||||
|
//var objDelta: number = object.y - object.last.y;
|
||||||
|
|
||||||
|
if (object.collisionMask.deltaY != 0)
|
||||||
|
{
|
||||||
|
// Check if the Y hulls actually overlap
|
||||||
|
//var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||||
|
//var objBounds: Quad = new Quad(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs);
|
||||||
|
|
||||||
|
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||||
|
if (object.collisionMask.intersectsRaw(x, x + width, y, y + height))
|
||||||
|
{
|
||||||
|
//var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS;
|
||||||
|
var maxOverlap: number = object.collisionMask.deltaYAbs + Collision.OVERLAP_BIAS;
|
||||||
|
|
||||||
|
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||||
|
if (object.collisionMask.deltaY > 0)
|
||||||
|
{
|
||||||
|
//overlap = object.y + object.height - y;
|
||||||
|
overlap = object.collisionMask.bottom - y;
|
||||||
|
|
||||||
|
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false)
|
||||||
|
{
|
||||||
|
overlap = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
object.touching |= Collision.DOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (object.collisionMask.deltaY < 0)
|
||||||
|
{
|
||||||
|
//overlap = object.y - height - y;
|
||||||
|
overlap = object.collisionMask.y - height - y;
|
||||||
|
|
||||||
|
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false)
|
||||||
|
{
|
||||||
|
overlap = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
object.touching |= Collision.UP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - with super low velocities you get lots of stuttering, set some kind of base minimum here
|
||||||
|
|
||||||
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
|
if (overlap != 0)
|
||||||
|
{
|
||||||
|
if (separate == true)
|
||||||
|
{
|
||||||
|
object.y = object.y - overlap;
|
||||||
|
object.velocity.y = -(object.velocity.y * object.elasticity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.TILE_OVERLAP = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Separates the two objects on their x axis
|
* Separates the two objects on their x axis
|
||||||
* @param object1 The first GameObject to separate
|
* @param object1 The first GameObject to separate
|
||||||
@@ -827,25 +1016,17 @@ module Phaser {
|
|||||||
|
|
||||||
// First, get the two object deltas
|
// First, get the two object deltas
|
||||||
var overlap: number = 0;
|
var overlap: number = 0;
|
||||||
var obj1Delta: number = object1.x - object1.last.x;
|
|
||||||
var obj2Delta: number = object2.x - object2.last.x;
|
|
||||||
|
|
||||||
if (obj1Delta != obj2Delta)
|
if (object1.collisionMask.deltaX != object2.collisionMask.deltaX)
|
||||||
{
|
{
|
||||||
// Check if the X hulls actually overlap
|
if (object1.collisionMask.intersects(object2.collisionMask))
|
||||||
var obj1DeltaAbs: number = (obj1Delta > 0) ? obj1Delta : -obj1Delta;
|
|
||||||
var obj2DeltaAbs: number = (obj2Delta > 0) ? obj2Delta : -obj2Delta;
|
|
||||||
var obj1Bounds: Quad = new Quad(object1.x - ((obj1Delta > 0) ? obj1Delta : 0), object1.last.y, object1.width + ((obj1Delta > 0) ? obj1Delta : -obj1Delta), object1.height);
|
|
||||||
var obj2Bounds: Quad = new Quad(object2.x - ((obj2Delta > 0) ? obj2Delta : 0), object2.last.y, object2.width + ((obj2Delta > 0) ? obj2Delta : -obj2Delta), object2.height);
|
|
||||||
|
|
||||||
if ((obj1Bounds.x + obj1Bounds.width > obj2Bounds.x) && (obj1Bounds.x < obj2Bounds.x + obj2Bounds.width) && (obj1Bounds.y + obj1Bounds.height > obj2Bounds.y) && (obj1Bounds.y < obj2Bounds.y + obj2Bounds.height))
|
|
||||||
{
|
{
|
||||||
var maxOverlap: number = obj1DeltaAbs + obj2DeltaAbs + Collision.OVERLAP_BIAS;
|
var maxOverlap: number = object1.collisionMask.deltaXAbs + object2.collisionMask.deltaXAbs + Collision.OVERLAP_BIAS;
|
||||||
|
|
||||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||||
if (obj1Delta > obj2Delta)
|
if (object1.collisionMask.deltaX > object2.collisionMask.deltaX)
|
||||||
{
|
{
|
||||||
overlap = object1.x + object1.width - object2.x;
|
overlap = object1.collisionMask.right - object2.collisionMask.x;
|
||||||
|
|
||||||
if ((overlap > maxOverlap) || !(object1.allowCollisions & Collision.RIGHT) || !(object2.allowCollisions & Collision.LEFT))
|
if ((overlap > maxOverlap) || !(object1.allowCollisions & Collision.RIGHT) || !(object2.allowCollisions & Collision.LEFT))
|
||||||
{
|
{
|
||||||
@@ -857,9 +1038,9 @@ module Phaser {
|
|||||||
object2.touching |= Collision.LEFT;
|
object2.touching |= Collision.LEFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (obj1Delta < obj2Delta)
|
else if (object1.collisionMask.deltaX < object2.collisionMask.deltaX)
|
||||||
{
|
{
|
||||||
overlap = object1.x - object2.width - object2.x;
|
overlap = object1.collisionMask.x - object2.collisionMask.width - object2.collisionMask.x;
|
||||||
|
|
||||||
if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.LEFT) || !(object2.allowCollisions & Collision.RIGHT))
|
if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.LEFT) || !(object2.allowCollisions & Collision.RIGHT))
|
||||||
{
|
{
|
||||||
@@ -931,25 +1112,18 @@ module Phaser {
|
|||||||
|
|
||||||
// First, get the two object deltas
|
// First, get the two object deltas
|
||||||
var overlap: number = 0;
|
var overlap: number = 0;
|
||||||
var obj1Delta: number = object1.y - object1.last.y;
|
|
||||||
var obj2Delta: number = object2.y - object2.last.y;
|
|
||||||
|
|
||||||
if (obj1Delta != obj2Delta)
|
if (object1.collisionMask.deltaY != object2.collisionMask.deltaY)
|
||||||
{
|
{
|
||||||
// Check if the Y hulls actually overlap
|
if (object1.collisionMask.intersects(object2.collisionMask))
|
||||||
var obj1DeltaAbs: number = (obj1Delta > 0) ? obj1Delta : -obj1Delta;
|
|
||||||
var obj2DeltaAbs: number = (obj2Delta > 0) ? obj2Delta : -obj2Delta;
|
|
||||||
var obj1Bounds: Quad = new Quad(object1.x, object1.y - ((obj1Delta > 0) ? obj1Delta : 0), object1.width, object1.height + obj1DeltaAbs);
|
|
||||||
var obj2Bounds: Quad = new Quad(object2.x, object2.y - ((obj2Delta > 0) ? obj2Delta : 0), object2.width, object2.height + obj2DeltaAbs);
|
|
||||||
|
|
||||||
if ((obj1Bounds.x + obj1Bounds.width > obj2Bounds.x) && (obj1Bounds.x < obj2Bounds.x + obj2Bounds.width) && (obj1Bounds.y + obj1Bounds.height > obj2Bounds.y) && (obj1Bounds.y < obj2Bounds.y + obj2Bounds.height))
|
|
||||||
{
|
{
|
||||||
var maxOverlap: number = obj1DeltaAbs + obj2DeltaAbs + Collision.OVERLAP_BIAS;
|
// This is the only place to use the DeltaAbs values
|
||||||
|
var maxOverlap: number = object1.collisionMask.deltaYAbs + object2.collisionMask.deltaYAbs + Collision.OVERLAP_BIAS;
|
||||||
|
|
||||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||||
if (obj1Delta > obj2Delta)
|
if (object1.collisionMask.deltaY > object2.collisionMask.deltaY)
|
||||||
{
|
{
|
||||||
overlap = object1.y + object1.height - object2.y;
|
overlap = object1.collisionMask.bottom - object2.collisionMask.y;
|
||||||
|
|
||||||
if ((overlap > maxOverlap) || !(object1.allowCollisions & Collision.DOWN) || !(object2.allowCollisions & Collision.UP))
|
if ((overlap > maxOverlap) || !(object1.allowCollisions & Collision.DOWN) || !(object2.allowCollisions & Collision.UP))
|
||||||
{
|
{
|
||||||
@@ -961,9 +1135,9 @@ module Phaser {
|
|||||||
object2.touching |= Collision.UP;
|
object2.touching |= Collision.UP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (obj1Delta < obj2Delta)
|
else if (object1.collisionMask.deltaY < object2.collisionMask.deltaY)
|
||||||
{
|
{
|
||||||
overlap = object1.y - object2.height - object2.y;
|
overlap = object1.collisionMask.y - object2.collisionMask.height - object2.collisionMask.y;
|
||||||
|
|
||||||
if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.UP) || !(object2.allowCollisions & Collision.DOWN))
|
if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.UP) || !(object2.allowCollisions & Collision.DOWN))
|
||||||
{
|
{
|
||||||
@@ -1003,7 +1177,7 @@ module Phaser {
|
|||||||
object1.y = object1.y - overlap;
|
object1.y = object1.y - overlap;
|
||||||
object1.velocity.y = obj2Velocity - obj1Velocity * object1.elasticity;
|
object1.velocity.y = obj2Velocity - obj1Velocity * object1.elasticity;
|
||||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||||
if (object2.active && object2.moves && (obj1Delta > obj2Delta))
|
if (object2.active && object2.moves && (object1.collisionMask.deltaY > object2.collisionMask.deltaY))
|
||||||
{
|
{
|
||||||
object1.x += object2.x - object2.last.x;
|
object1.x += object2.x - object2.last.x;
|
||||||
}
|
}
|
||||||
@@ -1013,7 +1187,7 @@ module Phaser {
|
|||||||
object2.y += overlap;
|
object2.y += overlap;
|
||||||
object2.velocity.y = obj1Velocity - obj2Velocity * object2.elasticity;
|
object2.velocity.y = obj1Velocity - obj2Velocity * object2.elasticity;
|
||||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||||
if (object1.active && object1.moves && (obj1Delta < obj2Delta))
|
if (object1.active && object1.moves && (object1.collisionMask.deltaY < object2.collisionMask.deltaY))
|
||||||
{
|
{
|
||||||
object2.x += object1.x - object1.last.x;
|
object2.x += object1.x - object1.last.x;
|
||||||
}
|
}
|
||||||
@@ -1051,6 +1225,478 @@ module Phaser {
|
|||||||
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
|
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// SAT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flattens the specified array of points onto a unit vector axis,
|
||||||
|
* resulting in a one dimensional range of the minimum and
|
||||||
|
* maximum value on that axis.
|
||||||
|
*
|
||||||
|
* @param {Array.<Vector>} points The points to flatten.
|
||||||
|
* @param {Vector} normal The unit vector axis to flatten on.
|
||||||
|
* @param {Array.<number>} result An array. After calling this function,
|
||||||
|
* result[0] will be the minimum value,
|
||||||
|
* result[1] will be the maximum value.
|
||||||
|
*/
|
||||||
|
public static flattenPointsOn(points, normal, result) {
|
||||||
|
|
||||||
|
var min = Number.MAX_VALUE;
|
||||||
|
var max = -Number.MAX_VALUE;
|
||||||
|
var len = points.length;
|
||||||
|
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// Get the magnitude of the projection of the point onto the normal
|
||||||
|
var dot = points[i].dot(normal);
|
||||||
|
if (dot < min) { min = dot; }
|
||||||
|
if (dot > max) { max = dot; }
|
||||||
|
}
|
||||||
|
|
||||||
|
result[0] = min; result[1] = max;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pool of Vectors used in calculations.
|
||||||
|
*
|
||||||
|
* @type {Array.<Vector>}
|
||||||
|
*/
|
||||||
|
public static T_VECTORS: Vector2[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pool of Arrays used in calculations.
|
||||||
|
*
|
||||||
|
* @type {Array.<Array.<*>>}
|
||||||
|
*/
|
||||||
|
public static T_ARRAYS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether two convex clockwise polygons are separated by the specified
|
||||||
|
* axis (must be a unit vector).
|
||||||
|
*
|
||||||
|
* @param {Vector} aPos The position of the first polygon.
|
||||||
|
* @param {Vector} bPos The position of the second polygon.
|
||||||
|
* @param {Array.<Vector>} aPoints The points in the first polygon.
|
||||||
|
* @param {Array.<Vector>} bPoints The points in the second polygon.
|
||||||
|
* @param {Vector} axis The axis (unit sized) to test against. The points of both polygons
|
||||||
|
* will be projected onto this axis.
|
||||||
|
* @param {Response=} response A Response object (optional) which will be populated
|
||||||
|
* if the axis is not a separating axis.
|
||||||
|
* @return {boolean} true if it is a separating axis, false otherwise. If false,
|
||||||
|
* and a response is passed in, information about how much overlap and
|
||||||
|
* the direction of the overlap will be populated.
|
||||||
|
*/
|
||||||
|
public static isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response?:Response = null): bool {
|
||||||
|
|
||||||
|
var rangeA = Collision.T_ARRAYS.pop();
|
||||||
|
var rangeB = Collision.T_ARRAYS.pop();
|
||||||
|
|
||||||
|
// Get the magnitude of the offset between the two polygons
|
||||||
|
var offsetV = Collision.T_VECTORS.pop().copyFrom(bPos).sub(aPos);
|
||||||
|
var projectedOffset = offsetV.dot(axis);
|
||||||
|
|
||||||
|
// Project the polygons onto the axis.
|
||||||
|
Collision.flattenPointsOn(aPoints, axis, rangeA);
|
||||||
|
Collision.flattenPointsOn(bPoints, axis, rangeB);
|
||||||
|
|
||||||
|
// Move B's range to its position relative to A.
|
||||||
|
rangeB[0] += projectedOffset;
|
||||||
|
rangeB[1] += projectedOffset;
|
||||||
|
|
||||||
|
// Check if there is a gap. If there is, this is a separating axis and we can stop
|
||||||
|
if (rangeA[0] > rangeB[1] || rangeB[0] > rangeA[1])
|
||||||
|
{
|
||||||
|
Collision.T_VECTORS.push(offsetV);
|
||||||
|
Collision.T_ARRAYS.push(rangeA);
|
||||||
|
Collision.T_ARRAYS.push(rangeB);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're calculating a response, calculate the overlap.
|
||||||
|
if (response)
|
||||||
|
{
|
||||||
|
var overlap = 0;
|
||||||
|
|
||||||
|
// A starts further left than B
|
||||||
|
if (rangeA[0] < rangeB[0])
|
||||||
|
{
|
||||||
|
response.aInB = false;
|
||||||
|
|
||||||
|
// A ends before B does. We have to pull A out of B
|
||||||
|
if (rangeA[1] < rangeB[1])
|
||||||
|
{
|
||||||
|
overlap = rangeA[1] - rangeB[0];
|
||||||
|
response.bInA = false;
|
||||||
|
// B is fully inside A. Pick the shortest way out.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var option1 = rangeA[1] - rangeB[0];
|
||||||
|
var option2 = rangeB[1] - rangeA[0];
|
||||||
|
overlap = option1 < option2 ? option1 : -option2;
|
||||||
|
}
|
||||||
|
// B starts further left than A
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.bInA = false;
|
||||||
|
|
||||||
|
// B ends before A ends. We have to push A out of B
|
||||||
|
if (rangeA[1] > rangeB[1])
|
||||||
|
{
|
||||||
|
overlap = rangeA[0] - rangeB[1];
|
||||||
|
response.aInB = false;
|
||||||
|
// A is fully inside B. Pick the shortest way out.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var option1 = rangeA[1] - rangeB[0];
|
||||||
|
var option2 = rangeB[1] - rangeA[0];
|
||||||
|
overlap = option1 < option2 ? option1 : -option2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is the smallest amount of overlap we've seen so far, set it as the minimum overlap.
|
||||||
|
var absOverlap = Math.abs(overlap);
|
||||||
|
|
||||||
|
if (absOverlap < response.overlap)
|
||||||
|
{
|
||||||
|
response.overlap = absOverlap;
|
||||||
|
response.overlapN.copyFrom(axis);
|
||||||
|
|
||||||
|
if (overlap < 0)
|
||||||
|
{
|
||||||
|
response.overlapN.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.T_VECTORS.push(offsetV);
|
||||||
|
Collision.T_ARRAYS.push(rangeA);
|
||||||
|
Collision.T_ARRAYS.push(rangeB);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LEFT_VORNOI_REGION:number = -1;
|
||||||
|
public static MIDDLE_VORNOI_REGION:number = 0;
|
||||||
|
public static RIGHT_VORNOI_REGION:number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates which Vornoi region a point is on a line segment.
|
||||||
|
* It is assumed that both the line and the point are relative to (0, 0)
|
||||||
|
*
|
||||||
|
* | (0) |
|
||||||
|
* (-1) [0]--------------[1] (1)
|
||||||
|
* | (0) |
|
||||||
|
*
|
||||||
|
* @param {Vector} line The line segment.
|
||||||
|
* @param {Vector} point The point.
|
||||||
|
* @return {number} LEFT_VORNOI_REGION (-1) if it is the left region,
|
||||||
|
* MIDDLE_VORNOI_REGION (0) if it is the middle region,
|
||||||
|
* RIGHT_VORNOI_REGION (1) if it is the right region.
|
||||||
|
*/
|
||||||
|
public static vornoiRegion(line: Vector2, point: Vector2): number {
|
||||||
|
|
||||||
|
var len2 = line.length2();
|
||||||
|
var dp = point.dot(line);
|
||||||
|
|
||||||
|
if (dp < 0) { return Collision.LEFT_VORNOI_REGION; }
|
||||||
|
else if (dp > len2) { return Collision.RIGHT_VORNOI_REGION; }
|
||||||
|
else { return Collision.MIDDLE_VORNOI_REGION; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if two circles intersect.
|
||||||
|
*
|
||||||
|
* @param {Circle} a The first circle.
|
||||||
|
* @param {Circle} b The second circle.
|
||||||
|
* @param {Response=} response Response object (optional) that will be populated if
|
||||||
|
* the circles intersect.
|
||||||
|
* @return {boolean} true if the circles intersect, false if they don't.
|
||||||
|
*/
|
||||||
|
public static testCircleCircle(a: Circle, b: Circle, response?: Response = null): bool {
|
||||||
|
|
||||||
|
var differenceV = Collision.T_VECTORS.pop().copyFrom(b.pos).sub(a.pos);
|
||||||
|
var totalRadius = a.radius + b.radius;
|
||||||
|
var totalRadiusSq = totalRadius * totalRadius;
|
||||||
|
var distanceSq = differenceV.length2();
|
||||||
|
|
||||||
|
if (distanceSq > totalRadiusSq)
|
||||||
|
{
|
||||||
|
// They do not intersect
|
||||||
|
Collision.T_VECTORS.push(differenceV);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// They intersect. If we're calculating a response, calculate the overlap.
|
||||||
|
if (response)
|
||||||
|
{
|
||||||
|
var dist = Math.sqrt(distanceSq);
|
||||||
|
response.a = a;
|
||||||
|
response.b = b;
|
||||||
|
response.overlap = totalRadius - dist;
|
||||||
|
response.overlapN.copyFrom(differenceV.normalize());
|
||||||
|
response.overlapV.copyFrom(differenceV).scale(response.overlap);
|
||||||
|
response.aInB = a.radius <= b.radius && dist <= b.radius - a.radius;
|
||||||
|
response.bInA = b.radius <= a.radius && dist <= a.radius - b.radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.T_VECTORS.push(differenceV);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a polygon and a circle intersect.
|
||||||
|
*
|
||||||
|
* @param {Polygon} polygon The polygon.
|
||||||
|
* @param {Circle} circle The circle.
|
||||||
|
* @param {Response=} response Response object (optional) that will be populated if
|
||||||
|
* they interset.
|
||||||
|
* @return {boolean} true if they intersect, false if they don't.
|
||||||
|
*/
|
||||||
|
public static testPolygonCircle(polygon: Polygon, circle: Circle, response?: Response = null): bool {
|
||||||
|
|
||||||
|
var circlePos = Collision.T_VECTORS.pop().copyFrom(circle.pos).sub(polygon.pos);
|
||||||
|
var radius = circle.radius;
|
||||||
|
var radius2 = radius * radius;
|
||||||
|
var points = polygon.points;
|
||||||
|
var len = points.length;
|
||||||
|
var edge = T_VECTORS.pop();
|
||||||
|
var point = T_VECTORS.pop();
|
||||||
|
|
||||||
|
// For each edge in the polygon
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
var next = i === len - 1 ? 0 : i + 1;
|
||||||
|
var prev = i === 0 ? len - 1 : i - 1;
|
||||||
|
var overlap = 0;
|
||||||
|
var overlapN = null;
|
||||||
|
|
||||||
|
// Get the edge
|
||||||
|
edge.copyFrom(polygon.edges[i]);
|
||||||
|
// Calculate the center of the cirble relative to the starting point of the edge
|
||||||
|
point.copyFrom(circlePos).sub(points[i]);
|
||||||
|
|
||||||
|
// If the distance between the center of the circle and the point
|
||||||
|
// is bigger than the radius, the polygon is definitely not fully in
|
||||||
|
// the circle.
|
||||||
|
if (response && point.length2() > radius2)
|
||||||
|
{
|
||||||
|
response.aInB = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate which Vornoi region the center of the circle is in.
|
||||||
|
var region = vornoiRegion(edge, point);
|
||||||
|
|
||||||
|
if (region === Collision.LEFT_VORNOI_REGION)
|
||||||
|
{
|
||||||
|
// Need to make sure we're in the RIGHT_VORNOI_REGION of the previous edge.
|
||||||
|
edge.copyFrom(polygon.edges[prev]);
|
||||||
|
|
||||||
|
// Calculate the center of the circle relative the starting point of the previous edge
|
||||||
|
var point2 = Collision.T_VECTORS.pop().copyFrom(circlePos).sub(points[prev]);
|
||||||
|
region = vornoiRegion(edge, point2);
|
||||||
|
|
||||||
|
if (region === Collision.RIGHT_VORNOI_REGION)
|
||||||
|
{
|
||||||
|
// It's in the region we want. Check if the circle intersects the point.
|
||||||
|
var dist = point.length2();
|
||||||
|
|
||||||
|
if (dist > radius)
|
||||||
|
{
|
||||||
|
// No intersection
|
||||||
|
Collision.T_VECTORS.push(circlePos);
|
||||||
|
Collision.T_VECTORS.push(edge);
|
||||||
|
Collision.T_VECTORS.push(point);
|
||||||
|
Collision.T_VECTORS.push(point2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (response)
|
||||||
|
{
|
||||||
|
// It intersects, calculate the overlap
|
||||||
|
response.bInA = false;
|
||||||
|
overlapN = point.normalize();
|
||||||
|
overlap = radius - dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.T_VECTORS.push(point2);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (region === Collision.RIGHT_VORNOI_REGION)
|
||||||
|
{
|
||||||
|
// Need to make sure we're in the left region on the next edge
|
||||||
|
edge.copyFrom(polygon.edges[next]);
|
||||||
|
|
||||||
|
// Calculate the center of the circle relative to the starting point of the next edge
|
||||||
|
point.copyFrom(circlePos).sub(points[next]);
|
||||||
|
region = vornoiRegion(edge, point);
|
||||||
|
|
||||||
|
if (region === Collision.LEFT_VORNOI_REGION)
|
||||||
|
{
|
||||||
|
// It's in the region we want. Check if the circle intersects the point.
|
||||||
|
var dist = point.length2();
|
||||||
|
|
||||||
|
if (dist > radius)
|
||||||
|
{
|
||||||
|
// No intersection
|
||||||
|
Collision.T_VECTORS.push(circlePos);
|
||||||
|
Collision.T_VECTORS.push(edge);
|
||||||
|
Collision.T_VECTORS.push(point);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (response)
|
||||||
|
{
|
||||||
|
// It intersects, calculate the overlap
|
||||||
|
response.bInA = false;
|
||||||
|
overlapN = point.normalize();
|
||||||
|
overlap = radius - dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// MIDDLE_VORNOI_REGION
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Need to check if the circle is intersecting the edge,
|
||||||
|
// Change the edge into its "edge normal".
|
||||||
|
var normal = edge.perp().normalize();
|
||||||
|
|
||||||
|
// Find the perpendicular distance between the center of the
|
||||||
|
// circle and the edge.
|
||||||
|
var dist = point.dot(normal);
|
||||||
|
var distAbs = Math.abs(dist);
|
||||||
|
|
||||||
|
// If the circle is on the outside of the edge, there is no intersection
|
||||||
|
if (dist > 0 && distAbs > radius)
|
||||||
|
{
|
||||||
|
Collision.T_VECTORS.push(circlePos);
|
||||||
|
Collision.T_VECTORS.push(normal);
|
||||||
|
Collision.T_VECTORS.push(point);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (response)
|
||||||
|
{
|
||||||
|
// It intersects, calculate the overlap.
|
||||||
|
overlapN = normal;
|
||||||
|
overlap = radius - dist;
|
||||||
|
// If the center of the circle is on the outside of the edge, or part of the
|
||||||
|
// circle is on the outside, the circle is not fully inside the polygon.
|
||||||
|
if (dist >= 0 || overlap < 2 * radius)
|
||||||
|
{
|
||||||
|
response.bInA = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is the smallest overlap we've seen, keep it.
|
||||||
|
// (overlapN may be null if the circle was in the wrong Vornoi region)
|
||||||
|
if (overlapN && response && Math.abs(overlap) < Math.abs(response.overlap))
|
||||||
|
{
|
||||||
|
response.overlap = overlap;
|
||||||
|
response.overlapN.copyFrom(overlapN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the final overlap vector - based on the smallest overlap.
|
||||||
|
if (response)
|
||||||
|
{
|
||||||
|
response.a = polygon;
|
||||||
|
response.b = circle;
|
||||||
|
response.overlapV.copyFrom(response.overlapN).scale(response.overlap);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collision.T_VECTORS.push(circlePos);
|
||||||
|
Collision.T_VECTORS.push(edge);
|
||||||
|
Collision.T_VECTORS.push(point);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a circle and a polygon intersect.
|
||||||
|
*
|
||||||
|
* NOTE: This runs slightly slower than polygonCircle as it just
|
||||||
|
* runs polygonCircle and reverses everything at the end.
|
||||||
|
*
|
||||||
|
* @param {Circle} circle The circle.
|
||||||
|
* @param {Polygon} polygon The polygon.
|
||||||
|
* @param {Response=} response Response object (optional) that will be populated if
|
||||||
|
* they interset.
|
||||||
|
* @return {boolean} true if they intersect, false if they don't.
|
||||||
|
*/
|
||||||
|
public static testCirclePolygon(circle: Circle, polygon: Polygon, response?: Response = null): bool {
|
||||||
|
|
||||||
|
var result = Collision.testPolygonCircle(polygon, circle, response);
|
||||||
|
|
||||||
|
if (result && response)
|
||||||
|
{
|
||||||
|
// Swap A and B in the response.
|
||||||
|
var a = response.a;
|
||||||
|
var aInB = response.aInB;
|
||||||
|
response.overlapN.reverse();
|
||||||
|
response.overlapV.reverse();
|
||||||
|
response.a = response.b;
|
||||||
|
response.b = a;
|
||||||
|
response.aInB = response.bInA;
|
||||||
|
response.bInA = aInB;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether two convex, clockwise polygons intersect.
|
||||||
|
*
|
||||||
|
* @param {Polygon} a The first polygon.
|
||||||
|
* @param {Polygon} b The second polygon.
|
||||||
|
* @param {Response=} response Response object (optional) that will be populated if
|
||||||
|
* they interset.
|
||||||
|
* @return {boolean} true if they intersect, false if they don't.
|
||||||
|
*/
|
||||||
|
public static testPolygonPolygon(a: Polygon, b: Polygon, response?: Response = null): bool {
|
||||||
|
|
||||||
|
var aPoints = a.points;
|
||||||
|
var aLen = aPoints.length;
|
||||||
|
var bPoints = b.points;
|
||||||
|
var bLen = bPoints.length;
|
||||||
|
|
||||||
|
// If any of the edge normals of A is a separating axis, no intersection.
|
||||||
|
for (var i = 0; i < aLen; i++)
|
||||||
|
{
|
||||||
|
if (Collision.isSeparatingAxis(a.pos, b.pos, aPoints, bPoints, a.normals[i], response))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If any of the edge normals of B is a separating axis, no intersection.
|
||||||
|
for (var i = 0; i < bLen; i++)
|
||||||
|
{
|
||||||
|
if (Collision.isSeparatingAxis(a.pos, b.pos, aPoints, bPoints, b.normals[i], response))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since none of the edge normals of A or B are a separating axis, there is an intersection
|
||||||
|
// and we've already calculated the smallest overlap (in isSeparatingAxis). Calculate the
|
||||||
|
// final overlap vector.
|
||||||
|
if (response)
|
||||||
|
{
|
||||||
|
response.a = a;
|
||||||
|
response.b = b;
|
||||||
|
response.overlapV.copyFrom(response.overlapN).scale(response.overlap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+125
-24
@@ -13,6 +13,14 @@ module Phaser {
|
|||||||
|
|
||||||
export class DynamicTexture {
|
export class DynamicTexture {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DynamicTexture constructor
|
||||||
|
* Create a new <code>DynamicTexture</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param width {number} Init width of this texture.
|
||||||
|
* @param height {number} Init height of this texture.
|
||||||
|
*/
|
||||||
constructor(game: Game, width: number, height: number) {
|
constructor(game: Game, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -26,6 +34,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
private _sx: number = 0;
|
private _sx: number = 0;
|
||||||
@@ -39,10 +50,30 @@ module Phaser {
|
|||||||
|
|
||||||
// Input / Output nodes?
|
// Input / Output nodes?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bound of this texture with width and height info.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public bounds: Rectangle;
|
public bounds: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is actually a wrapper of canvas.
|
||||||
|
* @type {HTMLCanvasElement}
|
||||||
|
*/
|
||||||
public canvas: HTMLCanvasElement;
|
public canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas context of this object.
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
public context: CanvasRenderingContext2D;
|
public context: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a color of a specific pixel.
|
||||||
|
* @param x {number} X position of the pixel in this texture.
|
||||||
|
* @param y {number} Y position of the pixel in this texture.
|
||||||
|
* @return {number} A native color value integer (format: 0xRRGGBB)
|
||||||
|
*/
|
||||||
public getPixel(x: number, y: number): number {
|
public getPixel(x: number, y: number): number {
|
||||||
|
|
||||||
//r = imageData.data[0];
|
//r = imageData.data[0];
|
||||||
@@ -55,6 +86,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a color of a specific pixel (including alpha value).
|
||||||
|
* @param x {number} X position of the pixel in this texture.
|
||||||
|
* @param y {number} Y position of the pixel in this texture.
|
||||||
|
* @return A native color value integer (format: 0xAARRGGBB)
|
||||||
|
*/
|
||||||
public getPixel32(x: number, y: number) {
|
public getPixel32(x: number, y: number) {
|
||||||
|
|
||||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||||
@@ -63,20 +100,36 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a CanvasPixelArray
|
/**
|
||||||
|
* Get pixels in array in a specific rectangle.
|
||||||
|
* @param rect {Rectangle} The specific rectangle.
|
||||||
|
* @returns {array} CanvasPixelArray.
|
||||||
|
*/
|
||||||
public getPixels(rect: Rectangle) {
|
public getPixels(rect: Rectangle) {
|
||||||
|
|
||||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setPixel(x: number, y: number, color: number) {
|
/**
|
||||||
|
* Set color of a specific pixel.
|
||||||
|
* @param x {number} X position of the target pixel.
|
||||||
|
* @param y {number} Y position of the target pixel.
|
||||||
|
* @param color {number} Native integer with color value. (format: 0xRRGGBB)
|
||||||
|
*/
|
||||||
|
public setPixel(x: number, y: number, color: string) {
|
||||||
|
|
||||||
this.context.fillStyle = color;
|
this.context.fillStyle = color;
|
||||||
this.context.fillRect(x, y, 1, 1);
|
this.context.fillRect(x, y, 1, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set color (with alpha) of a specific pixel.
|
||||||
|
* @param x {number} X position of the target pixel.
|
||||||
|
* @param y {number} Y position of the target pixel.
|
||||||
|
* @param color {number} Native integer with color value. (format: 0xAARRGGBB)
|
||||||
|
*/
|
||||||
public setPixel32(x: number, y: number, color: number) {
|
public setPixel32(x: number, y: number, color: number) {
|
||||||
|
|
||||||
this.context.fillStyle = color;
|
this.context.fillStyle = color;
|
||||||
@@ -84,12 +137,22 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set image data to a specific rectangle.
|
||||||
|
* @param rect {Rectangle} Target rectangle.
|
||||||
|
* @param input {object} Source image data.
|
||||||
|
*/
|
||||||
public setPixels(rect: Rectangle, input) {
|
public setPixels(rect: Rectangle, input) {
|
||||||
|
|
||||||
this.context.putImageData(input, rect.x, rect.y);
|
this.context.putImageData(input, rect.x, rect.y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
public fillRect(rect: Rectangle, color: number) {
|
||||||
|
|
||||||
this.context.fillStyle = color;
|
this.context.fillStyle = color;
|
||||||
@@ -97,6 +160,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
public pasteImage(key: string, frame?: number = -1, destX?: number = 0, destY?: number = 0, destWidth?: number = null, destHeight?: number = null) {
|
public pasteImage(key: string, frame?: number = -1, destX?: number = 0, destY?: number = 0, destWidth?: number = null, destHeight?: number = null) {
|
||||||
|
|
||||||
var texture = null;
|
var texture = null;
|
||||||
@@ -138,21 +204,27 @@ module Phaser {
|
|||||||
if (texture != null)
|
if (texture != null)
|
||||||
{
|
{
|
||||||
this.context.drawImage(
|
this.context.drawImage(
|
||||||
texture, // Source Image
|
texture, // Source Image
|
||||||
this._sx, // Source X (location within the source image)
|
this._sx, // Source X (location within the source image)
|
||||||
this._sy, // Source Y
|
this._sy, // Source Y
|
||||||
this._sw, // Source Width
|
this._sw, // Source Width
|
||||||
this._sh, // Source Height
|
this._sh, // Source Height
|
||||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||||
this._dy, // Destination Y
|
this._dy, // Destination Y
|
||||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
|
// TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
|
||||||
|
/**
|
||||||
|
* 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 destPoint {Point} Top-left point the target image data will be paste at.
|
||||||
|
*/
|
||||||
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
|
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
|
||||||
|
|
||||||
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
||||||
@@ -167,12 +239,41 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an array of GameObjects it will update each of them so that their canvas/contexts reference this DynamicTexture
|
||||||
|
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
|
||||||
|
*/
|
||||||
|
public assignCanvasToGameObjects(objects: GameObject[]) {
|
||||||
|
|
||||||
|
for (var i = 0; i < objects.length; i++)
|
||||||
|
{
|
||||||
|
objects[i].canvas = this.canvas;
|
||||||
|
objects[i].context = this.context;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the whole canvas.
|
||||||
|
*/
|
||||||
public clear() {
|
public clear() {
|
||||||
|
|
||||||
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
|
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders this DynamicTexture to the Stage at the given x/y coordinates
|
||||||
|
*
|
||||||
|
* @param x {number} The X coordinate to render on the stage to (given in screen coordinates, not world)
|
||||||
|
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
|
||||||
|
*/
|
||||||
|
public render(x?: number = 0, y?: number = 0) {
|
||||||
|
|
||||||
|
this._game.stage.context.drawImage(this.canvas, x, y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public get width(): number {
|
public get width(): number {
|
||||||
return this.bounds.width;
|
return this.bounds.width;
|
||||||
}
|
}
|
||||||
@@ -183,13 +284,13 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an alpha and 3 color values this will return an integer representation of it
|
* Given an alpha and 3 color values this will return an integer representation of it
|
||||||
*
|
*
|
||||||
* @param alpha The Alpha value (between 0 and 255)
|
* @param alpha {number} The Alpha value (between 0 and 255)
|
||||||
* @param red The Red channel value (between 0 and 255)
|
* @param red {number} The Red channel value (between 0 and 255)
|
||||||
* @param green The Green channel value (between 0 and 255)
|
* @param green {number} The Green channel value (between 0 and 255)
|
||||||
* @param blue The Blue channel value (between 0 and 255)
|
* @param blue {number} The Blue channel value (between 0 and 255)
|
||||||
*
|
*
|
||||||
* @return A native color value integer (format: 0xAARRGGBB)
|
* @return A native color value integer (format: 0xAARRGGBB)
|
||||||
*/
|
*/
|
||||||
private getColor32(alpha: number, red: number, green: number, blue: number): number {
|
private getColor32(alpha: number, red: number, green: number, blue: number): number {
|
||||||
|
|
||||||
@@ -199,12 +300,12 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given 3 color values this will return an integer representation of it
|
* Given 3 color values this will return an integer representation of it
|
||||||
*
|
*
|
||||||
* @param red The Red channel value (between 0 and 255)
|
* @param red {number} The Red channel value (between 0 and 255)
|
||||||
* @param green The Green channel value (between 0 and 255)
|
* @param green {number} The Green channel value (between 0 and 255)
|
||||||
* @param blue The Blue channel value (between 0 and 255)
|
* @param blue {number} The Blue channel value (between 0 and 255)
|
||||||
*
|
*
|
||||||
* @return A native color value integer (format: 0xRRGGBB)
|
* @return A native color value integer (format: 0xRRGGBB)
|
||||||
*/
|
*/
|
||||||
private getColor(red: number, green: number, blue: number): number {
|
private getColor(red: number, green: number, blue: number): number {
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ module Phaser {
|
|||||||
* Adds a new FX to the FXManager.
|
* Adds a new FX to the FXManager.
|
||||||
* The effect must be an object with at least one of the following methods: preUpdate, postUpdate, preRender, render or postRender.
|
* The effect must be an object with at least one of the following methods: preUpdate, postUpdate, preRender, render or postRender.
|
||||||
* A new instance of the effect will be created and a reference to Game will be passed to the object constructor.
|
* A new instance of the effect will be created and a reference to Game will be passed to the object constructor.
|
||||||
|
* @param {object} effect
|
||||||
|
* @return {any}
|
||||||
*/
|
*/
|
||||||
public add(effect): any {
|
public add(effect): any {
|
||||||
|
|
||||||
@@ -154,6 +156,11 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
|
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
|
||||||
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
|
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
|
||||||
|
* @param {Camera} camera
|
||||||
|
* @param {number} cameraX
|
||||||
|
* @param {number} cameraY
|
||||||
|
* @param {number} cameraWidth
|
||||||
|
* @param {number} cameraHeight
|
||||||
*/
|
*/
|
||||||
public preRender(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
|
public preRender(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
|
||||||
|
|
||||||
@@ -172,6 +179,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
|
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
|
||||||
|
* @param {Camera} camera
|
||||||
|
* @param {number} cameraX
|
||||||
|
* @param {number} cameraY
|
||||||
|
* @param {number} cameraWidth
|
||||||
|
* @param {number} cameraHeight
|
||||||
*/
|
*/
|
||||||
public render(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
|
public render(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
|
||||||
|
|
||||||
|
|||||||
+272
-73
@@ -6,6 +6,7 @@
|
|||||||
/// <reference path="DynamicTexture.ts" />
|
/// <reference path="DynamicTexture.ts" />
|
||||||
/// <reference path="FXManager.ts" />
|
/// <reference path="FXManager.ts" />
|
||||||
/// <reference path="GameMath.ts" />
|
/// <reference path="GameMath.ts" />
|
||||||
|
/// <reference path="GameObjectFactory.ts" />
|
||||||
/// <reference path="Group.ts" />
|
/// <reference path="Group.ts" />
|
||||||
/// <reference path="Loader.ts" />
|
/// <reference path="Loader.ts" />
|
||||||
/// <reference path="Motion.ts" />
|
/// <reference path="Motion.ts" />
|
||||||
@@ -15,13 +16,16 @@
|
|||||||
/// <reference path="Stage.ts" />
|
/// <reference path="Stage.ts" />
|
||||||
/// <reference path="Time.ts" />
|
/// <reference path="Time.ts" />
|
||||||
/// <reference path="TweenManager.ts" />
|
/// <reference path="TweenManager.ts" />
|
||||||
|
/// <reference path="VerletManager.ts" />
|
||||||
/// <reference path="World.ts" />
|
/// <reference path="World.ts" />
|
||||||
|
/// <reference path="geom/Vector2.ts" />
|
||||||
/// <reference path="system/Device.ts" />
|
/// <reference path="system/Device.ts" />
|
||||||
/// <reference path="system/RandomDataGenerator.ts" />
|
/// <reference path="system/RandomDataGenerator.ts" />
|
||||||
/// <reference path="system/RequestAnimationFrame.ts" />
|
/// <reference path="system/RequestAnimationFrame.ts" />
|
||||||
/// <reference path="system/input/Input.ts" />
|
/// <reference path="system/input/Input.ts" />
|
||||||
/// <reference path="system/input/Keyboard.ts" />
|
/// <reference path="system/input/Keyboard.ts" />
|
||||||
/// <reference path="system/input/Mouse.ts" />
|
/// <reference path="system/input/Mouse.ts" />
|
||||||
|
/// <reference path="system/input/MSPointer.ts" />
|
||||||
/// <reference path="system/input/Touch.ts" />
|
/// <reference path="system/input/Touch.ts" />
|
||||||
/// <reference path="gameobjects/Emitter.ts" />
|
/// <reference path="gameobjects/Emitter.ts" />
|
||||||
/// <reference path="gameobjects/GameObject.ts" />
|
/// <reference path="gameobjects/GameObject.ts" />
|
||||||
@@ -34,7 +38,7 @@
|
|||||||
/**
|
/**
|
||||||
* Phaser - Game
|
* Phaser - Game
|
||||||
*
|
*
|
||||||
* This is where the magic happens. The Game object is the heart of your game,
|
* This is where the magic happens. The Game object is the heart of your game,
|
||||||
* providing quick access to common functions and handling the boot process.
|
* providing quick access to common functions and handling the boot process.
|
||||||
*
|
*
|
||||||
* "Hell, there are no rules here - we're trying to accomplish something."
|
* "Hell, there are no rules here - we're trying to accomplish something."
|
||||||
@@ -45,13 +49,29 @@ module Phaser {
|
|||||||
|
|
||||||
export class Game {
|
export class Game {
|
||||||
|
|
||||||
constructor(callbackContext, parent?: string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
|
/**
|
||||||
|
* Game constructor
|
||||||
|
*
|
||||||
|
* Instantiate a new <code>Phaser.Game</code> object.
|
||||||
|
*
|
||||||
|
* @param callbackContext Which context will the callbacks be called with.
|
||||||
|
* @param parent {string} ID of its parent DOM element.
|
||||||
|
* @param width {number} The width of your game in game pixels.
|
||||||
|
* @param height {number} The height of your game in game pixels.
|
||||||
|
* @param initCallback {function} Init callback invoked when init default screen.
|
||||||
|
* @param createCallback {function} Create callback invoked when create default screen.
|
||||||
|
* @param updateCallback {function} Update callback invoked when update default screen.
|
||||||
|
* @param renderCallback {function} Render callback invoked when render default screen.
|
||||||
|
* @param destroyCallback {function} Destroy callback invoked when state is destroyed.
|
||||||
|
*/
|
||||||
|
constructor(callbackContext, parent?: string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null, destroyCallback = null) {
|
||||||
|
|
||||||
this.callbackContext = callbackContext;
|
this.callbackContext = callbackContext;
|
||||||
this.onInitCallback = initCallback;
|
this.onInitCallback = initCallback;
|
||||||
this.onCreateCallback = createCallback;
|
this.onCreateCallback = createCallback;
|
||||||
this.onUpdateCallback = updateCallback;
|
this.onUpdateCallback = updateCallback;
|
||||||
this.onRenderCallback = renderCallback;
|
this.onRenderCallback = renderCallback;
|
||||||
|
this.onDestroyCallback = destroyCallback;
|
||||||
|
|
||||||
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
||||||
{
|
{
|
||||||
@@ -65,39 +85,202 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _raf: RequestAnimationFrame;
|
/**
|
||||||
|
* Game loop trigger wrapper.
|
||||||
|
*/
|
||||||
|
public _raf: RequestAnimationFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Max allowable accumulation.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _maxAccumulation: number = 32;
|
private _maxAccumulation: number = 32;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total number of milliseconds elapsed since last update loop.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _accumulator: number = 0;
|
private _accumulator: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Milliseconds of time per step of the game loop.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _step: number = 0;
|
private _step: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether loader complete loading or not.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
private _loadComplete: bool = false;
|
private _loadComplete: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game is paused?
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
private _paused: bool = false;
|
private _paused: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state to be switched to in the next frame.
|
||||||
|
* @type {State}
|
||||||
|
*/
|
||||||
private _pendingState = null;
|
private _pendingState = null;
|
||||||
|
|
||||||
// Event callbacks
|
/**
|
||||||
|
* The current State object (defaults to null)
|
||||||
|
* @type {State}
|
||||||
|
*/
|
||||||
|
public state = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context for calling the callbacks.
|
||||||
|
*/
|
||||||
public callbackContext;
|
public callbackContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be called when init states. (loading assets...)
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
public onInitCallback = null;
|
public onInitCallback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be called when create states. (setup states...)
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
public onCreateCallback = null;
|
public onCreateCallback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be called when update states.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
public onUpdateCallback = null;
|
public onUpdateCallback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be called when render states.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
public onRenderCallback = null;
|
public onRenderCallback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be called when states paused.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
public onPausedCallback = null;
|
public onPausedCallback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be called when the state is destroyed (i.e. swapping to a new state)
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
|
public onDestroyCallback = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the GameObject Factory.
|
||||||
|
* @type {GameObjectFactory}
|
||||||
|
*/
|
||||||
|
public add: GameObjectFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the assets cache.
|
||||||
|
* @type {Cache}
|
||||||
|
*/
|
||||||
public cache: Cache;
|
public cache: Cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the collision helper.
|
||||||
|
* @type {Collision}
|
||||||
|
*/
|
||||||
public collision: Collision;
|
public collision: Collision;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the input manager
|
||||||
|
* @type {Input}
|
||||||
|
*/
|
||||||
public input: Input;
|
public input: Input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the assets loader.
|
||||||
|
* @type {Loader}
|
||||||
|
*/
|
||||||
public loader: Loader;
|
public loader: Loader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the math helper.
|
||||||
|
* @type {GameMath}
|
||||||
|
*/
|
||||||
public math: GameMath;
|
public math: GameMath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the motion helper.
|
||||||
|
* @type {Motion}
|
||||||
|
*/
|
||||||
public motion: Motion;
|
public motion: Motion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the sound manager.
|
||||||
|
* @type {SoundManager}
|
||||||
|
*/
|
||||||
public sound: SoundManager;
|
public sound: SoundManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the stage.
|
||||||
|
* @type {Stage}
|
||||||
|
*/
|
||||||
public stage: Stage;
|
public stage: Stage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to game clock.
|
||||||
|
* @type {Time}
|
||||||
|
*/
|
||||||
public time: Time;
|
public time: Time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the tween manager.
|
||||||
|
* @type {TweenManager}
|
||||||
|
*/
|
||||||
public tweens: TweenManager;
|
public tweens: TweenManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the verlet manager.
|
||||||
|
* @type {VerletManager}
|
||||||
|
*/
|
||||||
|
public verlet: Phaser.Verlet.VerletManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the world.
|
||||||
|
* @type {World}
|
||||||
|
*/
|
||||||
public world: World;
|
public world: World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of repeatable random data generator helper.
|
||||||
|
* @type {RandomDataGenerator}
|
||||||
|
*/
|
||||||
public rnd: RandomDataGenerator;
|
public rnd: RandomDataGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains device information and capabilities.
|
||||||
|
* @type {Device}
|
||||||
|
*/
|
||||||
public device: Device;
|
public device: Device;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the game engine is booted, aka available.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public isBooted: bool = false;
|
public isBooted: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is game running or paused?
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public isRunning: bool = false;
|
public isRunning: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize engine sub modules and start the game.
|
||||||
|
* @param parent {string} ID of parent Dom element.
|
||||||
|
* @param width {number} Width of the game screen.
|
||||||
|
* @param height {number} Height of the game screen.
|
||||||
|
*/
|
||||||
private boot(parent: string, width: number, height: number) {
|
private boot(parent: string, width: number, height: number) {
|
||||||
|
|
||||||
if (this.isBooted == true)
|
if (this.isBooted == true)
|
||||||
@@ -116,6 +299,7 @@ module Phaser {
|
|||||||
this.math = new GameMath(this);
|
this.math = new GameMath(this);
|
||||||
this.stage = new Stage(this, parent, width, height);
|
this.stage = new Stage(this, parent, width, height);
|
||||||
this.world = new World(this, width, height);
|
this.world = new World(this, width, height);
|
||||||
|
this.add = new GameObjectFactory(this);
|
||||||
this.sound = new SoundManager(this);
|
this.sound = new SoundManager(this);
|
||||||
this.cache = new Cache(this);
|
this.cache = new Cache(this);
|
||||||
this.collision = new Collision(this);
|
this.collision = new Collision(this);
|
||||||
@@ -124,21 +308,23 @@ module Phaser {
|
|||||||
this.tweens = new TweenManager(this);
|
this.tweens = new TweenManager(this);
|
||||||
this.input = new Input(this);
|
this.input = new Input(this);
|
||||||
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
||||||
|
this.verlet = new Phaser.Verlet.VerletManager(this, width, height);
|
||||||
|
|
||||||
this.framerate = 60;
|
this.framerate = 60;
|
||||||
this.isBooted = true;
|
this.isBooted = true;
|
||||||
|
this.input.start();
|
||||||
|
|
||||||
// Display the default game screen?
|
// Display the default game screen?
|
||||||
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
|
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
|
||||||
{
|
{
|
||||||
this._raf = new RequestAnimationFrame(this.bootLoop, this);
|
this._raf = new RequestAnimationFrame(this, this.bootLoop);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
this._loadComplete = false;
|
this._loadComplete = false;
|
||||||
|
|
||||||
this._raf = new RequestAnimationFrame(this.loop, this);
|
this._raf = new RequestAnimationFrame(this, this.loop);
|
||||||
|
|
||||||
if (this._pendingState)
|
if (this._pendingState)
|
||||||
{
|
{
|
||||||
@@ -155,25 +341,31 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the loader has finished after init was run.
|
||||||
|
*/
|
||||||
private loadComplete() {
|
private loadComplete() {
|
||||||
|
|
||||||
// Called when the loader has finished after init was run
|
|
||||||
this._loadComplete = true;
|
this._loadComplete = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game loop method will be called when it's booting.
|
||||||
|
*/
|
||||||
private bootLoop() {
|
private bootLoop() {
|
||||||
|
|
||||||
this.time.update();
|
|
||||||
this.tweens.update();
|
this.tweens.update();
|
||||||
this.input.update();
|
this.input.update();
|
||||||
this.stage.update();
|
this.stage.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game loop method will be called when it's paused.
|
||||||
|
*/
|
||||||
private pausedLoop() {
|
private pausedLoop() {
|
||||||
|
|
||||||
this.time.update();
|
|
||||||
this.tweens.update();
|
this.tweens.update();
|
||||||
this.input.update();
|
this.input.update();
|
||||||
this.stage.update();
|
this.stage.update();
|
||||||
@@ -185,12 +377,15 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game loop method will be called when it's running.
|
||||||
|
*/
|
||||||
private loop() {
|
private loop() {
|
||||||
|
|
||||||
this.time.update();
|
|
||||||
this.tweens.update();
|
this.tweens.update();
|
||||||
this.input.update();
|
this.input.update();
|
||||||
this.stage.update();
|
this.stage.update();
|
||||||
|
this.verlet.update();
|
||||||
|
|
||||||
this._accumulator += this.time.delta;
|
this._accumulator += this.time.delta;
|
||||||
|
|
||||||
@@ -220,6 +415,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start current state.
|
||||||
|
*/
|
||||||
private startState() {
|
private startState() {
|
||||||
|
|
||||||
if (this.onInitCallback !== null)
|
if (this.onInitCallback !== null)
|
||||||
@@ -252,15 +450,30 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCallbacks(initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
|
/**
|
||||||
|
* Set all state callbacks (init, create, update, render).
|
||||||
|
* @param initCallback {function} Init callback invoked when init state.
|
||||||
|
* @param createCallback {function} Create callback invoked when create state.
|
||||||
|
* @param updateCallback {function} Update callback invoked when update state.
|
||||||
|
* @param renderCallback {function} Render callback invoked when render state.
|
||||||
|
* @param destroyCallback {function} Destroy callback invoked when state is destroyed.
|
||||||
|
*/
|
||||||
|
public setCallbacks(initCallback = null, createCallback = null, updateCallback = null, renderCallback = null, destroyCallback = null) {
|
||||||
|
|
||||||
this.onInitCallback = initCallback;
|
this.onInitCallback = initCallback;
|
||||||
this.onCreateCallback = createCallback;
|
this.onCreateCallback = createCallback;
|
||||||
this.onUpdateCallback = updateCallback;
|
this.onUpdateCallback = updateCallback;
|
||||||
this.onRenderCallback = renderCallback;
|
this.onRenderCallback = renderCallback;
|
||||||
|
this.onDestroyCallback = destroyCallback;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch to a new State.
|
||||||
|
* @param state {State} The state you want to switch to.
|
||||||
|
* @param [clearWorld] {boolean} clear everything in the world? (Default to true)
|
||||||
|
* @param [clearCache] {boolean} clear asset cache? (Default to false and ONLY available when clearWorld=true)
|
||||||
|
*/
|
||||||
public switchState(state, clearWorld: bool = true, clearCache: bool = false) {
|
public switchState(state, clearWorld: bool = true, clearCache: bool = false) {
|
||||||
|
|
||||||
if (this.isBooted == false)
|
if (this.isBooted == false)
|
||||||
@@ -269,47 +482,61 @@ module Phaser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destroy current state?
|
||||||
|
if (this.onDestroyCallback !== null)
|
||||||
|
{
|
||||||
|
this.onDestroyCallback.call(this.callbackContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.input.reset(true);
|
||||||
|
|
||||||
// Prototype?
|
// Prototype?
|
||||||
if (typeof state === 'function')
|
if (typeof state === 'function')
|
||||||
{
|
{
|
||||||
state = new state(this);
|
this.state = new state(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok, have we got the right functions?
|
// Ok, have we got the right functions?
|
||||||
if (state['create'] || state['update'])
|
if (this.state['create'] || this.state['update'])
|
||||||
{
|
{
|
||||||
this.callbackContext = state;
|
this.callbackContext = this.state;
|
||||||
|
|
||||||
this.onInitCallback = null;
|
this.onInitCallback = null;
|
||||||
this.onCreateCallback = null;
|
this.onCreateCallback = null;
|
||||||
this.onUpdateCallback = null;
|
this.onUpdateCallback = null;
|
||||||
this.onRenderCallback = null;
|
this.onRenderCallback = null;
|
||||||
this.onPausedCallback = null;
|
this.onPausedCallback = null;
|
||||||
|
this.onDestroyCallback = null;
|
||||||
|
|
||||||
// Bingo, let's set them up
|
// Bingo, let's set them up
|
||||||
if (state['init'])
|
if (this.state['init'])
|
||||||
{
|
{
|
||||||
this.onInitCallback = state['init'];
|
this.onInitCallback = this.state['init'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state['create'])
|
if (this.state['create'])
|
||||||
{
|
{
|
||||||
this.onCreateCallback = state['create'];
|
this.onCreateCallback = this.state['create'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state['update'])
|
if (this.state['update'])
|
||||||
{
|
{
|
||||||
this.onUpdateCallback = state['update'];
|
this.onUpdateCallback = this.state['update'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state['render'])
|
if (this.state['render'])
|
||||||
{
|
{
|
||||||
this.onRenderCallback = state['render'];
|
this.onRenderCallback = this.state['render'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state['paused'])
|
if (this.state['paused'])
|
||||||
{
|
{
|
||||||
this.onPausedCallback = state['paused'];
|
this.onPausedCallback = this.state['paused'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state['destroy'])
|
||||||
|
{
|
||||||
|
this.onDestroyCallback = this.state['destroy'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearWorld)
|
if (clearWorld)
|
||||||
@@ -333,7 +560,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nuke the whole game from orbit
|
/**
|
||||||
|
* Nuke the whole game from orbit
|
||||||
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
|
||||||
this.callbackContext = null;
|
this.callbackContext = null;
|
||||||
@@ -342,6 +571,7 @@ module Phaser {
|
|||||||
this.onUpdateCallback = null;
|
this.onUpdateCallback = null;
|
||||||
this.onRenderCallback = null;
|
this.onRenderCallback = null;
|
||||||
this.onPausedCallback = null;
|
this.onPausedCallback = null;
|
||||||
|
this.onDestroyCallback = null;
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
this.input = null;
|
this.input = null;
|
||||||
this.loader = null;
|
this.loader = null;
|
||||||
@@ -362,20 +592,21 @@ module Phaser {
|
|||||||
if (value == true && this._paused == false)
|
if (value == true && this._paused == false)
|
||||||
{
|
{
|
||||||
this._paused = true;
|
this._paused = true;
|
||||||
this._raf.setCallback(this.pausedLoop);
|
this._raf.callback = this.pausedLoop;
|
||||||
}
|
}
|
||||||
else if (value == false && this._paused == true)
|
else if (value == false && this._paused == true)
|
||||||
{
|
{
|
||||||
this._paused = false;
|
this._paused = false;
|
||||||
this.time.time = Date.now();
|
//this.time.time = window.performance.now ? (performance.now() + performance.timing.navigationStart) : Date.now();
|
||||||
this.input.reset();
|
this.input.reset();
|
||||||
|
|
||||||
if (this.isRunning == false)
|
if (this.isRunning == false)
|
||||||
{
|
{
|
||||||
this._raf.setCallback(this.bootLoop);
|
this._raf.callback = this.bootLoop;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._raf.setCallback(this.loop);
|
this._raf.callback = this.loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,50 +627,18 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handy Proxy methods
|
/**
|
||||||
|
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
|
||||||
return this.world.createCamera(x, y, width, height);
|
* @param object1 The first GameObject or Group to check. If null the world.group is used.
|
||||||
}
|
* @param object2 The second GameObject or Group to check.
|
||||||
|
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
|
||||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
|
||||||
return this.world.createGeomSprite(x, y);
|
* @param context The context in which the callbacks will be called
|
||||||
}
|
* @returns {boolean} true if the objects overlap, otherwise false.
|
||||||
|
*/
|
||||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
public collide(objectOrGroup1: Basic = null, objectOrGroup2: Basic = null, notifyCallback = null, context? = this.callbackContext): bool {
|
||||||
return this.world.createSprite(x, y, key);
|
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
|
||||||
}
|
|
||||||
|
|
||||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
|
||||||
return this.world.createDynamicTexture(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGroup(MaxSize?: number = 0): Group {
|
|
||||||
return this.world.createGroup(MaxSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParticle(): Particle {
|
|
||||||
return this.world.createParticle();
|
|
||||||
}
|
|
||||||
|
|
||||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
|
||||||
return this.world.createEmitter(x, y, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
|
||||||
return this.world.createScrollZone(key, x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
|
||||||
return this.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTween(obj): Tween {
|
|
||||||
return this.tweens.create(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public collide(objectOrGroup1: Basic = null, objectOrGroup2: Basic = null, notifyCallback = null): bool {
|
|
||||||
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get camera(): Camera {
|
public get camera(): Camera {
|
||||||
|
|||||||
+128
-64
@@ -152,7 +152,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* force a value within the boundaries of two values
|
* force a value within the boundaries of two values
|
||||||
*
|
*
|
||||||
* if max < min, min is returned
|
* if max < min, min is returned
|
||||||
*/
|
*/
|
||||||
public clamp(input: number, max: number, min: number = 0): number {
|
public clamp(input: number, max: number, min: number = 0): number {
|
||||||
@@ -161,12 +161,12 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Snap a value to nearest grid slice, using rounding.
|
* Snap a value to nearest grid slice, using rounding.
|
||||||
*
|
*
|
||||||
* example if you have an interval gap of 5 and a position of 12... you will snap to 10. Where as 14 will snap to 15
|
* example if you have an interval gap of 5 and a position of 12... you will snap to 10. Where as 14 will snap to 15
|
||||||
*
|
*
|
||||||
* @param input - the value to snap
|
* @param input - the value to snap
|
||||||
* @param gap - the interval gap of the grid
|
* @param gap - the interval gap of the grid
|
||||||
* @param start - optional starting offset for gap
|
* @param [start] - optional starting offset for gap
|
||||||
*/
|
*/
|
||||||
public snapTo(input: number, gap: number, start: number = 0): number {
|
public snapTo(input: number, gap: number, start: number = 0): number {
|
||||||
if (gap == 0) return input;
|
if (gap == 0) return input;
|
||||||
@@ -178,12 +178,12 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Snap a value to nearest grid slice, using floor.
|
* Snap a value to nearest grid slice, using floor.
|
||||||
*
|
*
|
||||||
* example if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15
|
* example if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15
|
||||||
*
|
*
|
||||||
* @param input - the value to snap
|
* @param input - the value to snap
|
||||||
* @param gap - the interval gap of the grid
|
* @param gap - the interval gap of the grid
|
||||||
* @param start - optional starting offset for gap
|
* @param [start] - optional starting offset for gap
|
||||||
*/
|
*/
|
||||||
public snapToFloor(input: number, gap: number, start: number = 0): number {
|
public snapToFloor(input: number, gap: number, start: number = 0): number {
|
||||||
if (gap == 0) return input;
|
if (gap == 0) return input;
|
||||||
@@ -195,12 +195,12 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Snap a value to nearest grid slice, using ceil.
|
* Snap a value to nearest grid slice, using ceil.
|
||||||
*
|
*
|
||||||
* example if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20
|
* example if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20
|
||||||
*
|
*
|
||||||
* @param input - the value to snap
|
* @param input - the value to snap
|
||||||
* @param gap - the interval gap of the grid
|
* @param gap - the interval gap of the grid
|
||||||
* @param start - optional starting offset for gap
|
* @param [start] - optional starting offset for gap
|
||||||
*/
|
*/
|
||||||
public snapToCeil(input: number, gap: number, start: number = 0): number {
|
public snapToCeil(input: number, gap: number, start: number = 0): number {
|
||||||
if (gap == 0) return input;
|
if (gap == 0) return input;
|
||||||
@@ -231,17 +231,17 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* roundTo some place comparative to a 'base', default is 10 for decimal place
|
* roundTo some place comparative to a 'base', default is 10 for decimal place
|
||||||
*
|
*
|
||||||
* 'place' is represented by the power applied to 'base' to get that place
|
* 'place' is represented by the power applied to 'base' to get that place
|
||||||
*
|
*
|
||||||
* @param value - the value to round
|
* @param value - the value to round
|
||||||
* @param place - the place to round to
|
* @param place - the place to round to
|
||||||
* @param base - the base to round in... default is 10 for decimal
|
* @param base - the base to round in... default is 10 for decimal
|
||||||
*
|
*
|
||||||
* e.g.
|
* e.g.
|
||||||
*
|
*
|
||||||
* 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011
|
* 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011
|
||||||
*
|
*
|
||||||
* roundTo(2000/7,3) == 0
|
* roundTo(2000/7,3) == 0
|
||||||
* roundTo(2000/7,2) == 300
|
* roundTo(2000/7,2) == 300
|
||||||
* roundTo(2000/7,1) == 290
|
* roundTo(2000/7,1) == 290
|
||||||
@@ -251,7 +251,7 @@ module Phaser {
|
|||||||
* roundTo(2000/7,-3) == 285.714
|
* roundTo(2000/7,-3) == 285.714
|
||||||
* roundTo(2000/7,-4) == 285.7143
|
* roundTo(2000/7,-4) == 285.7143
|
||||||
* roundTo(2000/7,-5) == 285.71429
|
* roundTo(2000/7,-5) == 285.71429
|
||||||
*
|
*
|
||||||
* roundTo(2000/7,3,2) == 288 -- 100100000
|
* roundTo(2000/7,3,2) == 288 -- 100100000
|
||||||
* roundTo(2000/7,2,2) == 284 -- 100011100
|
* roundTo(2000/7,2,2) == 284 -- 100011100
|
||||||
* roundTo(2000/7,1,2) == 286 -- 100011110
|
* roundTo(2000/7,1,2) == 286 -- 100011110
|
||||||
@@ -261,8 +261,8 @@ module Phaser {
|
|||||||
* roundTo(2000/7,-3,2) == 285.75 -- 100011101.11
|
* roundTo(2000/7,-3,2) == 285.75 -- 100011101.11
|
||||||
* roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011
|
* roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011
|
||||||
* roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111
|
* roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111
|
||||||
*
|
*
|
||||||
* note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed
|
* note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed
|
||||||
* because we are rounding 100011.1011011011011011 which rounds up.
|
* because we are rounding 100011.1011011011011011 which rounds up.
|
||||||
*/
|
*/
|
||||||
public roundTo(value: number, place: number = 0, base: number = 10): number {
|
public roundTo(value: number, place: number = 0, base: number = 10): number {
|
||||||
@@ -336,7 +336,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* normalizes independent and then sets dep to the nearest value respective to independent
|
* normalizes independent and then sets dep to the nearest value respective to independent
|
||||||
*
|
*
|
||||||
* for instance if dep=-170 and ind=170 then 190 will be returned as an alternative to -170
|
* for instance if dep=-170 and ind=170 then 190 will be returned as an alternative to -170
|
||||||
*/
|
*/
|
||||||
public normalizeAngleToAnother(dep: number, ind: number, radians: bool = true): number {
|
public normalizeAngleToAnother(dep: number, ind: number, radians: bool = true): number {
|
||||||
@@ -345,7 +345,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* normalize independent and dependent and then set dependent to an angle relative to 'after/clockwise' independent
|
* normalize independent and dependent and then set dependent to an angle relative to 'after/clockwise' independent
|
||||||
*
|
*
|
||||||
* for instance dep=-170 and ind=170, then 190 will be reutrned as alternative to -170
|
* for instance dep=-170 and ind=170, then 190 will be reutrned as alternative to -170
|
||||||
*/
|
*/
|
||||||
public normalizeAngleAfterAnother(dep: number, ind: number, radians: bool = true): number {
|
public normalizeAngleAfterAnother(dep: number, ind: number, radians: bool = true): number {
|
||||||
@@ -356,7 +356,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* normalizes indendent and dependent and then sets dependent to an angle relative to 'before/counterclockwise' independent
|
* normalizes indendent and dependent and then sets dependent to an angle relative to 'before/counterclockwise' independent
|
||||||
*
|
*
|
||||||
* for instance dep = 190 and ind = 170, then -170 will be returned as an alternative to 190
|
* for instance dep = 190 and ind = 170, then -170 will be returned as an alternative to 190
|
||||||
*/
|
*/
|
||||||
public normalizeAngleBeforeAnother(dep: number, ind: number, radians: bool = true): number {
|
public normalizeAngleBeforeAnother(dep: number, ind: number, radians: bool = true): number {
|
||||||
@@ -378,17 +378,17 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the logarithm of any value of any base
|
* Compute the logarithm of any value of any base
|
||||||
*
|
*
|
||||||
* a logarithm is the exponent that some constant (base) would have to be raised to
|
* a logarithm is the exponent that some constant (base) would have to be raised to
|
||||||
* to be equal to value.
|
* to be equal to value.
|
||||||
*
|
*
|
||||||
* i.e.
|
* i.e.
|
||||||
* 4 ^ x = 16
|
* 4 ^ x = 16
|
||||||
* can be rewritten as to solve for x
|
* can be rewritten as to solve for x
|
||||||
* logB4(16) = x
|
* logB4(16) = x
|
||||||
* which with this function would be
|
* which with this function would be
|
||||||
* LoDMath.logBaseOf(16,4)
|
* LoDMath.logBaseOf(16,4)
|
||||||
*
|
*
|
||||||
* which would return 2, because 4^2 = 16
|
* which would return 2, because 4^2 = 16
|
||||||
*/
|
*/
|
||||||
public logBaseOf(value: number, base: number): number {
|
public logBaseOf(value: number, base: number): number {
|
||||||
@@ -434,9 +434,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Factorial - N!
|
* Factorial - N!
|
||||||
*
|
*
|
||||||
* simple product series
|
* simple product series
|
||||||
*
|
*
|
||||||
* by definition:
|
* by definition:
|
||||||
* 0! == 1
|
* 0! == 1
|
||||||
*/
|
*/
|
||||||
@@ -455,7 +455,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* gamma function
|
* gamma function
|
||||||
*
|
*
|
||||||
* defined: gamma(N) == (N - 1)!
|
* defined: gamma(N) == (N - 1)!
|
||||||
*/
|
*/
|
||||||
public gammaFunction(value: number): number {
|
public gammaFunction(value: number): number {
|
||||||
@@ -464,9 +464,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* falling factorial
|
* falling factorial
|
||||||
*
|
*
|
||||||
* defined: (N)! / (N - x)!
|
* defined: (N)! / (N - x)!
|
||||||
*
|
*
|
||||||
* written subscript: (N)x OR (base)exp
|
* written subscript: (N)x OR (base)exp
|
||||||
*/
|
*/
|
||||||
public fallingFactorial(base: number, exp: number): number {
|
public fallingFactorial(base: number, exp: number): number {
|
||||||
@@ -475,9 +475,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* rising factorial
|
* rising factorial
|
||||||
*
|
*
|
||||||
* defined: (N + x - 1)! / (N - 1)!
|
* defined: (N + x - 1)! / (N - 1)!
|
||||||
*
|
*
|
||||||
* written superscript N^(x) OR base^(exp)
|
* written superscript N^(x) OR base^(exp)
|
||||||
*/
|
*/
|
||||||
public risingFactorial(base: number, exp: number): number {
|
public risingFactorial(base: number, exp: number): number {
|
||||||
@@ -487,7 +487,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* binomial coefficient
|
* binomial coefficient
|
||||||
*
|
*
|
||||||
* defined: N! / (k!(N-k)!)
|
* defined: N! / (k!(N-k)!)
|
||||||
* reduced: N! / (N-k)! == (N)k (fallingfactorial)
|
* reduced: N! / (N-k)! == (N)k (fallingfactorial)
|
||||||
* reduced: (N)k / k!
|
* reduced: (N)k / k!
|
||||||
@@ -498,10 +498,10 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* rising binomial coefficient
|
* rising binomial coefficient
|
||||||
*
|
*
|
||||||
* as one can notice in the analysis of binCoef(...) that
|
* as one can notice in the analysis of binCoef(...) that
|
||||||
* binCoef is the (N)k divided by k!. Similarly rising binCoef
|
* binCoef is the (N)k divided by k!. Similarly rising binCoef
|
||||||
* is merely N^(k) / k!
|
* is merely N^(k) / k!
|
||||||
*/
|
*/
|
||||||
public risingBinCoef(n: number, k: number): number {
|
public risingBinCoef(n: number, k: number): number {
|
||||||
return this.risingFactorial(n, k) / this.factorial(k);
|
return this.risingFactorial(n, k) / this.factorial(k);
|
||||||
@@ -542,7 +542,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given amount to the value, but never lets the value go over the specified maximum
|
* Adds the given amount to the value, but never lets the value go over the specified maximum
|
||||||
*
|
*
|
||||||
* @param value The value to add the amount to
|
* @param value The value to add the amount to
|
||||||
* @param amount The amount to add to the value
|
* @param amount The amount to add to the value
|
||||||
* @param max The maximum the value is allowed to be
|
* @param max The maximum the value is allowed to be
|
||||||
@@ -563,7 +563,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtracts the given amount from the value, but never lets the value go below the specified minimum
|
* Subtracts the given amount from the value, but never lets the value go below the specified minimum
|
||||||
*
|
*
|
||||||
* @param value The base value
|
* @param value The base value
|
||||||
* @param amount The amount to subtract from the base value
|
* @param amount The amount to subtract from the base value
|
||||||
* @param min The minimum the value is allowed to be
|
* @param min The minimum the value is allowed to be
|
||||||
@@ -584,7 +584,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
|
* Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
|
||||||
* <p>Values must be positive integers, and are passed through Math.abs</p>
|
* <p>Values must be positive integers, and are passed through Math.abs</p>
|
||||||
*
|
*
|
||||||
* @param value The value to add the amount to
|
* @param value The value to add the amount to
|
||||||
* @param amount The amount to add to the value
|
* @param amount The amount to add to the value
|
||||||
* @param max The maximum the value is allowed to be
|
* @param max The maximum the value is allowed to be
|
||||||
@@ -606,7 +606,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Randomly returns either a 1 or -1
|
* Randomly returns either a 1 or -1
|
||||||
*
|
*
|
||||||
* @return 1 or -1
|
* @return 1 or -1
|
||||||
*/
|
*/
|
||||||
public randomSign(): number {
|
public randomSign(): number {
|
||||||
@@ -615,9 +615,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the number given is odd.
|
* Returns true if the number given is odd.
|
||||||
*
|
*
|
||||||
* @param n The number to check
|
* @param n The number to check
|
||||||
*
|
*
|
||||||
* @return True if the given number is odd. False if the given number is even.
|
* @return True if the given number is odd. False if the given number is even.
|
||||||
*/
|
*/
|
||||||
public isOdd(n: number): bool {
|
public isOdd(n: number): bool {
|
||||||
@@ -635,9 +635,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the number given is even.
|
* Returns true if the number given is even.
|
||||||
*
|
*
|
||||||
* @param n The number to check
|
* @param n The number to check
|
||||||
*
|
*
|
||||||
* @return True if the given number is even. False if the given number is odd.
|
* @return True if the given number is even. False if the given number is odd.
|
||||||
*/
|
*/
|
||||||
public isEven(n: number): bool {
|
public isEven(n: number): bool {
|
||||||
@@ -656,9 +656,9 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Keeps an angle value between -180 and +180<br>
|
* Keeps an angle value between -180 and +180<br>
|
||||||
* Should be called whenever the angle is updated on the Sprite to stop it from going insane.
|
* Should be called whenever the angle is updated on the Sprite to stop it from going insane.
|
||||||
*
|
*
|
||||||
* @param angle The angle value to check
|
* @param angle The angle value to check
|
||||||
*
|
*
|
||||||
* @return The new angle value, returns the same as the input angle if it was within bounds
|
* @return The new angle value, returns the same as the input angle if it was within bounds
|
||||||
*/
|
*/
|
||||||
public wrapAngle(angle: number): number {
|
public wrapAngle(angle: number): number {
|
||||||
@@ -685,11 +685,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps an angle value between the given min and max values
|
* Keeps an angle value between the given min and max values
|
||||||
*
|
*
|
||||||
* @param angle The angle value to check. Must be between -180 and +180
|
* @param angle The angle value to check. Must be between -180 and +180
|
||||||
* @param min The minimum angle that is allowed (must be -180 or greater)
|
* @param min The minimum angle that is allowed (must be -180 or greater)
|
||||||
* @param max The maximum angle that is allowed (must be 180 or less)
|
* @param max The maximum angle that is allowed (must be 180 or less)
|
||||||
*
|
*
|
||||||
* @return The new angle value, returns the same as the input angle if it was within bounds
|
* @return The new angle value, returns the same as the input angle if it was within bounds
|
||||||
*/
|
*/
|
||||||
public angleLimit(angle: number, min: number, max: number): number {
|
public angleLimit(angle: number, min: number, max: number): number {
|
||||||
@@ -832,7 +832,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Generates a random number. Deterministic, meaning safe
|
* Generates a random number. Deterministic, meaning safe
|
||||||
* to use if you want to record replays in random environments.
|
* to use if you want to record replays in random environments.
|
||||||
*
|
*
|
||||||
* @return A <code>Number</code> between 0 and 1.
|
* @return A <code>Number</code> between 0 and 1.
|
||||||
*/
|
*/
|
||||||
public random(): number {
|
public random(): number {
|
||||||
@@ -841,9 +841,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random number based on the seed provided.
|
* Generates a random number based on the seed provided.
|
||||||
*
|
*
|
||||||
* @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
|
* @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
|
||||||
*
|
*
|
||||||
* @return A <code>Number</code> between 0 and 1.
|
* @return A <code>Number</code> between 0 and 1.
|
||||||
*/
|
*/
|
||||||
public srand(Seed: number): number {
|
public srand(Seed: number): number {
|
||||||
@@ -855,11 +855,11 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Fetch a random entry from the given array.
|
* Fetch a random entry from the given array.
|
||||||
* Will return null if random selection is missing, or array has no entries.
|
* Will return null if random selection is missing, or array has no entries.
|
||||||
*
|
*
|
||||||
* @param objects An array of objects.
|
* @param objects An array of objects.
|
||||||
* @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
* @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
||||||
* @param length Optional restriction on the number of values you want to randomly select from.
|
* @param length Optional restriction on the number of values you want to randomly select from.
|
||||||
*
|
*
|
||||||
* @return The random object that was selected.
|
* @return The random object that was selected.
|
||||||
*/
|
*/
|
||||||
public getRandom(objects, startIndex: number = 0, length: number = 0) {
|
public getRandom(objects, startIndex: number = 0, length: number = 0) {
|
||||||
@@ -885,9 +885,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
|
* Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
|
||||||
*
|
*
|
||||||
* @param Value Any number.
|
* @param Value Any number.
|
||||||
*
|
*
|
||||||
* @return The rounded value of that number.
|
* @return The rounded value of that number.
|
||||||
*/
|
*/
|
||||||
public floor(Value: number): number {
|
public floor(Value: number): number {
|
||||||
@@ -897,9 +897,9 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
|
* Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
|
||||||
*
|
*
|
||||||
* @param Value Any number.
|
* @param Value Any number.
|
||||||
*
|
*
|
||||||
* @return The rounded value of that number.
|
* @return The rounded value of that number.
|
||||||
*/
|
*/
|
||||||
public ceil(Value: number): number {
|
public ceil(Value: number): number {
|
||||||
@@ -977,25 +977,25 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the length of the given vector
|
* Finds the length of the given vector
|
||||||
*
|
*
|
||||||
* @param dx
|
* @param dx
|
||||||
* @param dy
|
* @param dy
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public vectorLength(dx:number, dy:number):number
|
public vectorLength(dx:number, dy:number):number
|
||||||
{
|
{
|
||||||
return Math.sqrt(dx * dx + dy * dy);
|
return Math.sqrt(dx * dx + dy * dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the dot product value of two vectors
|
* Finds the dot product value of two vectors
|
||||||
*
|
*
|
||||||
* @param ax Vector X
|
* @param ax Vector X
|
||||||
* @param ay Vector Y
|
* @param ay Vector Y
|
||||||
* @param bx Vector X
|
* @param bx Vector X
|
||||||
* @param by Vector Y
|
* @param by Vector Y
|
||||||
*
|
*
|
||||||
* @return Dot product
|
* @return Dot product
|
||||||
*/
|
*/
|
||||||
public dotProduct(ax:number, ay:number, bx:number, by:number):number
|
public dotProduct(ax:number, ay:number, bx:number, by:number):number
|
||||||
@@ -1003,6 +1003,70 @@ module Phaser {
|
|||||||
return ax * bx + ay * by;
|
return ax * bx + ay * by;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffles the data in the given array into a new order
|
||||||
|
* @param array The array to shuffle
|
||||||
|
* @return The array
|
||||||
|
*/
|
||||||
|
public shuffleArray(array) {
|
||||||
|
|
||||||
|
for (var i = array.length - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
|
var temp = array[i];
|
||||||
|
array[i] = array[j];
|
||||||
|
array[j] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the distance from this Point object to the given Point object.
|
||||||
|
* @method distanceFrom
|
||||||
|
* @param {Point} target - The destination Point object.
|
||||||
|
* @param {Boolean} round - Round the distance to the nearest integer (default false)
|
||||||
|
* @return {Number} The distance between this Point object and the destination Point object.
|
||||||
|
**/
|
||||||
|
public static distanceBetween(x1: number, y1: number, x2: number, y2: number): number {
|
||||||
|
|
||||||
|
var dx = x1 - x2;
|
||||||
|
var dy = y1 - y2;
|
||||||
|
|
||||||
|
return Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates the point around the x/y coordinates given to the desired angle 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} 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) {
|
||||||
|
|
||||||
|
if (asDegrees)
|
||||||
|
{
|
||||||
|
angle = angle * GameMath.DEG_TO_RAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get distance from origin to the point
|
||||||
|
if (distance === null)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
return point;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,219 @@
|
|||||||
|
/// <reference path="Game.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - GameObjectFactory
|
||||||
|
*
|
||||||
|
* A quick way to create new world objects and add existing objects to the current world.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class GameObjectFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameObjectFactory constructor
|
||||||
|
* @param game {Game} A reference to the current Game.
|
||||||
|
*/
|
||||||
|
constructor(game: Phaser.Game) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
this._world = this._game.world;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to Game
|
||||||
|
*/
|
||||||
|
private _game: Phaser.Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to World
|
||||||
|
*/
|
||||||
|
private _world: Phaser.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new camera with specific position and size.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new camera.
|
||||||
|
* @param y {number} Y position of the new camera.
|
||||||
|
* @param width {number} Width of the new camera.
|
||||||
|
* @param height {number} Height of the new camera.
|
||||||
|
* @returns {Camera} The newly created camera object.
|
||||||
|
*/
|
||||||
|
public camera(x: number, y: number, width: number, height: number): Camera {
|
||||||
|
return this._world.createCamera(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new GeomSprite with specific position.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new geom sprite.
|
||||||
|
* @param y {number} Y position of the new geom sprite.
|
||||||
|
* @returns {GeomSprite} The newly created geom sprite object.
|
||||||
|
*/
|
||||||
|
public geomSprite(x: number, y: number): GeomSprite {
|
||||||
|
return this._world.createGeomSprite(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Sprite with specific position and sprite sheet key.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new sprite.
|
||||||
|
* @param y {number} Y position of the new sprite.
|
||||||
|
* @param key {string} Optional, key for the sprite sheet you want it to use.
|
||||||
|
* @returns {Sprite} The newly created sprite object.
|
||||||
|
*/
|
||||||
|
public sprite(x: number, y: number, key?: string = ''): Sprite {
|
||||||
|
return this._world.createSprite(x, y, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new DynamicTexture with specific size.
|
||||||
|
*
|
||||||
|
* @param width {number} Width of the texture.
|
||||||
|
* @param height {number} Height of the texture.
|
||||||
|
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||||
|
*/
|
||||||
|
public dynamicTexture(width: number, height: number): DynamicTexture {
|
||||||
|
return this._world.createDynamicTexture(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new object container.
|
||||||
|
*
|
||||||
|
* @param maxSize {number} Optional, capacity of this group.
|
||||||
|
* @returns {Group} The newly created group.
|
||||||
|
*/
|
||||||
|
public group(maxSize?: number = 0): Group {
|
||||||
|
return this._world.createGroup(maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Particle.
|
||||||
|
*
|
||||||
|
* @return {Particle} The newly created particle object.
|
||||||
|
*/
|
||||||
|
public particle(): Particle {
|
||||||
|
return this._world.createParticle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Emitter.
|
||||||
|
*
|
||||||
|
* @param x {number} Optional, x position of the emitter.
|
||||||
|
* @param y {number} Optional, y position of the emitter.
|
||||||
|
* @param size {number} Optional, size of this emitter.
|
||||||
|
* @return {Emitter} The newly created emitter object.
|
||||||
|
*/
|
||||||
|
public emitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||||
|
return this._world.createEmitter(x, y, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ScrollZone object with image key, position and size.
|
||||||
|
*
|
||||||
|
* @param key {string} Key to a image you wish this object to use.
|
||||||
|
* @param x {number} X position of this object.
|
||||||
|
* @param y {number} Y position of this object.
|
||||||
|
* @param width number} Width of this object.
|
||||||
|
* @param height {number} Height of this object.
|
||||||
|
* @returns {ScrollZone} The newly created scroll zone object.
|
||||||
|
*/
|
||||||
|
public scrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
||||||
|
return this._world.createScrollZone(key, x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Tilemap.
|
||||||
|
*
|
||||||
|
* @param key {string} Key for tileset image.
|
||||||
|
* @param mapData {string} Data of this tilemap.
|
||||||
|
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||||
|
* @param [resizeWorld] {boolean} resize the world to make same as tilemap?
|
||||||
|
* @param [tileWidth] {number} width of each tile.
|
||||||
|
* @param [tileHeight] {number} height of each tile.
|
||||||
|
* @return {Tilemap} The newly created tilemap object.
|
||||||
|
*/
|
||||||
|
public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||||
|
return this._world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a tween object for a specific object.
|
||||||
|
*
|
||||||
|
* @param obj Object you wish the tween will affect.
|
||||||
|
* @return {Phaser.Tween} The newly created tween object.
|
||||||
|
*/
|
||||||
|
public tween(obj): Tween {
|
||||||
|
return this._game.tweens.create(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an existing Sprite to the current world.
|
||||||
|
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||||
|
*
|
||||||
|
* @param sprite The Sprite to add to the Game World
|
||||||
|
* @return {Phaser.Sprite} The Sprite object
|
||||||
|
*/
|
||||||
|
public existingSprite(sprite: Sprite): Sprite {
|
||||||
|
return this._world.group.add(sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an existing GeomSprite to the current world.
|
||||||
|
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||||
|
*
|
||||||
|
* @param sprite The GeomSprite to add to the Game World
|
||||||
|
* @return {Phaser.GeomSprite} The GeomSprite object
|
||||||
|
*/
|
||||||
|
public existingGeomSprite(sprite: GeomSprite): GeomSprite {
|
||||||
|
return this._world.group.add(sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an existing Emitter to the current world.
|
||||||
|
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||||
|
*
|
||||||
|
* @param emitter The Emitter to add to the Game World
|
||||||
|
* @return {Phaser.Emitter} The Emitter object
|
||||||
|
*/
|
||||||
|
public existingEmitter(emitter: Emitter): Emitter {
|
||||||
|
return this._world.group.add(emitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an existing ScrollZone to the current world.
|
||||||
|
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||||
|
*
|
||||||
|
* @param scrollZone The ScrollZone to add to the Game World
|
||||||
|
* @return {Phaser.ScrollZone} The ScrollZone object
|
||||||
|
*/
|
||||||
|
public existingScrollZone(scrollZone: ScrollZone): ScrollZone {
|
||||||
|
return this._world.group.add(scrollZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an existing Tilemap to the current world.
|
||||||
|
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||||
|
*
|
||||||
|
* @param tilemap The Tilemap to add to the Game World
|
||||||
|
* @return {Phaser.Tilemap} The Tilemap object
|
||||||
|
*/
|
||||||
|
public existingTilemap(tilemap: Tilemap): Tilemap {
|
||||||
|
return this._world.group.add(tilemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an existing Tween to the current world.
|
||||||
|
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||||
|
*
|
||||||
|
* @param tween The Tween to add to the Game World
|
||||||
|
* @return {Phaser.Tween} The Tween object
|
||||||
|
*/
|
||||||
|
public existingTween(tween: Tween): Tween {
|
||||||
|
return this._game.tweens.add(tween);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+177
-74
@@ -5,7 +5,6 @@
|
|||||||
* Phaser - Group
|
* Phaser - Group
|
||||||
*
|
*
|
||||||
* This class is used for organising, updating and sorting game objects.
|
* This class is used for organising, updating and sorting game objects.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
@@ -22,9 +21,31 @@ module Phaser {
|
|||||||
this._maxSize = MaxSize;
|
this._maxSize = MaxSize;
|
||||||
this._marker = 0;
|
this._marker = 0;
|
||||||
this._sortIndex = null;
|
this._sortIndex = null;
|
||||||
|
this.cameraBlacklist = [];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal tracker for the maximum capacity of the group.
|
||||||
|
* Default is 0, or no max capacity.
|
||||||
|
*/
|
||||||
|
private _maxSize: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal helper variable for recycling objects a la <code>Emitter</code>.
|
||||||
|
*/
|
||||||
|
private _marker: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for sort.
|
||||||
|
*/
|
||||||
|
private _sortIndex: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for sort.
|
||||||
|
*/
|
||||||
|
private _sortOrder: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use with <code>sort()</code> to sort in ascending order.
|
* Use with <code>sort()</code> to sort in ascending order.
|
||||||
*/
|
*/
|
||||||
@@ -48,25 +69,62 @@ module Phaser {
|
|||||||
public length: number;
|
public length: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal tracker for the maximum capacity of the group.
|
* You can set a globalCompositeOperation that will be applied before the render method is called on this Groups children.
|
||||||
* Default is 0, or no max capacity.
|
* 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.
|
||||||
*/
|
*/
|
||||||
private _maxSize: number;
|
public globalCompositeOperation: string = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper variable for recycling objects a la <code>Emitter</code>.
|
* 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.
|
||||||
*/
|
*/
|
||||||
private _marker: number;
|
public alpha: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for sort.
|
* An Array of Cameras to which this Group, or any of its children, won't render
|
||||||
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
private _sortIndex: string;
|
public cameraBlacklist: number[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for sort.
|
* If you do not wish this object to be visible to a specific camera, pass the camera here.
|
||||||
|
*
|
||||||
|
* @param camera {Camera} The specific camera.
|
||||||
|
*/
|
||||||
|
public hideFromCamera(camera: Camera) {
|
||||||
|
|
||||||
|
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
|
||||||
|
{
|
||||||
|
this.cameraBlacklist.push(camera.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make this object only visible to a specific camera.
|
||||||
|
*
|
||||||
|
* @param camera {Camera} The camera you wish it to be visible.
|
||||||
|
*/
|
||||||
|
public showToCamera(camera: Camera) {
|
||||||
|
|
||||||
|
if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
|
||||||
|
{
|
||||||
|
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This clears the camera black list, making the GameObject visible to all cameras.
|
||||||
*/
|
*/
|
||||||
private _sortOrder: number;
|
public clearCameraList() {
|
||||||
|
|
||||||
|
this.cameraBlacklist.length = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this function to handle any deleting or "shutdown" type operations you might need,
|
* Override this function to handle any deleting or "shutdown" type operations you might need,
|
||||||
@@ -99,7 +157,12 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Automatically goes through and calls update on everything you added.
|
* Automatically goes through and calls update on everything you added.
|
||||||
*/
|
*/
|
||||||
public update() {
|
public update(forceUpdate?: bool = false) {
|
||||||
|
|
||||||
|
if (this.ignoreGlobalUpdate && forceUpdate == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var basic: Basic;
|
var basic: Basic;
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
@@ -108,10 +171,10 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
basic = this.members[i++];
|
basic = this.members[i++];
|
||||||
|
|
||||||
if ((basic != null) && basic.exists && basic.active)
|
if ((basic != null) && basic.exists && basic.active && basic.ignoreGlobalUpdate == false)
|
||||||
{
|
{
|
||||||
basic.preUpdate();
|
basic.preUpdate();
|
||||||
basic.update();
|
basic.update(forceUpdate);
|
||||||
basic.postUpdate();
|
basic.postUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +183,29 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Automatically goes through and calls render on everything you added.
|
* Automatically goes through and calls render on everything you added.
|
||||||
*/
|
*/
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number, forceRender?: bool = false) {
|
||||||
|
|
||||||
|
if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.ignoreGlobalRender && forceRender == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.globalCompositeOperation)
|
||||||
|
{
|
||||||
|
this._game.stage.context.save();
|
||||||
|
this._game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.alpha > 0)
|
||||||
|
{
|
||||||
|
var prevAlpha: number = this._game.stage.context.globalAlpha;
|
||||||
|
this._game.stage.context.globalAlpha = this.alpha;
|
||||||
|
}
|
||||||
|
|
||||||
var basic: Basic;
|
var basic: Basic;
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
@@ -129,11 +214,21 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
basic = this.members[i++];
|
basic = this.members[i++];
|
||||||
|
|
||||||
if ((basic != null) && basic.exists && basic.visible)
|
if ((basic != null) && basic.exists && basic.visible && basic.ignoreGlobalRender == false)
|
||||||
{
|
{
|
||||||
basic.render(camera, cameraOffsetX, cameraOffsetY);
|
basic.render(camera, cameraOffsetX, cameraOffsetY, forceRender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.alpha > 0)
|
||||||
|
{
|
||||||
|
this._game.stage.context.globalAlpha = prevAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.globalCompositeOperation)
|
||||||
|
{
|
||||||
|
this._game.stage.context.restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,7 +274,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new <code>Basic</code> subclass (Basic, Basic, Enemy, etc) to the group.
|
* Adds a new <code>Basic</code> subclass (Basic, GameObject, Sprite, etc) to the group.
|
||||||
* Group will try to replace a null member of the array first.
|
* Group will try to replace a null member of the array first.
|
||||||
* Failing that, Group will add it to the end of the member array,
|
* Failing that, Group will add it to the end of the member array,
|
||||||
* assuming there is room for it, and doubling the size of the array if necessary.
|
* assuming there is room for it, and doubling the size of the array if necessary.
|
||||||
@@ -187,11 +282,10 @@ module Phaser {
|
|||||||
* <p>WARNING: If the group has a maxSize that has already been met,
|
* <p>WARNING: If the group has a maxSize that has already been met,
|
||||||
* the object will NOT be added to the group!</p>
|
* the object will NOT be added to the group!</p>
|
||||||
*
|
*
|
||||||
* @param Object The object you want to add to the group.
|
* @param {Basic} Object The object you want to add to the group.
|
||||||
*
|
* @return {Basic} The same <code>Basic</code> object that was passed in.
|
||||||
* @return The same <code>Basic</code> object that was passed in.
|
|
||||||
*/
|
*/
|
||||||
public add(Object: Basic) {
|
public add(Object: Basic): any {
|
||||||
|
|
||||||
//Don't bother adding an object twice.
|
//Don't bother adding an object twice.
|
||||||
if (this.members.indexOf(Object) >= 0)
|
if (this.members.indexOf(Object) >= 0)
|
||||||
@@ -252,26 +346,26 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
|
* Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
|
||||||
*
|
*
|
||||||
* <p>If you specified a maximum size for this group (like in Emitter),
|
* <p>If you specified a maximum size for this group (like in Emitter),
|
||||||
* then recycle will employ what we're calling "rotating" recycling.
|
* then recycle will employ what we're calling "rotating" recycling.
|
||||||
* Recycle() will first check to see if the group is at capacity yet.
|
* Recycle() will first check to see if the group is at capacity yet.
|
||||||
* If group is not yet at capacity, recycle() returns a new object.
|
* If group is not yet at capacity, recycle() returns a new object.
|
||||||
* If the group IS at capacity, then recycle() just returns the next object in line.</p>
|
* If the group IS at capacity, then recycle() just returns the next object in line.</p>
|
||||||
*
|
*
|
||||||
* <p>If you did NOT specify a maximum size for this group,
|
* <p>If you did NOT specify a maximum size for this group,
|
||||||
* then recycle() will employ what we're calling "grow-style" recycling.
|
* then recycle() will employ what we're calling "grow-style" recycling.
|
||||||
* Recycle() will return either the first object with exists == false,
|
* Recycle() will return either the first object with exists == false,
|
||||||
* or, finding none, add a new object to the array,
|
* or, finding none, add a new object to the array,
|
||||||
* doubling the size of the array if necessary.</p>
|
* doubling the size of the array if necessary.</p>
|
||||||
*
|
*
|
||||||
* <p>WARNING: If this function needs to create a new object,
|
* <p>WARNING: If this function needs to create a new object,
|
||||||
* and no object class was provided, it will return null
|
* and no object class was provided, it will return null
|
||||||
* instead of a valid object!</p>
|
* instead of a valid object!</p>
|
||||||
*
|
*
|
||||||
* @param ObjectClass The class type you want to recycle (e.g. Basic, EvilRobot, etc). Do NOT "new" the class in the parameter!
|
* @param {class} ObjectClass The class type you want to recycle (e.g. Basic, EvilRobot, etc). Do NOT "new" the class in the parameter!
|
||||||
*
|
*
|
||||||
* @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).
|
* @return {any} A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).
|
||||||
*/
|
*/
|
||||||
public recycle(ObjectClass = null) {
|
public recycle(ObjectClass = null) {
|
||||||
|
|
||||||
@@ -320,11 +414,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an object from the group.
|
* Removes an object from the group.
|
||||||
*
|
*
|
||||||
* @param object The <code>Basic</code> you want to remove.
|
* @param {Basic} object The <code>Basic</code> you want to remove.
|
||||||
* @param splice Whether the object should be cut from the array entirely or not.
|
* @param {boolean} splice Whether the object should be cut from the array entirely or not.
|
||||||
*
|
*
|
||||||
* @return The removed object.
|
* @return {Basic} The removed object.
|
||||||
*/
|
*/
|
||||||
public remove(object: Basic, splice: bool = false): Basic {
|
public remove(object: Basic, splice: bool = false): Basic {
|
||||||
|
|
||||||
@@ -351,11 +445,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces an existing <code>Basic</code> with a new one.
|
* Replaces an existing <code>Basic</code> with a new one.
|
||||||
*
|
*
|
||||||
* @param oldObject The object you want to replace.
|
* @param {Basic} oldObject The object you want to replace.
|
||||||
* @param newObject The new object you want to use instead.
|
* @param {Basic} newObject The new object you want to use instead.
|
||||||
*
|
*
|
||||||
* @return The new object.
|
* @return {Basic} The new object.
|
||||||
*/
|
*/
|
||||||
public replace(oldObject: Basic, newObject: Basic): Basic {
|
public replace(oldObject: Basic, newObject: Basic): Basic {
|
||||||
|
|
||||||
@@ -378,9 +472,9 @@ module Phaser {
|
|||||||
* <code>myGroup.sort("y",Group.ASCENDING)</code> at the bottom of your
|
* <code>myGroup.sort("y",Group.ASCENDING)</code> at the bottom of your
|
||||||
* <code>State.update()</code> override. To sort all existing objects after
|
* <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>.
|
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
|
||||||
*
|
*
|
||||||
* @param 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 "y".
|
||||||
* @param 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>.
|
* @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 = "y", order: number = Group.ASCENDING) {
|
public sort(index: string = "y", order: number = Group.ASCENDING) {
|
||||||
|
|
||||||
@@ -392,10 +486,10 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Go through and set the specified variable to the specified value on all members of the group.
|
* Go through and set the specified variable to the specified value on all members of the group.
|
||||||
*
|
*
|
||||||
* @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
|
* @param {string} VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
|
||||||
* @param Value The value you want to assign to that variable.
|
* @param {Object} Value The value you want to assign to that variable.
|
||||||
* @param Recurse Default value is true, meaning if <code>setAll()</code> encounters a member that is a group, it will call <code>setAll()</code> on that group rather than modifying its variable.
|
* @param {boolean} Recurse Default value is true, meaning if <code>setAll()</code> encounters a member that is a group, it will call <code>setAll()</code> on that group rather than modifying its variable.
|
||||||
*/
|
*/
|
||||||
public setAll(VariableName: string, Value: Object, Recurse: bool = true) {
|
public setAll(VariableName: string, Value: Object, Recurse: bool = true) {
|
||||||
|
|
||||||
@@ -423,9 +517,9 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Go through and call the specified function on all members of the group.
|
* Go through and call the specified function on all members of the group.
|
||||||
* Currently only works on functions that have no required parameters.
|
* Currently only works on functions that have no required parameters.
|
||||||
*
|
*
|
||||||
* @param FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
|
* @param {string} FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
|
||||||
* @param Recurse Default value is true, meaning if <code>callAll()</code> encounters a member that is a group, it will call <code>callAll()</code> on that group rather than calling the group's function.
|
* @param {boolean} Recurse Default value is true, meaning if <code>callAll()</code> encounters a member that is a group, it will call <code>callAll()</code> on that group rather than calling the group's function.
|
||||||
*/
|
*/
|
||||||
public callAll(FunctionName: string, Recurse: bool = true) {
|
public callAll(FunctionName: string, Recurse: bool = true) {
|
||||||
|
|
||||||
@@ -450,6 +544,10 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {function} callback
|
||||||
|
* @param {boolean} recursive
|
||||||
|
*/
|
||||||
public forEach(callback, recursive: bool = false) {
|
public forEach(callback, recursive: bool = false) {
|
||||||
|
|
||||||
var basic;
|
var basic;
|
||||||
@@ -474,6 +572,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any} context
|
||||||
|
* @param {function} callback
|
||||||
|
* @param {boolean} recursive
|
||||||
|
*/
|
||||||
public forEachAlive(context, callback, recursive: bool = false) {
|
public forEachAlive(context, callback, recursive: bool = false) {
|
||||||
|
|
||||||
var basic;
|
var basic;
|
||||||
@@ -501,10 +604,10 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Call this function to retrieve the first object with exists == false in the group.
|
* Call this function to retrieve the first object with exists == false in the group.
|
||||||
* This is handy for recycling in general, e.g. respawning enemies.
|
* This is handy for recycling in general, e.g. respawning enemies.
|
||||||
*
|
*
|
||||||
* @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
|
* @param {any} [ObjectClass] An optional parameter that lets you narrow the results to instances of this particular class.
|
||||||
*
|
*
|
||||||
* @return A <code>Basic</code> currently flagged as not existing.
|
* @return {any} A <code>Basic</code> currently flagged as not existing.
|
||||||
*/
|
*/
|
||||||
public getFirstAvailable(ObjectClass = null) {
|
public getFirstAvailable(ObjectClass = null) {
|
||||||
|
|
||||||
@@ -528,8 +631,8 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Call this function to retrieve the first index set to 'null'.
|
* Call this function to retrieve the first index set to 'null'.
|
||||||
* Returns -1 if no index stores a null object.
|
* Returns -1 if no index stores a null object.
|
||||||
*
|
*
|
||||||
* @return An <code>int</code> indicating the first null slot in the group.
|
* @return {number} An <code>int</code> indicating the first null slot in the group.
|
||||||
*/
|
*/
|
||||||
public getFirstNull(): number {
|
public getFirstNull(): number {
|
||||||
|
|
||||||
@@ -556,8 +659,8 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Call this function to retrieve the first object with exists == true in the group.
|
* Call this function to retrieve the first object with exists == true in the group.
|
||||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
||||||
*
|
*
|
||||||
* @return A <code>Basic</code> currently flagged as existing.
|
* @return {Basic} A <code>Basic</code> currently flagged as existing.
|
||||||
*/
|
*/
|
||||||
public getFirstExtant(): Basic {
|
public getFirstExtant(): Basic {
|
||||||
|
|
||||||
@@ -581,8 +684,8 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Call this function to retrieve the first object with dead == false in the group.
|
* Call this function to retrieve the first object with dead == false in the group.
|
||||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
||||||
*
|
*
|
||||||
* @return A <code>Basic</code> currently flagged as not dead.
|
* @return {Basic} A <code>Basic</code> currently flagged as not dead.
|
||||||
*/
|
*/
|
||||||
public getFirstAlive(): Basic {
|
public getFirstAlive(): Basic {
|
||||||
|
|
||||||
@@ -606,8 +709,8 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Call this function to retrieve the first object with dead == true in the group.
|
* Call this function to retrieve the first object with dead == true in the group.
|
||||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
||||||
*
|
*
|
||||||
* @return A <code>Basic</code> currently flagged as dead.
|
* @return {Basic} A <code>Basic</code> currently flagged as dead.
|
||||||
*/
|
*/
|
||||||
public getFirstDead(): Basic {
|
public getFirstDead(): Basic {
|
||||||
|
|
||||||
@@ -630,8 +733,8 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this function to find out how many members of the group are not dead.
|
* Call this function to find out how many members of the group are not dead.
|
||||||
*
|
*
|
||||||
* @return The number of <code>Basic</code>s flagged as not dead. Returns -1 if group is empty.
|
* @return {number} The number of <code>Basic</code>s flagged as not dead. Returns -1 if group is empty.
|
||||||
*/
|
*/
|
||||||
public countLiving(): number {
|
public countLiving(): number {
|
||||||
|
|
||||||
@@ -663,8 +766,8 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this function to find out how many members of the group are dead.
|
* Call this function to find out how many members of the group are dead.
|
||||||
*
|
*
|
||||||
* @return The number of <code>Basic</code>s flagged as dead. Returns -1 if group is empty.
|
* @return {number} The number of <code>Basic</code>s flagged as dead. Returns -1 if group is empty.
|
||||||
*/
|
*/
|
||||||
public countDead(): number {
|
public countDead(): number {
|
||||||
|
|
||||||
@@ -696,11 +799,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a member at random from the group.
|
* Returns a member at random from the group.
|
||||||
*
|
*
|
||||||
* @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
* @param {number} StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
||||||
* @param Length Optional restriction on the number of values you want to randomly select from.
|
* @param {number} Length Optional restriction on the number of values you want to randomly select from.
|
||||||
*
|
*
|
||||||
* @return A <code>Basic</code> from the members list.
|
* @return {Basic} A <code>Basic</code> from the members list.
|
||||||
*/
|
*/
|
||||||
public getRandom(StartIndex: number = 0, Length: number = 0): Basic {
|
public getRandom(StartIndex: number = 0, Length: number = 0): Basic {
|
||||||
|
|
||||||
@@ -743,11 +846,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for the sort process.
|
* Helper function for the sort process.
|
||||||
*
|
*
|
||||||
* @param Obj1 The first object being sorted.
|
* @param {Basic} Obj1 The first object being sorted.
|
||||||
* @param Obj2 The second object being sorted.
|
* @param {Basic} Obj2 The second object being sorted.
|
||||||
*
|
*
|
||||||
* @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
||||||
*/
|
*/
|
||||||
public sortHandler(Obj1: Basic, Obj2: Basic): number {
|
public sortHandler(Obj1: Basic, Obj2: Basic): number {
|
||||||
|
|
||||||
|
|||||||
+237
-34
@@ -11,6 +11,12 @@ module Phaser {
|
|||||||
|
|
||||||
export class Loader {
|
export class Loader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loader constructor
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param callback {function} This will be called when assets completely loaded.
|
||||||
|
*/
|
||||||
constructor(game: Game, callback) {
|
constructor(game: Game, callback) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -22,19 +28,70 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array stors assets keys. So you can get that asset by its unique key.
|
||||||
|
*/
|
||||||
private _keys: string[];
|
private _keys: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains all the assets file infos.
|
||||||
|
*/
|
||||||
private _fileList;
|
private _fileList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game initialial assets loading callback.
|
||||||
|
*/
|
||||||
private _gameCreateComplete;
|
private _gameCreateComplete;
|
||||||
private _onComplete;
|
private _onComplete;
|
||||||
private _onFileLoad;
|
private _onFileLoad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates assets loading progress. (from 0 to 100)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _progressChunk: number;
|
private _progressChunk: number;
|
||||||
|
|
||||||
private _xhr: XMLHttpRequest;
|
private _xhr: XMLHttpRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Length of assets queue.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _queueSize: number;
|
private _queueSize: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if game is completely loaded.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public hasLoaded: bool;
|
public hasLoaded: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loading progress (from 0 to 1)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public progress: number;
|
public progress: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The crossOrigin value applied to loaded images
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
public crossOrigin: string = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TextureAtlas data format constants
|
||||||
|
*/
|
||||||
|
public static TEXTURE_ATLAS_JSON_ARRAY: number = 0;
|
||||||
|
public static TEXTURE_ATLAS_JSON_HASH: number = 1;
|
||||||
|
public static TEXTURE_ATLAS_XML_STARLING: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset loader, this will remove all loaded assets.
|
||||||
|
*/
|
||||||
public reset() {
|
public reset() {
|
||||||
this._queueSize = 0;
|
this._queueSize = 0;
|
||||||
}
|
}
|
||||||
@@ -45,6 +102,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new image asset loading request with key and url.
|
||||||
|
* @param key {string} Unique asset key of this image file.
|
||||||
|
* @param url {string} URL of image file.
|
||||||
|
*/
|
||||||
public addImageFile(key: string, url: string) {
|
public addImageFile(key: string, url: string) {
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
if (this.checkKeyExists(key) === false)
|
||||||
@@ -56,6 +118,14 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new sprite sheet loading request.
|
||||||
|
* @param key {string} Unique asset key of the sheet file.
|
||||||
|
* @param url {string} URL of sheet file.
|
||||||
|
* @param frameWidth {number} Width of each single frame.
|
||||||
|
* @param frameHeight {number} Height of each single frame.
|
||||||
|
* @param frameMax {number} How many frames in this sprite sheet.
|
||||||
|
*/
|
||||||
public addSpriteSheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
|
public addSpriteSheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
if (this.checkKeyExists(key) === false)
|
||||||
@@ -67,40 +137,78 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTextureAtlas(key: string, url: string, jsonURL?: string = null, jsonData? = null) {
|
/**
|
||||||
|
* Add a new texture atlas loading request.
|
||||||
|
* @param key {string} Unique asset key of the texture atlas file.
|
||||||
|
* @param textureURL {string} The url of the texture atlas image file.
|
||||||
|
* @param [atlasURL] {string} The url of the texture atlas data file (json/xml)
|
||||||
|
* @param [atlasData] {object} A JSON or XML data object.
|
||||||
|
* @param [format] {number} A value describing the format of the data.
|
||||||
|
*/
|
||||||
|
public addTextureAtlas(key: string, textureURL: string, atlasURL?: string = null, atlasData? = null, format?:number = Loader.TEXTURE_ATLAS_JSON_ARRAY) {
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
if (this.checkKeyExists(key) === false)
|
||||||
{
|
{
|
||||||
if (jsonURL !== null)
|
if (atlasURL !== null)
|
||||||
{
|
{
|
||||||
// A URL to a json file has been given
|
// A URL to a json/xml file has been given
|
||||||
this._queueSize++;
|
this._queueSize++;
|
||||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: jsonURL, jsonData: null, error: false, loaded: false };
|
this._fileList[key] = { type: 'textureatlas', key: key, url: textureURL, atlasURL: atlasURL, data: null, format: format, error: false, loaded: false };
|
||||||
this._keys.push(key);
|
this._keys.push(key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// A json string or object has been given
|
if (format == Loader.TEXTURE_ATLAS_JSON_ARRAY)
|
||||||
if (typeof jsonData === 'string')
|
|
||||||
{
|
{
|
||||||
var data = JSON.parse(jsonData);
|
// A json string or object has been given
|
||||||
// Malformed?
|
if (typeof atlasData === 'string')
|
||||||
if (data['frames'])
|
|
||||||
{
|
{
|
||||||
this._queueSize++;
|
atlasData = JSON.parse(atlasData);
|
||||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: data['frames'], error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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._keys.push(key);
|
||||||
}
|
}
|
||||||
else
|
else if (format == Loader.TEXTURE_ATLAS_XML_STARLING)
|
||||||
{
|
{
|
||||||
// Malformed?
|
// An xml string or object has been given
|
||||||
if (jsonData['frames'])
|
if (typeof atlasData === 'string')
|
||||||
{
|
{
|
||||||
this._queueSize++;
|
var xml;
|
||||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: jsonData['frames'], error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
try
|
||||||
|
{
|
||||||
|
if (window['DOMParser'])
|
||||||
|
{
|
||||||
|
var domparser = new DOMParser();
|
||||||
|
xml = domparser.parseFromString(atlasData, "text/xml");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml = new ActiveXObject("Microsoft.XMLDOM");
|
||||||
|
xml.async = 'false';
|
||||||
|
xml.loadXML(atlasData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
xml = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
|
||||||
|
{
|
||||||
|
throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
atlasData = xml;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._queueSize++;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -109,6 +217,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new audio file loading request.
|
||||||
|
* @param key {string} Unique asset key of the audio file.
|
||||||
|
* @param url {string} URL of audio file.
|
||||||
|
*/
|
||||||
public addAudioFile(key: string, url: string) {
|
public addAudioFile(key: string, url: string) {
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
if (this.checkKeyExists(key) === false)
|
||||||
@@ -120,6 +233,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new text file loading request.
|
||||||
|
* @param key {string} Unique asset key of the text file.
|
||||||
|
* @param url {string} URL of text file.
|
||||||
|
*/
|
||||||
public addTextFile(key: string, url: string) {
|
public addTextFile(key: string, url: string) {
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
if (this.checkKeyExists(key) === false)
|
||||||
@@ -131,18 +249,30 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove loading request of a file.
|
||||||
|
* @param key {string} Key of the file you want to remove.
|
||||||
|
*/
|
||||||
public removeFile(key: string) {
|
public removeFile(key: string) {
|
||||||
|
|
||||||
delete this._fileList[key];
|
delete this._fileList[key];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all file loading requests.
|
||||||
|
*/
|
||||||
public removeAll() {
|
public removeAll() {
|
||||||
|
|
||||||
this._fileList = {};
|
this._fileList = {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load assets.
|
||||||
|
* @param onFileLoadCallback {function} Called when each file loaded successfully.
|
||||||
|
* @param onCompleteCallback {function} Called when all assets completely loaded.
|
||||||
|
*/
|
||||||
public load(onFileLoadCallback = null, onCompleteCallback = null) {
|
public load(onFileLoadCallback = null, onCompleteCallback = null) {
|
||||||
|
|
||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
@@ -176,6 +306,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load files. Private method ONLY used by loader.
|
||||||
|
*/
|
||||||
private loadFile() {
|
private loadFile() {
|
||||||
|
|
||||||
var file = this._fileList[this._keys.pop()];
|
var file = this._fileList[this._keys.pop()];
|
||||||
@@ -191,6 +324,7 @@ module Phaser {
|
|||||||
file.data.name = file.key;
|
file.data.name = file.key;
|
||||||
file.data.onload = () => this.fileComplete(file.key);
|
file.data.onload = () => this.fileComplete(file.key);
|
||||||
file.data.onerror = () => this.fileError(file.key);
|
file.data.onerror = () => this.fileError(file.key);
|
||||||
|
file.data.crossOrigin = this.crossOrigin;
|
||||||
file.data.src = file.url;
|
file.data.src = file.url;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -213,6 +347,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error occured when load a file.
|
||||||
|
* @param key {string} Key of the error loading file.
|
||||||
|
*/
|
||||||
private fileError(key: string) {
|
private fileError(key: string) {
|
||||||
|
|
||||||
this._fileList[key].loaded = true;
|
this._fileList[key].loaded = true;
|
||||||
@@ -222,6 +360,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a file is successfully loaded.
|
||||||
|
* @param key {string} Key of the successfully loaded file.
|
||||||
|
*/
|
||||||
private fileComplete(key: string) {
|
private fileComplete(key: string) {
|
||||||
|
|
||||||
this._fileList[key].loaded = true;
|
this._fileList[key].loaded = true;
|
||||||
@@ -240,18 +382,27 @@ module Phaser {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'textureatlas':
|
case 'textureatlas':
|
||||||
if (file.jsonURL == null)
|
if (file.atlasURL == null)
|
||||||
{
|
{
|
||||||
this._game.cache.addTextureAtlas(file.key, file.url, file.data, file.jsonData);
|
this._game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Load the JSON before carrying on with the next file
|
// Load the JSON or XML before carrying on with the next file
|
||||||
loadNext = false;
|
loadNext = false;
|
||||||
this._xhr.open("GET", file.jsonURL, true);
|
this._xhr.open("GET", file.atlasURL, true);
|
||||||
this._xhr.responseType = "text";
|
this._xhr.responseType = "text";
|
||||||
this._xhr.onload = () => this.jsonLoadComplete(file.key);
|
|
||||||
this._xhr.onerror = () => this.jsonLoadError(file.key);
|
if (file.format == Loader.TEXTURE_ATLAS_JSON_ARRAY)
|
||||||
|
{
|
||||||
|
this._xhr.onload = () => this.jsonLoadComplete(file.key);
|
||||||
|
}
|
||||||
|
else if (file.format == Loader.TEXTURE_ATLAS_XML_STARLING)
|
||||||
|
{
|
||||||
|
this._xhr.onload = () => this.xmlLoadComplete(file.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._xhr.onerror = () => this.dataLoadError(file.key);
|
||||||
this._xhr.send();
|
this._xhr.send();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -274,36 +425,83 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Successfully loaded a JSON file.
|
||||||
|
* @param key {string} Key of the loaded JSON file.
|
||||||
|
*/
|
||||||
private jsonLoadComplete(key: string) {
|
private jsonLoadComplete(key: string) {
|
||||||
|
|
||||||
var data = JSON.parse(this._xhr.response);
|
var data = JSON.parse(this._xhr.response);
|
||||||
|
var file = this._fileList[key];
|
||||||
|
|
||||||
// Malformed?
|
this._game.cache.addTextureAtlas(file.key, file.url, file.data, data['frames'], file.format);
|
||||||
if (data['frames'])
|
|
||||||
{
|
|
||||||
var file = this._fileList[key];
|
|
||||||
this._game.cache.addTextureAtlas(file.key, file.url, file.data, data['frames']);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nextFile(key, true);
|
this.nextFile(key, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private jsonLoadError(key: string) {
|
/**
|
||||||
|
* Error occured when load a JSON.
|
||||||
|
* @param key {string} Key of the error loading JSON file.
|
||||||
|
*/
|
||||||
|
private dataLoadError(key: string) {
|
||||||
|
|
||||||
var file = this._fileList[key];
|
var file = this._fileList[key];
|
||||||
|
|
||||||
file.error = true;
|
file.error = true;
|
||||||
|
|
||||||
this.nextFile(key, true);
|
this.nextFile(key, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private xmlLoadComplete(key: string) {
|
||||||
|
|
||||||
|
var atlasData = this._xhr.response;
|
||||||
|
var xml;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (window['DOMParser'])
|
||||||
|
{
|
||||||
|
var domparser = new DOMParser();
|
||||||
|
xml = domparser.parseFromString(atlasData, "text/xml");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml = new ActiveXObject("Microsoft.XMLDOM");
|
||||||
|
xml.async = 'false';
|
||||||
|
xml.loadXML(atlasData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
xml = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
|
||||||
|
{
|
||||||
|
throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
|
||||||
|
}
|
||||||
|
|
||||||
|
var file = this._fileList[key];
|
||||||
|
this._game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
|
||||||
|
|
||||||
|
this.nextFile(key, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle loading next file.
|
||||||
|
* @param previousKey {string} Key of previous loaded asset.
|
||||||
|
* @param success {boolean} Whether the previous asset loaded successfully or not.
|
||||||
|
*/
|
||||||
private nextFile(previousKey: string, success: bool) {
|
private nextFile(previousKey: string, success: bool) {
|
||||||
|
|
||||||
this.progress = Math.round(this.progress + this._progressChunk);
|
this.progress = Math.round(this.progress + this._progressChunk);
|
||||||
|
|
||||||
if (this.progress > 1)
|
if (this.progress > 100)
|
||||||
{
|
{
|
||||||
this.progress = 1;
|
this.progress = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._onFileLoad)
|
if (this._onFileLoad)
|
||||||
@@ -329,6 +527,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether asset exists with a specific key.
|
||||||
|
* @param key {string} Key of the asset you want to check.
|
||||||
|
* @return {boolean} Return true if exists, otherwise return false.
|
||||||
|
*/
|
||||||
private checkKeyExists(key: string): bool {
|
private checkKeyExists(key: string): bool {
|
||||||
|
|
||||||
if (this._fileList[key])
|
if (this._fileList[key])
|
||||||
|
|||||||
+104
-104
@@ -21,13 +21,13 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
|
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
|
||||||
*
|
*
|
||||||
* @param Velocity Any component of velocity (e.g. 20).
|
* @param {number} Velocity Any component of velocity (e.g. 20).
|
||||||
* @param Acceleration Rate at which the velocity is changing.
|
* @param {number} Acceleration Rate at which the velocity is changing.
|
||||||
* @param Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
* @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
||||||
* @param Max An absolute value cap for the velocity.
|
* @param {number} Max An absolute value cap for the velocity.
|
||||||
*
|
*
|
||||||
* @return The altered Velocity value.
|
* @return {number} The altered Velocity value.
|
||||||
*/
|
*/
|
||||||
public computeVelocity(Velocity: number, Acceleration: number = 0, Drag: number = 0, Max: number = 10000): number {
|
public computeVelocity(Velocity: number, Acceleration: number = 0, Drag: number = 0, Max: number = 10000): number {
|
||||||
|
|
||||||
@@ -71,11 +71,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the angle and speed calculate the velocity and return it as a Point
|
* Given the angle and speed calculate the velocity and return it as a Point
|
||||||
*
|
*
|
||||||
* @param angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
* @param {number} angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
||||||
* @param speed The speed it will move, in pixels per second sq
|
* @param {number} speed The speed it will move, in pixels per second sq
|
||||||
*
|
*
|
||||||
* @return A Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
* @return {Point} A Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||||
*/
|
*/
|
||||||
public velocityFromAngle(angle: number, speed: number): Point {
|
public velocityFromAngle(angle: number, speed: number): Point {
|
||||||
|
|
||||||
@@ -97,24 +97,24 @@ module Phaser {
|
|||||||
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
||||||
* If you need the object to accelerate, see accelerateTowardsObject() instead
|
* If you need the object to accelerate, see accelerateTowardsObject() instead
|
||||||
* Note: Doesn't take into account acceleration, maxVelocity or drag (if you set drag or acceleration too high this object may not move at all)
|
* Note: Doesn't take into account acceleration, maxVelocity or drag (if you set drag or acceleration too high this object may not move at all)
|
||||||
*
|
*
|
||||||
* @param source The Sprite on which the velocity will be set
|
* @param {GameObject} source The Sprite on which the velocity will be set
|
||||||
* @param dest The Sprite where the source object will move to
|
* @param {GameObject} dest The Sprite where the source object will move to
|
||||||
* @param speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
* @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
||||||
* @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
||||||
*/
|
*/
|
||||||
public moveTowardsObject(source:GameObject, dest:GameObject, speed:number= 60, maxTime:number = 0)
|
public moveTowardsObject(source:GameObject, dest:GameObject, speed:number= 60, maxTime:number = 0)
|
||||||
{
|
{
|
||||||
var a:number = this.angleBetween(source, dest);
|
var a:number = this.angleBetween(source, dest);
|
||||||
|
|
||||||
if (maxTime > 0)
|
if (maxTime > 0)
|
||||||
{
|
{
|
||||||
var d:number = this.distanceBetween(source, dest);
|
var d:number = this.distanceBetween(source, dest);
|
||||||
|
|
||||||
// We know how many pixels we need to move, but how fast?
|
// We know how many pixels we need to move, but how fast?
|
||||||
speed = d / (maxTime / 1000);
|
speed = d / (maxTime / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
source.velocity.x = Math.cos(a) * speed;
|
source.velocity.x = Math.cos(a) * speed;
|
||||||
source.velocity.y = Math.sin(a) * speed;
|
source.velocity.y = Math.sin(a) * speed;
|
||||||
|
|
||||||
@@ -124,23 +124,23 @@ module Phaser {
|
|||||||
* Sets the x/y acceleration on the source Sprite so it will move towards the destination Sprite at the speed given (in pixels per second)<br>
|
* Sets the x/y acceleration on the source Sprite so it will move towards the destination Sprite at the speed given (in pixels per second)<br>
|
||||||
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
|
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
|
||||||
* If you don't need acceleration look at moveTowardsObject() instead.
|
* If you don't need acceleration look at moveTowardsObject() instead.
|
||||||
*
|
*
|
||||||
* @param source The Sprite on which the acceleration will be set
|
* @param {GameObject} source The Sprite on which the acceleration will be set
|
||||||
* @param dest The Sprite where the source object will move towards
|
* @param {GameObject} dest The Sprite where the source object will move towards
|
||||||
* @param speed The speed it will accelerate in pixels per second
|
* @param {number} speed The speed it will accelerate in pixels per second
|
||||||
* @param xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
* @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
||||||
* @param ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
||||||
*/
|
*/
|
||||||
public accelerateTowardsObject(source:GameObject, dest:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number)
|
public accelerateTowardsObject(source:GameObject, dest:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number)
|
||||||
{
|
{
|
||||||
var a:number = this.angleBetween(source, dest);
|
var a:number = this.angleBetween(source, dest);
|
||||||
|
|
||||||
source.velocity.x = 0;
|
source.velocity.x = 0;
|
||||||
source.velocity.y = 0;
|
source.velocity.y = 0;
|
||||||
|
|
||||||
source.acceleration.x = Math.cos(a) * speed;
|
source.acceleration.x = Math.cos(a) * speed;
|
||||||
source.acceleration.y = Math.sin(a) * speed;
|
source.acceleration.y = Math.sin(a) * speed;
|
||||||
|
|
||||||
source.maxVelocity.x = xSpeedMax;
|
source.maxVelocity.x = xSpeedMax;
|
||||||
source.maxVelocity.y = ySpeedMax;
|
source.maxVelocity.y = ySpeedMax;
|
||||||
|
|
||||||
@@ -151,23 +151,23 @@ module Phaser {
|
|||||||
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
|
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
|
||||||
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
|
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
|
||||||
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
||||||
*
|
*
|
||||||
* @param source The Sprite to move
|
* @param {GameObject} source The Sprite to move
|
||||||
* @param speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
* @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
||||||
* @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
||||||
*/
|
*/
|
||||||
public moveTowardsMouse(source:GameObject, speed:number = 60, maxTime:number = 0)
|
public moveTowardsMouse(source:GameObject, speed:number = 60, maxTime:number = 0)
|
||||||
{
|
{
|
||||||
var a:number = this.angleBetweenMouse(source);
|
var a:number = this.angleBetweenMouse(source);
|
||||||
|
|
||||||
if (maxTime > 0)
|
if (maxTime > 0)
|
||||||
{
|
{
|
||||||
var d:number = this.distanceToMouse(source);
|
var d:number = this.distanceToMouse(source);
|
||||||
|
|
||||||
// We know how many pixels we need to move, but how fast?
|
// We know how many pixels we need to move, but how fast?
|
||||||
speed = d / (maxTime / 1000);
|
speed = d / (maxTime / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
source.velocity.x = Math.cos(a) * speed;
|
source.velocity.x = Math.cos(a) * speed;
|
||||||
source.velocity.y = Math.sin(a) * speed;
|
source.velocity.y = Math.sin(a) * speed;
|
||||||
|
|
||||||
@@ -177,22 +177,22 @@ module Phaser {
|
|||||||
* Sets the x/y acceleration on the source Sprite so it will move towards the mouse coordinates at the speed given (in pixels per second)<br>
|
* Sets the x/y acceleration on the source Sprite so it will move towards the mouse coordinates at the speed given (in pixels per second)<br>
|
||||||
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
|
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
|
||||||
* If you don't need acceleration look at moveTowardsMouse() instead.
|
* If you don't need acceleration look at moveTowardsMouse() instead.
|
||||||
*
|
*
|
||||||
* @param source The Sprite on which the acceleration will be set
|
* @param {GameObject} source The Sprite on which the acceleration will be set
|
||||||
* @param speed The speed it will accelerate in pixels per second
|
* @param {number} speed The speed it will accelerate in pixels per second
|
||||||
* @param xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
* @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
||||||
* @param ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
||||||
*/
|
*/
|
||||||
public accelerateTowardsMouse(source:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number)
|
public accelerateTowardsMouse(source:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number)
|
||||||
{
|
{
|
||||||
var a:number = this.angleBetweenMouse(source);
|
var a:number = this.angleBetweenMouse(source);
|
||||||
|
|
||||||
source.velocity.x = 0;
|
source.velocity.x = 0;
|
||||||
source.velocity.y = 0;
|
source.velocity.y = 0;
|
||||||
|
|
||||||
source.acceleration.x = Math.cos(a) * speed;
|
source.acceleration.x = Math.cos(a) * speed;
|
||||||
source.acceleration.y = Math.sin(a) * speed;
|
source.acceleration.y = Math.sin(a) * speed;
|
||||||
|
|
||||||
source.maxVelocity.x = xSpeedMax;
|
source.maxVelocity.x = xSpeedMax;
|
||||||
source.maxVelocity.y = ySpeedMax;
|
source.maxVelocity.y = ySpeedMax;
|
||||||
}
|
}
|
||||||
@@ -202,24 +202,24 @@ module Phaser {
|
|||||||
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
|
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
|
||||||
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
|
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
|
||||||
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
||||||
*
|
*
|
||||||
* @param source The Sprite to move
|
* @param {GameObject} source The Sprite to move
|
||||||
* @param target The Point coordinates to move the source Sprite towards
|
* @param {Point} target The Point coordinates to move the source Sprite towards
|
||||||
* @param speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
* @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
||||||
* @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
||||||
*/
|
*/
|
||||||
public moveTowardsPoint(source:GameObject, target:Point, speed:number = 60, maxTime:number = 0)
|
public moveTowardsPoint(source:GameObject, target:Point, speed:number = 60, maxTime:number = 0)
|
||||||
{
|
{
|
||||||
var a:number = this.angleBetweenPoint(source, target);
|
var a:number = this.angleBetweenPoint(source, target);
|
||||||
|
|
||||||
if (maxTime > 0)
|
if (maxTime > 0)
|
||||||
{
|
{
|
||||||
var d:number = this.distanceToPoint(source, target);
|
var d:number = this.distanceToPoint(source, target);
|
||||||
|
|
||||||
// We know how many pixels we need to move, but how fast?
|
// We know how many pixels we need to move, but how fast?
|
||||||
speed = d / (maxTime / 1000);
|
speed = d / (maxTime / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
source.velocity.x = Math.cos(a) * speed;
|
source.velocity.x = Math.cos(a) * speed;
|
||||||
source.velocity.y = Math.sin(a) * speed;
|
source.velocity.y = Math.sin(a) * speed;
|
||||||
}
|
}
|
||||||
@@ -228,87 +228,87 @@ module Phaser {
|
|||||||
* Sets the x/y acceleration on the source Sprite so it will move towards the target coordinates at the speed given (in pixels per second)<br>
|
* Sets the x/y acceleration on the source Sprite so it will move towards the target coordinates at the speed given (in pixels per second)<br>
|
||||||
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
|
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
|
||||||
* If you don't need acceleration look at moveTowardsPoint() instead.
|
* If you don't need acceleration look at moveTowardsPoint() instead.
|
||||||
*
|
*
|
||||||
* @param source The Sprite on which the acceleration will be set
|
* @param {GameObject} source The Sprite on which the acceleration will be set
|
||||||
* @param target The Point coordinates to move the source Sprite towards
|
* @param {Point} target The Point coordinates to move the source Sprite towards
|
||||||
* @param speed The speed it will accelerate in pixels per second
|
* @param {number} speed The speed it will accelerate in pixels per second
|
||||||
* @param xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
* @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
||||||
* @param ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
||||||
*/
|
*/
|
||||||
public accelerateTowardsPoint(source:GameObject, target:Point, speed:number, xSpeedMax:number, ySpeedMax:number)
|
public accelerateTowardsPoint(source:GameObject, target:Point, speed:number, xSpeedMax:number, ySpeedMax:number)
|
||||||
{
|
{
|
||||||
var a:number = this.angleBetweenPoint(source, target);
|
var a:number = this.angleBetweenPoint(source, target);
|
||||||
|
|
||||||
source.velocity.x = 0;
|
source.velocity.x = 0;
|
||||||
source.velocity.y = 0;
|
source.velocity.y = 0;
|
||||||
|
|
||||||
source.acceleration.x = Math.cos(a) * speed;
|
source.acceleration.x = Math.cos(a) * speed;
|
||||||
source.acceleration.y = Math.sin(a) * speed;
|
source.acceleration.y = Math.sin(a) * speed;
|
||||||
|
|
||||||
source.maxVelocity.x = xSpeedMax;
|
source.maxVelocity.x = xSpeedMax;
|
||||||
source.maxVelocity.y = ySpeedMax;
|
source.maxVelocity.y = ySpeedMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the distance (in pixels, rounded) between two Sprites, taking their origin into account
|
* Find the distance (in pixels, rounded) between two Sprites, taking their origin into account
|
||||||
*
|
*
|
||||||
* @param a The first Sprite
|
* @param {GameObject} a The first Sprite
|
||||||
* @param b The second Sprite
|
* @param {GameObject} b The second Sprite
|
||||||
* @return int Distance (in pixels)
|
* @return {number} int Distance (in pixels)
|
||||||
*/
|
*/
|
||||||
public distanceBetween(a:GameObject, b:GameObject):number
|
public distanceBetween(a:GameObject, b:GameObject):number
|
||||||
{
|
{
|
||||||
var dx:number = (a.x + a.origin.x) - (b.x + b.origin.x);
|
var dx:number = (a.x + a.origin.x) - (b.x + b.origin.x);
|
||||||
var dy:number = (a.y + a.origin.y) - (b.y + b.origin.y);
|
var dy:number = (a.y + a.origin.y) - (b.y + b.origin.y);
|
||||||
|
|
||||||
return this._game.math.vectorLength(dx, dy);
|
return this._game.math.vectorLength(dx, dy);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the distance (in pixels, rounded) from an Sprite to the given Point, taking the source origin into account
|
* Find the distance (in pixels, rounded) from an Sprite to the given Point, taking the source origin into account
|
||||||
*
|
*
|
||||||
* @param a The Sprite
|
* @param {GameObject} a The Sprite
|
||||||
* @param target The Point
|
* @param {Point} target The Point
|
||||||
* @return int Distance (in pixels)
|
* @return {number} Distance (in pixels)
|
||||||
*/
|
*/
|
||||||
public distanceToPoint(a:GameObject, target:Point):number
|
public distanceToPoint(a:GameObject, target:Point):number
|
||||||
{
|
{
|
||||||
var dx:number = (a.x + a.origin.x) - (target.x);
|
var dx:number = (a.x + a.origin.x) - (target.x);
|
||||||
var dy:number = (a.y + a.origin.y) - (target.y);
|
var dy:number = (a.y + a.origin.y) - (target.y);
|
||||||
|
|
||||||
return this._game.math.vectorLength(dx, dy);
|
return this._game.math.vectorLength(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the distance (in pixels, rounded) from the object x/y and the mouse x/y
|
* Find the distance (in pixels, rounded) from the object x/y and the mouse x/y
|
||||||
*
|
*
|
||||||
* @param a The Sprite to test against
|
* @param {GameObject} a Sprite to test against
|
||||||
* @return int The distance between the given sprite and the mouse coordinates
|
* @return {number} The distance between the given sprite and the mouse coordinates
|
||||||
*/
|
*/
|
||||||
public distanceToMouse(a:GameObject):number
|
public distanceToMouse(a:GameObject):number
|
||||||
{
|
{
|
||||||
var dx: number = (a.x + a.origin.x) - this._game.input.x;
|
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 dy: number = (a.y + a.origin.y) - this._game.input.y;
|
||||||
|
|
||||||
return this._game.math.vectorLength(dx, dy);
|
return this._game.math.vectorLength(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the angle (in radians) between an Sprite and an Point. The source sprite takes its x/y and origin into account.
|
* Find the angle (in radians) between an Sprite and an Point. The source sprite takes its x/y and origin into account.
|
||||||
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
||||||
*
|
*
|
||||||
* @param a The Sprite to test from
|
* @param {GameObject} a The Sprite to test from
|
||||||
* @param target The Point to angle the Sprite towards
|
* @param {Point} target The Point to angle the Sprite towards
|
||||||
* @param asDegrees If you need the value in degrees instead of radians, set to true
|
* @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true
|
||||||
*
|
*
|
||||||
* @return Number The angle (in radians unless asDegrees is true)
|
* @return {number} The angle (in radians unless asDegrees is true)
|
||||||
*/
|
*/
|
||||||
public angleBetweenPoint(a:GameObject, target:Point, asDegrees:bool = false):number
|
public angleBetweenPoint(a:GameObject, target:Point, asDegrees:bool = false):number
|
||||||
{
|
{
|
||||||
var dx:number = (target.x) - (a.x + a.origin.x);
|
var dx:number = (target.x) - (a.x + a.origin.x);
|
||||||
var dy:number = (target.y) - (a.y + a.origin.y);
|
var dy:number = (target.y) - (a.y + a.origin.y);
|
||||||
|
|
||||||
if (asDegrees)
|
if (asDegrees)
|
||||||
{
|
{
|
||||||
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
|
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
|
||||||
@@ -322,18 +322,18 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Find the angle (in radians) between the two Sprite, taking their x/y and origin into account.
|
* Find the angle (in radians) between the two Sprite, taking their x/y and origin into account.
|
||||||
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
||||||
*
|
*
|
||||||
* @param a The Sprite to test from
|
* @param {GameObject} a The Sprite to test from
|
||||||
* @param b The Sprite to test to
|
* @param {GameObject} b The Sprite to test to
|
||||||
* @param asDegrees If you need the value in degrees instead of radians, set to true
|
* @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true
|
||||||
*
|
*
|
||||||
* @return Number The angle (in radians unless asDegrees is true)
|
* @return {number} The angle (in radians unless asDegrees is true)
|
||||||
*/
|
*/
|
||||||
public angleBetween(a:GameObject, b:GameObject, asDegrees:bool = false):number
|
public angleBetween(a:GameObject, b:GameObject, asDegrees:bool = false):number
|
||||||
{
|
{
|
||||||
var dx:number = (b.x + b.origin.x) - (a.x + a.origin.x);
|
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 dy:number = (b.y + b.origin.y) - (a.y + a.origin.y);
|
||||||
|
|
||||||
if (asDegrees)
|
if (asDegrees)
|
||||||
{
|
{
|
||||||
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
|
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
|
||||||
@@ -346,16 +346,16 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the GameObject and speed calculate the velocity and return it as an Point based on the direction the sprite is facing
|
* Given the GameObject and speed calculate the velocity and return it as an Point based on the direction the sprite is facing
|
||||||
*
|
*
|
||||||
* @param parent The Sprite to get the facing value from
|
* @param {GameObject} parent The Sprite to get the facing value from
|
||||||
* @param speed The speed it will move, in pixels per second sq
|
* @param {number} speed The speed it will move, in pixels per second sq
|
||||||
*
|
*
|
||||||
* @return An Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
* @return {Point} An Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||||
*/
|
*/
|
||||||
public velocityFromFacing(parent:GameObject, speed:number):Point
|
public velocityFromFacing(parent:GameObject, speed:number):Point
|
||||||
{
|
{
|
||||||
var a:number;
|
var a:number;
|
||||||
|
|
||||||
if (parent.facing == Collision.LEFT)
|
if (parent.facing == Collision.LEFT)
|
||||||
{
|
{
|
||||||
a = this._game.math.degreesToRadians(180);
|
a = this._game.math.degreesToRadians(180);
|
||||||
@@ -372,28 +372,28 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
a = this._game.math.degreesToRadians(90);
|
a = this._game.math.degreesToRadians(90);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Point(Math.cos(a) * speed, Math.sin(a) * speed);
|
return new Point(Math.cos(a) * speed, Math.sin(a) * speed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the angle (in radians) between an Sprite and the mouse, taking their x/y and origin into account.
|
* Find the angle (in radians) between an Sprite and the mouse, taking their x/y and origin into account.
|
||||||
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
||||||
*
|
*
|
||||||
* @param a The Object to test from
|
* @param {GameObject} a The Object to test from
|
||||||
* @param asDegrees If you need the value in degrees instead of radians, set to true
|
* @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true
|
||||||
*
|
*
|
||||||
* @return Number The angle (in radians unless asDegrees is true)
|
* @return {number} The angle (in radians unless asDegrees is true)
|
||||||
*/
|
*/
|
||||||
public angleBetweenMouse(a:GameObject, asDegrees:bool = false):number
|
public angleBetweenMouse(a:GameObject, asDegrees:bool = false):number
|
||||||
{
|
{
|
||||||
// In order to get the angle between the object and mouse, we need the objects screen coordinates (rather than world coordinates)
|
// In order to get the angle between the object and mouse, we need the objects screen coordinates (rather than world coordinates)
|
||||||
var p:MicroPoint = a.getScreenXY();
|
var p:MicroPoint = a.getScreenXY();
|
||||||
|
|
||||||
var dx:number = a._game.input.x - p.x;
|
var dx:number = a._game.input.x - p.x;
|
||||||
var dy:number = a._game.input.y - p.y;
|
var dy:number = a._game.input.y - p.y;
|
||||||
|
|
||||||
if (asDegrees)
|
if (asDegrees)
|
||||||
{
|
{
|
||||||
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
|
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
|
||||||
|
|||||||
+56
-4
@@ -79,6 +79,10 @@
|
|||||||
<Content Include="GameMath.js">
|
<Content Include="GameMath.js">
|
||||||
<DependentUpon>GameMath.ts</DependentUpon>
|
<DependentUpon>GameMath.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="GameObjectFactory.ts" />
|
||||||
|
<Content Include="GameObjectFactory.js">
|
||||||
|
<DependentUpon>GameObjectFactory.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="gameobjects\Emitter.js">
|
<Content Include="gameobjects\Emitter.js">
|
||||||
<DependentUpon>Emitter.ts</DependentUpon>
|
<DependentUpon>Emitter.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -105,9 +109,33 @@
|
|||||||
<Content Include="gameobjects\Tilemap.js">
|
<Content Include="gameobjects\Tilemap.js">
|
||||||
<DependentUpon>Tilemap.ts</DependentUpon>
|
<DependentUpon>Tilemap.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="verlet\AngleConstraint.ts" />
|
||||||
|
<TypeScriptCompile Include="VerletManager.ts" />
|
||||||
|
<TypeScriptCompile Include="geom\Polygon.ts" />
|
||||||
|
<Content Include="geom\Polygon.js">
|
||||||
|
<DependentUpon>Polygon.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geom\Response.ts" />
|
||||||
|
<Content Include="geom\Response.js">
|
||||||
|
<DependentUpon>Response.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="VerletManager.js">
|
||||||
|
<DependentUpon>VerletManager.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="verlet\AngleConstraint.js">
|
||||||
|
<DependentUpon>AngleConstraint.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="geom\Circle.js">
|
<Content Include="geom\Circle.js">
|
||||||
<DependentUpon>Circle.ts</DependentUpon>
|
<DependentUpon>Circle.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="verlet\DistanceConstraint.ts" />
|
||||||
|
<TypeScriptCompile Include="verlet\Composite.ts" />
|
||||||
|
<Content Include="verlet\Composite.js">
|
||||||
|
<DependentUpon>Composite.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="verlet\DistanceConstraint.js">
|
||||||
|
<DependentUpon>DistanceConstraint.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="geom\IntersectResult.js">
|
<Content Include="geom\IntersectResult.js">
|
||||||
<DependentUpon>IntersectResult.ts</DependentUpon>
|
<DependentUpon>IntersectResult.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -118,6 +146,14 @@
|
|||||||
<Content Include="geom\MicroPoint.js">
|
<Content Include="geom\MicroPoint.js">
|
||||||
<DependentUpon>MicroPoint.ts</DependentUpon>
|
<DependentUpon>MicroPoint.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="verlet\PinConstraint.ts" />
|
||||||
|
<TypeScriptCompile Include="verlet\Particle.ts" />
|
||||||
|
<Content Include="verlet\Particle.js">
|
||||||
|
<DependentUpon>Particle.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="verlet\PinConstraint.js">
|
||||||
|
<DependentUpon>PinConstraint.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="geom\Point.js">
|
<Content Include="geom\Point.js">
|
||||||
<DependentUpon>Point.ts</DependentUpon>
|
<DependentUpon>Point.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -128,11 +164,31 @@
|
|||||||
<Content Include="geom\Rectangle.js">
|
<Content Include="geom\Rectangle.js">
|
||||||
<DependentUpon>Rectangle.ts</DependentUpon>
|
<DependentUpon>Rectangle.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geom\Vector2.ts" />
|
||||||
|
<Content Include="geom\Vector2.js">
|
||||||
|
<DependentUpon>Vector2.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="SoundManager.js">
|
<Content Include="SoundManager.js">
|
||||||
<DependentUpon>SoundManager.ts</DependentUpon>
|
<DependentUpon>SoundManager.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
<TypeScriptCompile Include="system\screens\PauseScreen.ts" />
|
<TypeScriptCompile Include="system\screens\PauseScreen.ts" />
|
||||||
<TypeScriptCompile Include="system\screens\BootScreen.ts" />
|
<TypeScriptCompile Include="system\screens\BootScreen.ts" />
|
||||||
|
<TypeScriptCompile Include="system\input\MSPointer.ts" />
|
||||||
|
<TypeScriptCompile Include="system\input\Gestures.ts" />
|
||||||
|
<TypeScriptCompile Include="system\CollisionMask.ts" />
|
||||||
|
<Content Include="system\CollisionMask.js">
|
||||||
|
<DependentUpon>CollisionMask.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="system\input\Gestures.js">
|
||||||
|
<DependentUpon>Gestures.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="system\input\MSPointer.js">
|
||||||
|
<DependentUpon>MSPointer.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="system\input\Pointer.ts" />
|
||||||
|
<Content Include="system\input\Pointer.js">
|
||||||
|
<DependentUpon>Pointer.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="system\screens\BootScreen.js">
|
<Content Include="system\screens\BootScreen.js">
|
||||||
<DependentUpon>BootScreen.ts</DependentUpon>
|
<DependentUpon>BootScreen.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -229,9 +285,6 @@
|
|||||||
<Content Include="system\easing\Sinusoidal.js">
|
<Content Include="system\easing\Sinusoidal.js">
|
||||||
<DependentUpon>Sinusoidal.ts</DependentUpon>
|
<DependentUpon>Sinusoidal.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="system\input\Finger.js">
|
|
||||||
<DependentUpon>Finger.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\input\Input.js">
|
<Content Include="system\input\Input.js">
|
||||||
<DependentUpon>Input.ts</DependentUpon>
|
<DependentUpon>Input.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -248,7 +301,6 @@
|
|||||||
<TypeScriptCompile Include="system\input\Mouse.ts" />
|
<TypeScriptCompile Include="system\input\Mouse.ts" />
|
||||||
<TypeScriptCompile Include="system\input\Keyboard.ts" />
|
<TypeScriptCompile Include="system\input\Keyboard.ts" />
|
||||||
<TypeScriptCompile Include="system\input\Input.ts" />
|
<TypeScriptCompile Include="system\input\Input.ts" />
|
||||||
<TypeScriptCompile Include="system\input\Finger.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Sinusoidal.ts" />
|
<TypeScriptCompile Include="system\easing\Sinusoidal.ts" />
|
||||||
<TypeScriptCompile Include="system\easing\Quintic.ts" />
|
<TypeScriptCompile Include="system\easing\Quintic.ts" />
|
||||||
<TypeScriptCompile Include="system\easing\Quartic.ts" />
|
<TypeScriptCompile Include="system\easing\Quartic.ts" />
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Phaser
|
* Phaser
|
||||||
*
|
*
|
||||||
* v0.9.5 - April 28th 2013
|
* v0.9.6 - May 21st 2013
|
||||||
*
|
*
|
||||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||||
*
|
*
|
||||||
@@ -16,6 +16,6 @@
|
|||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
|
|
||||||
export var VERSION: string = 'Phaser version 0.9.5';
|
export var VERSION: string = 'Phaser version 0.9.6';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ module Phaser {
|
|||||||
|
|
||||||
export class SoundManager {
|
export class SoundManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SoundManager constructor
|
||||||
|
* Create a new <code>SoundManager</code>.
|
||||||
|
*/
|
||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -36,18 +40,39 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to AudioContext instance.
|
||||||
|
*/
|
||||||
private _context = null;
|
private _context = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gain node created from audio context.
|
||||||
|
*/
|
||||||
private _gainNode;
|
private _gainNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Volume of sounds.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _volume: number;
|
private _volume: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mute sounds.
|
||||||
|
*/
|
||||||
public mute() {
|
public mute() {
|
||||||
|
|
||||||
this._gainNode.gain.value = 0;
|
this._gainNode.gain.value = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable sounds.
|
||||||
|
*/
|
||||||
public unmute() {
|
public unmute() {
|
||||||
|
|
||||||
this._gainNode.gain.value = this._volume;
|
this._gainNode.gain.value = this._volume;
|
||||||
@@ -65,6 +90,12 @@ module Phaser {
|
|||||||
return this._volume;
|
return this._volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a sound with its assets key.
|
||||||
|
* @param key {string} Assets key of the sound to be decoded.
|
||||||
|
* @param callback {function} This will be invoked when finished decoding.
|
||||||
|
* @param [sound] {Sound} its bufer will be set to decoded data.
|
||||||
|
*/
|
||||||
public decode(key: string, callback = null, sound?: Sound = null) {
|
public decode(key: string, callback = null, sound?: Sound = null) {
|
||||||
|
|
||||||
var soundData = this._game.cache.getSound(key);
|
var soundData = this._game.cache.getSound(key);
|
||||||
@@ -90,6 +121,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play a sound with its assets key.
|
||||||
|
* @param key {string} Assets key of the sound you want to play.
|
||||||
|
* @param [volume] {number} volume of the sound you want to play.
|
||||||
|
* @param [loop] {boolean} loop when it finished playing? (Default to false)
|
||||||
|
* @return {Sound} The playing sound object.
|
||||||
|
*/
|
||||||
public play(key: string, volume?: number = 1, loop?: bool = false): Sound {
|
public play(key: string, volume?: number = 1, loop?: bool = false): Sound {
|
||||||
|
|
||||||
if (this._context === null)
|
if (this._context === null)
|
||||||
|
|||||||
+137
-21
@@ -15,6 +15,15 @@ module Phaser {
|
|||||||
|
|
||||||
export class Stage {
|
export class Stage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stage constructor
|
||||||
|
*
|
||||||
|
* Create a new <code>Stage</code> with specific width and height.
|
||||||
|
*
|
||||||
|
* @param parent {number} ID of parent DOM element.
|
||||||
|
* @param width {number} Width of the stage.
|
||||||
|
* @param height {number} Height of the stage.
|
||||||
|
*/
|
||||||
constructor(game: Game, parent: string, width: number, height: number) {
|
constructor(game: Game, parent: string, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -35,12 +44,15 @@ module Phaser {
|
|||||||
|
|
||||||
// Consume default actions on the canvas
|
// Consume default actions on the canvas
|
||||||
this.canvas.style.msTouchAction = 'none';
|
this.canvas.style.msTouchAction = 'none';
|
||||||
|
this.canvas.style['ms-touch-action'] = 'none';
|
||||||
this.canvas.style['touch-action'] = 'none';
|
this.canvas.style['touch-action'] = 'none';
|
||||||
|
this.canvas.style.backgroundColor = 'rgb(0,0,0)';
|
||||||
|
this.canvas.oncontextmenu = function(event) { event.preventDefault(); };
|
||||||
|
|
||||||
this.context = this.canvas.getContext('2d');
|
this.context = this.canvas.getContext('2d');
|
||||||
|
|
||||||
this.offset = this.getOffset(this.canvas);
|
this.offset = this.getOffset(this.canvas);
|
||||||
this.bounds = new Rectangle(this.offset.x, this.offset.y, width, height);
|
this.bounds = new Quad(this.offset.x, this.offset.y, width, height);
|
||||||
this.aspectRatio = width / height;
|
this.aspectRatio = width / height;
|
||||||
this.scaleMode = StageScaleMode.NO_SCALE;
|
this.scaleMode = StageScaleMode.NO_SCALE;
|
||||||
this.scale = new StageScaleMode(this._game);
|
this.scale = new StageScaleMode(this._game);
|
||||||
@@ -55,30 +67,96 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
private _bgColor: string;
|
|
||||||
|
/**
|
||||||
|
* Background color of the stage (defaults to black)
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
private _bgColor: string = 'rgb(0,0,0)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be displayed when Phaser is started without any default functions or State
|
||||||
|
* @type {BootScreen}
|
||||||
|
*/
|
||||||
private _bootScreen;
|
private _bootScreen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be displayed whenever the game loses focus or the player switches to another browser tab.
|
||||||
|
* @type {PauseScreen}
|
||||||
|
*/
|
||||||
private _pauseScreen;
|
private _pauseScreen;
|
||||||
|
|
||||||
public static ORIENTATION_LANDSCAPE: number = 0;
|
/**
|
||||||
public static ORIENTATION_PORTRAIT: number = 1;
|
* Bound of this stage.
|
||||||
|
* @type {Quad}
|
||||||
|
*/
|
||||||
|
public bounds: Quad;
|
||||||
|
|
||||||
public bounds: Rectangle;
|
/**
|
||||||
|
* Asperct ratio, thus: width / height.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public aspectRatio: number;
|
public aspectRatio: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the whole stage every frame? (Default to true)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public clear: bool = true;
|
public clear: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas element used by engine.
|
||||||
|
* @type {HTMLCanvasElement}
|
||||||
|
*/
|
||||||
public canvas: HTMLCanvasElement;
|
public canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render context of stage's canvas.
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
public context: CanvasRenderingContext2D;
|
public context: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not use pause screen when game is paused?
|
||||||
|
* (Default to false, aka always use PauseScreen)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public disablePauseScreen: bool = false;
|
public disablePauseScreen: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not use boot screen when engine starts?
|
||||||
|
* (Default to false, aka always use BootScreen)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public disableBootScreen: bool = false;
|
public disableBootScreen: bool = false;
|
||||||
public offset: Point;
|
|
||||||
|
/**
|
||||||
|
* Offset from this stage to the canvas element.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
|
public offset: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This object manages scaling of the game, see(StageScaleMode).
|
||||||
|
* @type {StageScaleMode}
|
||||||
|
*/
|
||||||
public scale: StageScaleMode;
|
public scale: StageScaleMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which mode will the game be scaled.
|
||||||
|
* Available: StageScaleMode.EXACT_FIT, StageScaleMode.NO_SCALE, StageScaleMode.SHOW_ALL.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public scaleMode: number;
|
public scaleMode: number;
|
||||||
|
|
||||||
public minScaleX: number = null;
|
/**
|
||||||
public maxScaleX: number = null;
|
* Update stage for rendering. This will handle scaling, clearing
|
||||||
public minScaleY: number = null;
|
* and PauseScreen/BootScreen updating and rendering.
|
||||||
public maxScaleY: number = null;
|
*/
|
||||||
|
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
this.scale.update();
|
this.scale.update();
|
||||||
@@ -103,6 +181,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called when the canvas elements visibility is changed.
|
||||||
|
*/
|
||||||
private visibilityChange(event) {
|
private visibilityChange(event) {
|
||||||
|
|
||||||
if (this.disablePauseScreen)
|
if (this.disablePauseScreen)
|
||||||
@@ -110,28 +191,43 @@ module Phaser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type === 'blur' || document['hidden'] === true || document['webkitHidden'] === true)
|
if (event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
|
||||||
{
|
{
|
||||||
if (this._game.paused == false)
|
if (this._game.paused == false)
|
||||||
{
|
{
|
||||||
this._pauseScreen.onPaused();
|
this.pauseGame();
|
||||||
this.saveCanvasValues();
|
|
||||||
this._game.paused = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.type == 'focus')
|
else
|
||||||
{
|
{
|
||||||
if (this._game.paused == true)
|
if (this._game.paused == true)
|
||||||
{
|
{
|
||||||
this._pauseScreen.onResume();
|
this.resumeGame();
|
||||||
this._game.paused = false;
|
|
||||||
this.restoreCanvasValues();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getOffset(element): Point {
|
public pauseGame() {
|
||||||
|
|
||||||
|
this._pauseScreen.onPaused();
|
||||||
|
this.saveCanvasValues();
|
||||||
|
this._game.paused = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public resumeGame() {
|
||||||
|
|
||||||
|
this._pauseScreen.onResume();
|
||||||
|
this.restoreCanvasValues();
|
||||||
|
this._game.paused = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the DOM offset values of the given element
|
||||||
|
*/
|
||||||
|
private getOffset(element): MicroPoint {
|
||||||
|
|
||||||
var box = element.getBoundingClientRect();
|
var box = element.getBoundingClientRect();
|
||||||
|
|
||||||
@@ -140,14 +236,31 @@ module Phaser {
|
|||||||
var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
|
var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
|
||||||
var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
|
var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
|
||||||
|
|
||||||
return new Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
|
return new MicroPoint(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas strokeStyle.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public strokeStyle: string;
|
public strokeStyle: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas lineWidth.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public lineWidth: number;
|
public lineWidth: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas fillStyle.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public fillStyle: string;
|
public fillStyle: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save current canvas properties (strokeStyle, lineWidth and fillStyle) for later using.
|
||||||
|
*/
|
||||||
public saveCanvasValues() {
|
public saveCanvasValues() {
|
||||||
|
|
||||||
this.strokeStyle = this.context.strokeStyle;
|
this.strokeStyle = this.context.strokeStyle;
|
||||||
@@ -156,6 +269,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore current canvas values (strokeStyle, lineWidth and fillStyle) with saved values.
|
||||||
|
*/
|
||||||
public restoreCanvasValues() {
|
public restoreCanvasValues() {
|
||||||
|
|
||||||
this.context.strokeStyle = this.strokeStyle;
|
this.context.strokeStyle = this.strokeStyle;
|
||||||
|
|||||||
+111
-44
@@ -10,10 +10,15 @@ module Phaser {
|
|||||||
|
|
||||||
export class State {
|
export class State {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State constructor
|
||||||
|
* Create a new <code>State</code>.
|
||||||
|
*/
|
||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
|
this.add = game.add;
|
||||||
this.camera = game.camera;
|
this.camera = game.camera;
|
||||||
this.cache = game.cache;
|
this.cache = game.cache;
|
||||||
this.collision = game.collision;
|
this.collision = game.collision;
|
||||||
@@ -29,73 +34,135 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to Game.
|
||||||
|
*/
|
||||||
public game: Game;
|
public game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently used camera.
|
||||||
|
* @type {Camera}
|
||||||
|
*/
|
||||||
public camera: Camera;
|
public camera: Camera;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the assets cache.
|
||||||
|
* @type {Cache}
|
||||||
|
*/
|
||||||
public cache: Cache;
|
public cache: Cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the collision helper.
|
||||||
|
* @type {Collision}
|
||||||
|
*/
|
||||||
public collision: Collision;
|
public collision: Collision;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the GameObject Factory.
|
||||||
|
* @type {GameObjectFactory}
|
||||||
|
*/
|
||||||
|
public add: GameObjectFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the input manager
|
||||||
|
* @type {Input}
|
||||||
|
*/
|
||||||
public input: Input;
|
public input: Input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the assets loader.
|
||||||
|
* @type {Loader}
|
||||||
|
*/
|
||||||
public loader: Loader;
|
public loader: Loader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the math helper.
|
||||||
|
* @type {GameMath}
|
||||||
|
*/
|
||||||
public math: GameMath;
|
public math: GameMath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the motion helper.
|
||||||
|
* @type {Motion}
|
||||||
|
*/
|
||||||
public motion: Motion;
|
public motion: Motion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the sound manager.
|
||||||
|
* @type {SoundManager}
|
||||||
|
*/
|
||||||
public sound: SoundManager;
|
public sound: SoundManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the stage.
|
||||||
|
* @type {Stage}
|
||||||
|
*/
|
||||||
public stage: Stage;
|
public stage: Stage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to game clock.
|
||||||
|
* @type {Time}
|
||||||
|
*/
|
||||||
public time: Time;
|
public time: Time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the tween manager.
|
||||||
|
* @type {TweenManager}
|
||||||
|
*/
|
||||||
public tweens: TweenManager;
|
public tweens: TweenManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the world.
|
||||||
|
* @type {World}
|
||||||
|
*/
|
||||||
public world: World;
|
public world: World;
|
||||||
|
|
||||||
|
// Override these in your own States
|
||||||
|
|
||||||
// Overload these in your own States
|
/**
|
||||||
|
* Override this method to add some load operations.
|
||||||
|
* If you need to use the loader, you may need to use them here.
|
||||||
|
*/
|
||||||
public init() { }
|
public init() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called after the game engine successfully switches states.
|
||||||
|
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
|
||||||
|
*/
|
||||||
public create() { }
|
public create() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put update logic here.
|
||||||
|
*/
|
||||||
public update() { }
|
public update() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put render operations here.
|
||||||
|
*/
|
||||||
public render() { }
|
public render() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be called when game paused.
|
||||||
|
*/
|
||||||
public paused() { }
|
public paused() { }
|
||||||
|
|
||||||
// Handy Proxy methods
|
/**
|
||||||
|
* This method will be called when the state is destroyed
|
||||||
|
*/
|
||||||
|
public destroy() { }
|
||||||
|
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
/**
|
||||||
return this.game.world.createCamera(x, y, width, height);
|
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
|
||||||
}
|
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
|
||||||
|
* @param object1 The first GameObject or Group to check. If null the world.group is used.
|
||||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
* @param object2 The second GameObject or Group to check.
|
||||||
return this.world.createGeomSprite(x, y);
|
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
|
||||||
}
|
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
|
||||||
|
* @param context The context in which the callbacks will be called
|
||||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
* @returns {boolean} true if the objects overlap, otherwise false.
|
||||||
return this.game.world.createSprite(x, y, key);
|
*/
|
||||||
}
|
public collide(objectOrGroup1: Basic = null, objectOrGroup2: Basic = null, notifyCallback = null, context? = this.game.callbackContext): bool {
|
||||||
|
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
|
||||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
|
||||||
return this.game.world.createDynamicTexture(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGroup(MaxSize?: number = 0): Group {
|
|
||||||
return this.game.world.createGroup(MaxSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParticle(): Particle {
|
|
||||||
return this.game.world.createParticle();
|
|
||||||
}
|
|
||||||
|
|
||||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
|
||||||
return this.game.world.createEmitter(x, y, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
|
||||||
return this.game.world.createScrollZone(key, x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
|
||||||
return this.game.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTween(obj): Tween {
|
|
||||||
return this.game.tweens.create(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public collide(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null): bool {
|
|
||||||
return this.collision.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, Collision.separate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+92
-39
@@ -10,40 +10,64 @@ module Phaser {
|
|||||||
|
|
||||||
export class Time {
|
export class Time {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time constructor
|
||||||
|
* Create a new <code>Time</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
*/
|
||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this._started = Date.now();
|
this._started = 0;
|
||||||
this._timeLastSecond = this._started;
|
this._timeLastSecond = this._started;
|
||||||
this.time = this._started;
|
this.time = this._started;
|
||||||
|
this._game = game;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time when this object created.
|
||||||
|
* @param {number}
|
||||||
|
*/
|
||||||
private _started: number;
|
private _started: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time scale factor.
|
||||||
|
* Set it to 0.5 for slow motion, to 2.0 makes game twice faster.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public timeScale: number = 1.0;
|
public timeScale: number = 1.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Elapsed since last frame.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public elapsed: number = 0;
|
public elapsed: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Game time counter.
|
||||||
* @property time
|
* @property time
|
||||||
* @type Number
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
public time: number = 0;
|
public time: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Time of current frame.
|
||||||
* @property now
|
* @property now
|
||||||
* @type Number
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
public now: number = 0;
|
public now: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Elapsed time since last frame.
|
||||||
* @property delta
|
* @property delta
|
||||||
* @type Number
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
public delta: number = 0;
|
public delta: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,23 +81,58 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frames per second.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public fps: number = 0;
|
public fps: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimal fps.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public fpsMin: number = 1000;
|
public fpsMin: number = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximal fps.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public fpsMax: number = 0;
|
public fpsMax: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mininal duration between 2 frames.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public msMin: number = 1000;
|
public msMin: number = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximal duration between 2 frames.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public msMax: number = 0;
|
public msMax: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many frames in last second.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public frames: number = 0;
|
public frames: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time of last second.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _timeLastSecond: number = 0;
|
private _timeLastSecond: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Update clock and calculate the fps.
|
||||||
* @method update
|
* This is called automatically by Game._raf
|
||||||
*/
|
* @method update
|
||||||
public update() {
|
* @param {number} raf The current timestamp, either performance.now or Date.now
|
||||||
|
*/
|
||||||
|
public update(raf: number) {
|
||||||
|
|
||||||
// Can we use performance.now() ?
|
this.now = raf; // mark
|
||||||
this.now = Date.now(); // mark
|
//this.now = Date.now(); // mark
|
||||||
this.delta = this.now - this.time; // elapsedMS
|
this.delta = this.now - this.time; // elapsedMS
|
||||||
|
|
||||||
this.msMin = Math.min(this.msMin, this.delta);
|
this.msMin = Math.min(this.msMin, this.delta);
|
||||||
@@ -93,20 +152,14 @@ module Phaser {
|
|||||||
|
|
||||||
this.time = this.now; // _total
|
this.time = this.now; // _total
|
||||||
|
|
||||||
//// Lock the delta at 0.1 to minimise fps tunneling
|
|
||||||
//if (this.delta > 0.1)
|
|
||||||
//{
|
|
||||||
// this.delta = 0.1;
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* How long has passed since given time.
|
||||||
* @method elapsedSince
|
* @method elapsedSince
|
||||||
* @param {Number} since
|
* @param {number} since The time you want to measure.
|
||||||
* @return {Number}
|
* @return {number} Duration between given time and now.
|
||||||
*/
|
*/
|
||||||
public elapsedSince(since: number): number {
|
public elapsedSince(since: number): number {
|
||||||
|
|
||||||
return this.now - since;
|
return this.now - since;
|
||||||
@@ -114,11 +167,11 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* How long has passed since give time (in seconds).
|
||||||
* @method elapsedSecondsSince
|
* @method elapsedSecondsSince
|
||||||
* @param {Number} since
|
* @param {number} since The time you want to measure (in seconds).
|
||||||
* @return {Number}
|
* @return {number} Duration between given time and now (in seconds).
|
||||||
*/
|
*/
|
||||||
public elapsedSecondsSince(since: number): number {
|
public elapsedSecondsSince(since: number): number {
|
||||||
|
|
||||||
return (this.now - since) * 0.001;
|
return (this.now - since) * 0.001;
|
||||||
@@ -126,9 +179,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Set the start time to now.
|
||||||
* @method reset
|
* @method reset
|
||||||
*/
|
*/
|
||||||
public reset() {
|
public reset() {
|
||||||
|
|
||||||
this._started = this.now;
|
this._started = this.now;
|
||||||
|
|||||||
+41
-1
@@ -7,7 +7,7 @@
|
|||||||
* The Game has a single instance of the TweenManager through which all Tween objects are created and updated.
|
* The Game has a single instance of the TweenManager through which all Tween objects are created and updated.
|
||||||
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
|
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
|
||||||
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
|
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
|
||||||
* I converted it to TypeScript, swapped the callbacks for signals and patched a few issues with regard
|
* I converted it to TypeScript, swapped the callbacks for signals and patched a few issues with regard
|
||||||
* to properties and completion errors. Please see https://github.com/sole/tween.js for a full list of contributors.
|
* to properties and completion errors. Please see https://github.com/sole/tween.js for a full list of contributors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,6 +15,10 @@ module Phaser {
|
|||||||
|
|
||||||
export class TweenManager {
|
export class TweenManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TweenManager constructor
|
||||||
|
* @param game {Game} A reference to the current Game.
|
||||||
|
*/
|
||||||
constructor(game: Phaser.Game) {
|
constructor(game: Phaser.Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -22,27 +26,53 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to Game
|
||||||
|
*/
|
||||||
private _game: Phaser.Game;
|
private _game: Phaser.Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private array which is the container of all tween objects.
|
||||||
|
*/
|
||||||
private _tweens: Phaser.Tween[];
|
private _tweens: Phaser.Tween[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the tween objects in an array.
|
||||||
|
* @return {Phaser.Tween[]} Array with all tween objects.
|
||||||
|
*/
|
||||||
public getAll() {
|
public getAll() {
|
||||||
|
|
||||||
return this._tweens;
|
return this._tweens;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all tween objects.
|
||||||
|
*/
|
||||||
public removeAll() {
|
public removeAll() {
|
||||||
|
|
||||||
this._tweens.length = 0;
|
this._tweens.length = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a tween object for a specific object.
|
||||||
|
*
|
||||||
|
* @param object {object} Object you wish the tween will affect.
|
||||||
|
* @return {Phaser.Tween} The newly created tween object.
|
||||||
|
*/
|
||||||
public create(object): Phaser.Tween {
|
public create(object): Phaser.Tween {
|
||||||
|
|
||||||
return new Phaser.Tween(object, this._game);
|
return new Phaser.Tween(object, this._game);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an exist tween object to the manager.
|
||||||
|
*
|
||||||
|
* @param tween {Phaser.Tween} The tween object you want to add.
|
||||||
|
* @return {Phaser.Tween} The tween object you added to the manager.
|
||||||
|
*/
|
||||||
public add(tween: Phaser.Tween) {
|
public add(tween: Phaser.Tween) {
|
||||||
|
|
||||||
tween.parent = this._game;
|
tween.parent = this._game;
|
||||||
@@ -53,6 +83,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a tween from this manager.
|
||||||
|
*
|
||||||
|
* @param tween {Phaser.Tween} The tween object you want to remove.
|
||||||
|
*/
|
||||||
public remove(tween: Phaser.Tween) {
|
public remove(tween: Phaser.Tween) {
|
||||||
|
|
||||||
var i = this._tweens.indexOf(tween);
|
var i = this._tweens.indexOf(tween);
|
||||||
@@ -64,6 +99,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update all the tween objects you added to this manager.
|
||||||
|
*
|
||||||
|
* @return {boolean} Return false if there's no tween to update, otherwise return true.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
if (this._tweens.length === 0)
|
if (this._tweens.length === 0)
|
||||||
|
|||||||
@@ -0,0 +1,411 @@
|
|||||||
|
/// <reference path="Game.ts" />
|
||||||
|
/// <reference path="geom/Vector2.ts" />
|
||||||
|
/// <reference path="verlet/Composite.ts" />
|
||||||
|
/// <reference path="verlet/Particle.ts" />
|
||||||
|
/// <reference path="verlet/DistanceConstraint.ts" />
|
||||||
|
/// <reference path="verlet/PinConstraint.ts" />
|
||||||
|
/// <reference path="verlet/AngleConstraint.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Verlet
|
||||||
|
*
|
||||||
|
* Based on verlet-js by Sub Protocol released under MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser.Verlet {
|
||||||
|
|
||||||
|
export class VerletManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Vector2 object.
|
||||||
|
* @class Vector2
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x coordinate of vector2
|
||||||
|
* @param {Number} y The y coordinate of vector2
|
||||||
|
* @return {Vector2} This object
|
||||||
|
**/
|
||||||
|
constructor(game: Game, width: number, height: number) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.gravity = new Vector2(0, 0.2);
|
||||||
|
this.friction = 0.99;
|
||||||
|
this.groundFriction = 0.8;
|
||||||
|
|
||||||
|
this.canvas = game.stage.canvas;
|
||||||
|
this.context = game.stage.context;
|
||||||
|
|
||||||
|
this._game.input.onDown.add(this.mouseDownHandler, this);
|
||||||
|
this._game.input.onUp.add(this.mouseUpHandler, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private _game: Game;
|
||||||
|
private _v = new Phaser.Vector2;
|
||||||
|
|
||||||
|
public composites = [];
|
||||||
|
|
||||||
|
public width: number;
|
||||||
|
public height: number;
|
||||||
|
public step: number = 16;
|
||||||
|
public gravity: Vector2;
|
||||||
|
public friction: number;
|
||||||
|
public groundFriction: number;
|
||||||
|
public selectionRadius: number = 20;
|
||||||
|
public draggedEntity = null;
|
||||||
|
public highlightColor = '#4f545c';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the canvas this renders to
|
||||||
|
* @type {HTMLCanvasElement}
|
||||||
|
*/
|
||||||
|
public canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the context this renders to
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
|
public context: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes time of intersection of a particle with a wall
|
||||||
|
*
|
||||||
|
* @param {Vec2} line walls root position
|
||||||
|
* @param {Vec2} p particle position
|
||||||
|
* @param {Vec2} dir walls direction
|
||||||
|
* @param {Vec2} v particles velocity
|
||||||
|
*/
|
||||||
|
public intersectionTime(wall, p, dir, v) {
|
||||||
|
|
||||||
|
if (dir.x != 0)
|
||||||
|
{
|
||||||
|
var denominator = v.y - dir.y * v.x / dir.x;
|
||||||
|
if (denominator == 0) return undefined; // Movement is parallel to wall
|
||||||
|
var numerator = wall.y + dir.y * (p.x - wall.x) / dir.x - p.y;
|
||||||
|
return numerator / denominator;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (v.x == 0) return undefined; // parallel again
|
||||||
|
var denominator = v.x;
|
||||||
|
var numerator = wall.x - p.x;
|
||||||
|
return numerator / denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public intersectionPoint(wall, p, dir, v) {
|
||||||
|
var t = this.intersectionTime(wall, p, dir, v);
|
||||||
|
return new Phaser.Vector2(p.x + v.x * t, p.y + v.y * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bounds(particle: Phaser.Verlet.Particle) {
|
||||||
|
|
||||||
|
this._v.mutableSet(particle.pos);
|
||||||
|
this._v.mutableSub(particle.lastPos);
|
||||||
|
|
||||||
|
if (particle.pos.y > this.height - 1)
|
||||||
|
{
|
||||||
|
particle.pos.mutableSet(this.intersectionPoint(new Phaser.Vector2(0, this.height - 1), particle.lastPos, new Phaser.Vector2(1, 0), this._v));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (particle.pos.x < 0)
|
||||||
|
{
|
||||||
|
particle.pos.mutableSet(this.intersectionPoint(new Phaser.Vector2(0, 0), particle.pos, new Phaser.Vector2(0, 1), this._v));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (particle.pos.x > this.width - 1)
|
||||||
|
{
|
||||||
|
particle.pos.mutableSet(this.intersectionPoint(new Phaser.Vector2(this.width - 1, 0), particle.pos, new Phaser.Vector2(0, 1), this._v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public createPoint(pos: Vector2) {
|
||||||
|
|
||||||
|
var composite = new Phaser.Verlet.Composite(this._game);
|
||||||
|
|
||||||
|
composite.particles.push(new Phaser.Verlet.Particle(pos));
|
||||||
|
|
||||||
|
this.composites.push(composite);
|
||||||
|
|
||||||
|
return composite;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public createLineSegments(vertices, stiffness) {
|
||||||
|
|
||||||
|
var composite = new Phaser.Verlet.Composite(this._game);
|
||||||
|
var i;
|
||||||
|
|
||||||
|
for (i in vertices)
|
||||||
|
{
|
||||||
|
composite.particles.push(new Phaser.Verlet.Particle(vertices[i]));
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
composite.constraints.push(new Phaser.Verlet.DistanceConstraint(composite.particles[i], composite.particles[i - 1], stiffness));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.composites.push(composite);
|
||||||
|
|
||||||
|
return composite;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public createCloth(origin, width, height, segments, pinMod, stiffness) {
|
||||||
|
|
||||||
|
var composite = new Phaser.Verlet.Composite(this._game);
|
||||||
|
|
||||||
|
var xStride = width / segments;
|
||||||
|
var yStride = height / segments;
|
||||||
|
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
|
||||||
|
for (y = 0; y < segments; ++y)
|
||||||
|
{
|
||||||
|
for (x = 0; x < segments; ++x)
|
||||||
|
{
|
||||||
|
var px = origin.x + x * xStride - width / 2 + xStride / 2;
|
||||||
|
var py = origin.y + y * yStride - height / 2 + yStride / 2;
|
||||||
|
|
||||||
|
composite.particles.push(new Phaser.Verlet.Particle(new Vector2(px, py)));
|
||||||
|
|
||||||
|
if (x > 0)
|
||||||
|
{
|
||||||
|
composite.constraints.push(new Phaser.Verlet.DistanceConstraint(composite.particles[y * segments + x], composite.particles[y * segments + x - 1], stiffness));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y > 0)
|
||||||
|
{
|
||||||
|
composite.constraints.push(new Phaser.Verlet.DistanceConstraint(composite.particles[y * segments + x], composite.particles[(y - 1) * segments + x], stiffness));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = 0; x < segments; ++x)
|
||||||
|
{
|
||||||
|
if (x % pinMod == 0)
|
||||||
|
{
|
||||||
|
composite.pin(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.composites.push(composite);
|
||||||
|
|
||||||
|
return composite;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public createTire(origin, radius, segments, spokeStiffness, treadStiffness) {
|
||||||
|
|
||||||
|
var stride = (2 * Math.PI) / segments;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
var composite = new Phaser.Verlet.Composite(this._game);
|
||||||
|
|
||||||
|
// particles
|
||||||
|
for (i = 0; i < segments; ++i)
|
||||||
|
{
|
||||||
|
var theta = i * stride;
|
||||||
|
composite.particles.push(new Particle(new Vector2(origin.x + Math.cos(theta) * radius, origin.y + Math.sin(theta) * radius)));
|
||||||
|
}
|
||||||
|
|
||||||
|
var center = new Particle(origin);
|
||||||
|
composite.particles.push(center);
|
||||||
|
|
||||||
|
// constraints
|
||||||
|
for (i = 0; i < segments; ++i)
|
||||||
|
{
|
||||||
|
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[(i + 1) % segments], treadStiffness));
|
||||||
|
composite.constraints.push(new DistanceConstraint(composite.particles[i], center, spokeStiffness))
|
||||||
|
composite.constraints.push(new DistanceConstraint(composite.particles[i], composite.particles[(i + 5) % segments], treadStiffness));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.composites.push(composite);
|
||||||
|
|
||||||
|
return composite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
|
||||||
|
if (this.composites.length == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var i, j, c;
|
||||||
|
|
||||||
|
for (c in this.composites)
|
||||||
|
{
|
||||||
|
for (i in this.composites[c].particles)
|
||||||
|
{
|
||||||
|
var particles = this.composites[c].particles;
|
||||||
|
|
||||||
|
// calculate velocity
|
||||||
|
var velocity = particles[i].pos.sub(particles[i].lastPos).scale(this.friction);
|
||||||
|
|
||||||
|
// ground friction
|
||||||
|
if (particles[i].pos.y >= this.height - 1 && velocity.length2() > 0.000001)
|
||||||
|
{
|
||||||
|
var m = velocity.length();
|
||||||
|
velocity.x /= m;
|
||||||
|
velocity.y /= m;
|
||||||
|
velocity.mutableScale(m * this.groundFriction);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save last good state
|
||||||
|
particles[i].lastPos.mutableSet(particles[i].pos);
|
||||||
|
|
||||||
|
// gravity
|
||||||
|
particles[i].pos.mutableAdd(this.gravity);
|
||||||
|
|
||||||
|
// inertia
|
||||||
|
particles[i].pos.mutableAdd(velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle dragging of entities
|
||||||
|
if (this.draggedEntity)
|
||||||
|
{
|
||||||
|
this.draggedEntity.pos.mutableSet(this._game.input.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
// relax
|
||||||
|
var stepCoef = 1 / this.step;
|
||||||
|
|
||||||
|
for (c in this.composites)
|
||||||
|
{
|
||||||
|
var constraints = this.composites[c].constraints;
|
||||||
|
|
||||||
|
for (i = 0; i < this.step; ++i)
|
||||||
|
{
|
||||||
|
for (j in constraints)
|
||||||
|
{
|
||||||
|
constraints[j].relax(stepCoef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bounds checking
|
||||||
|
for (c in this.composites)
|
||||||
|
{
|
||||||
|
var particles = this.composites[c].particles;
|
||||||
|
|
||||||
|
for (i in particles)
|
||||||
|
{
|
||||||
|
this.bounds(particles[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private mouseDownHandler() {
|
||||||
|
|
||||||
|
var nearest = this.nearestEntity();
|
||||||
|
|
||||||
|
if (nearest)
|
||||||
|
{
|
||||||
|
this.draggedEntity = nearest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private mouseUpHandler() {
|
||||||
|
this.draggedEntity = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public nearestEntity() {
|
||||||
|
|
||||||
|
var c, i;
|
||||||
|
var d2Nearest = 0;
|
||||||
|
var entity = null;
|
||||||
|
var constraintsNearest = null;
|
||||||
|
|
||||||
|
// find nearest point
|
||||||
|
for (c in this.composites)
|
||||||
|
{
|
||||||
|
var particles = this.composites[c].particles;
|
||||||
|
|
||||||
|
for (i in particles)
|
||||||
|
{
|
||||||
|
var d2 = particles[i].pos.distance2(this._game.input.position);
|
||||||
|
|
||||||
|
if (d2 <= this.selectionRadius * this.selectionRadius && (entity == null || d2 < d2Nearest))
|
||||||
|
{
|
||||||
|
entity = particles[i];
|
||||||
|
constraintsNearest = this.composites[c].constraints;
|
||||||
|
d2Nearest = d2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// search for pinned constraints for this entity
|
||||||
|
for (i in constraintsNearest)
|
||||||
|
{
|
||||||
|
if (constraintsNearest[i] instanceof PinConstraint && constraintsNearest[i].a == entity)
|
||||||
|
{
|
||||||
|
entity = constraintsNearest[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public hideNearestEntityCircle: bool = false;
|
||||||
|
|
||||||
|
public render() {
|
||||||
|
|
||||||
|
var i, c;
|
||||||
|
|
||||||
|
for (c in this.composites)
|
||||||
|
{
|
||||||
|
// draw constraints
|
||||||
|
if (this.composites[c].drawConstraints)
|
||||||
|
{
|
||||||
|
this.composites[c].drawConstraints(this.context, this.composites[c]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var constraints = this.composites[c].constraints;
|
||||||
|
|
||||||
|
for (i in constraints)
|
||||||
|
{
|
||||||
|
constraints[i].render(this.context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw particles
|
||||||
|
if (this.composites[c].drawParticles)
|
||||||
|
{
|
||||||
|
this.composites[c].drawParticles(this.context, this.composites[c]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var particles = this.composites[c].particles;
|
||||||
|
|
||||||
|
for (i in particles)
|
||||||
|
{
|
||||||
|
particles[i].render(this.context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// highlight nearest / dragged entity
|
||||||
|
var nearest = this.draggedEntity || this.nearestEntity();
|
||||||
|
|
||||||
|
if (nearest && this.hideNearestEntityCircle == false)
|
||||||
|
{
|
||||||
|
this.context.beginPath();
|
||||||
|
this.context.arc(nearest.pos.x, nearest.pos.y, 8, 0, 2 * Math.PI);
|
||||||
|
this.context.strokeStyle = this.highlightColor;
|
||||||
|
this.context.stroke();
|
||||||
|
this.context.closePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+139
-5
@@ -3,6 +3,8 @@
|
|||||||
/**
|
/**
|
||||||
* Phaser - World
|
* Phaser - World
|
||||||
*
|
*
|
||||||
|
* "This world is but a canvas to our imagination." - Henry David Thoreau
|
||||||
|
*
|
||||||
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
|
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
|
||||||
* by stage limits and can be any size or dimension. You look into the world via cameras and all game objects
|
* by stage limits and can be any size or dimension. You look into the world via cameras and all game objects
|
||||||
* live within the world at world-based coordinates. By default a world is created the same size as your Stage.
|
* live within the world at world-based coordinates. By default a world is created the same size as your Stage.
|
||||||
@@ -12,14 +14,19 @@ module Phaser {
|
|||||||
|
|
||||||
export class World {
|
export class World {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* World constructor
|
||||||
|
* Create a new <code>World</code> with specific width and height.
|
||||||
|
*
|
||||||
|
* @param width {number} Width of the world bound.
|
||||||
|
* @param height {number} Height of the world bound.
|
||||||
|
*/
|
||||||
constructor(game: Game, width: number, height: number) {
|
constructor(game: Game, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
|
|
||||||
this.cameras = new CameraManager(this._game, 0, 0, width, height);
|
this.cameras = new CameraManager(this._game, 0, 0, width, height);
|
||||||
|
|
||||||
this._game.camera = this.cameras.current;
|
|
||||||
|
|
||||||
this.group = new Group(this._game, 0);
|
this.group = new Group(this._game, 0);
|
||||||
|
|
||||||
this.bounds = new Rectangle(0, 0, width, height);
|
this.bounds = new Rectangle(0, 0, width, height);
|
||||||
@@ -28,13 +35,37 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera manager of this world.
|
||||||
|
* @type {CameraManager}
|
||||||
|
*/
|
||||||
public cameras: CameraManager;
|
public cameras: CameraManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object container stores every object created with `create*` methods.
|
||||||
|
* @type {Group}
|
||||||
|
*/
|
||||||
public group: Group;
|
public group: Group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bound of this world that objects can not escape from.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public bounds: Rectangle;
|
public bounds: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public worldDivisions: number;
|
public worldDivisions: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called automatically every frame, and is where main logic performs.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
this.group.preUpdate();
|
this.group.preUpdate();
|
||||||
@@ -45,6 +76,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render every thing to the screen, automatically called after update().
|
||||||
|
*/
|
||||||
public render() {
|
public render() {
|
||||||
|
|
||||||
// Unlike in flixel our render process is camera driven, not group driven
|
// Unlike in flixel our render process is camera driven, not group driven
|
||||||
@@ -52,6 +86,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up memory.
|
||||||
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
|
||||||
this.group.destroy();
|
this.group.destroy();
|
||||||
@@ -62,7 +99,16 @@ module Phaser {
|
|||||||
|
|
||||||
// World methods
|
// World methods
|
||||||
|
|
||||||
public setSize(width: number, height: number, updateCameraBounds: bool = true) {
|
/**
|
||||||
|
* Update size of this world with specific width and height.
|
||||||
|
* You can choose update camera bounds and verlet manager automatically or not.
|
||||||
|
*
|
||||||
|
* @param width {number} New width of the world.
|
||||||
|
* @param height {number} New height of the world.
|
||||||
|
* @param [updateCameraBounds] {boolean} update camera bounds automatically or not. Default to true.
|
||||||
|
* @param [updateVerletBounds] {boolean} update verlet bounds automatically or not. Default to true.
|
||||||
|
*/
|
||||||
|
public setSize(width: number, height: number, updateCameraBounds: bool = true, updateVerletBounds: bool = true) {
|
||||||
|
|
||||||
this.bounds.width = width;
|
this.bounds.width = width;
|
||||||
this.bounds.height = height;
|
this.bounds.height = height;
|
||||||
@@ -72,6 +118,12 @@ module Phaser {
|
|||||||
this._game.camera.setBounds(0, 0, width, height);
|
this._game.camera.setBounds(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updateVerletBounds == true)
|
||||||
|
{
|
||||||
|
this._game.verlet.width = width;
|
||||||
|
this._game.verlet.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get width(): number {
|
public get width(): number {
|
||||||
@@ -108,48 +160,130 @@ module Phaser {
|
|||||||
|
|
||||||
// Cameras
|
// Cameras
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new camera with specific position and size.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new camera.
|
||||||
|
* @param y {number} Y position of the new camera.
|
||||||
|
* @param width {number} Width of the new camera.
|
||||||
|
* @param height {number} Height of the new camera.
|
||||||
|
* @returns {Camera} The newly created camera object.
|
||||||
|
*/
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
||||||
return this.cameras.addCamera(x, y, width, height);
|
return this.cameras.addCamera(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a new camera with its id.
|
||||||
|
*
|
||||||
|
* @param id {number} ID of the camera you want to remove.
|
||||||
|
* @returns {boolean} True if successfully removed the camera, otherwise return false.
|
||||||
|
*/
|
||||||
public removeCamera(id: number): bool {
|
public removeCamera(id: number): bool {
|
||||||
return this.cameras.removeCamera(id);
|
return this.cameras.removeCamera(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the cameras.
|
||||||
|
*
|
||||||
|
* @returns {array} An array contains all the cameras.
|
||||||
|
*/
|
||||||
public getAllCameras(): Camera[] {
|
public getAllCameras(): Camera[] {
|
||||||
return this.cameras.getAll();
|
return this.cameras.getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game Objects
|
// Game Objects
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Sprite with specific position and sprite sheet key.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new sprite.
|
||||||
|
* @param y {number} Y position of the new sprite.
|
||||||
|
* @param [key] {string} key for the sprite sheet you want it to use.
|
||||||
|
* @returns {Sprite} The newly created sprite object.
|
||||||
|
*/
|
||||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
||||||
return <Sprite> this.group.add(new Sprite(this._game, x, y, key));
|
return <Sprite> this.group.add(new Sprite(this._game, x, y, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new GeomSprite with specific position.
|
||||||
|
*
|
||||||
|
* @param x {number} X position of the new geom sprite.
|
||||||
|
* @param y {number} Y position of the new geom sprite.
|
||||||
|
* @returns {GeomSprite} The newly created geom sprite object.
|
||||||
|
*/
|
||||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
public createGeomSprite(x: number, y: number): GeomSprite {
|
||||||
return <GeomSprite> this.group.add(new GeomSprite(this._game, x, y));
|
return <GeomSprite> this.group.add(new GeomSprite(this._game, x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new DynamicTexture with specific size.
|
||||||
|
*
|
||||||
|
* @param width {number} Width of the texture.
|
||||||
|
* @param height {number} Height of the texture.
|
||||||
|
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||||
|
*/
|
||||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
||||||
return new DynamicTexture(this._game, width, height);
|
return new DynamicTexture(this._game, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createGroup(MaxSize?: number = 0): Group {
|
/**
|
||||||
return <Group> this.group.add(new Group(this._game, MaxSize));
|
* Create a new object container.
|
||||||
|
*
|
||||||
|
* @param [maxSize] {number} capacity of this group.
|
||||||
|
* @returns {Group} The newly created group.
|
||||||
|
*/
|
||||||
|
public createGroup(maxSize?: number = 0): Group {
|
||||||
|
return <Group> this.group.add(new Group(this._game, maxSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ScrollZone object with image key, position and size.
|
||||||
|
*
|
||||||
|
* @param key {number} Key to a image you wish this object to use.
|
||||||
|
* @param x {number} X position of this object.
|
||||||
|
* @param y {number} Y position of this object.
|
||||||
|
* @param width {number} Width of this object.
|
||||||
|
* @param height {number} Height of this object.
|
||||||
|
* @returns {ScrollZone} The newly created scroll zone object.
|
||||||
|
*/
|
||||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
||||||
return <ScrollZone> this.group.add(new ScrollZone(this._game, key, x, y, width, height));
|
return <ScrollZone> this.group.add(new ScrollZone(this._game, key, x, y, width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Tilemap.
|
||||||
|
*
|
||||||
|
* @param key {string} Key for tileset image.
|
||||||
|
* @param mapData {string} Data of this tilemap.
|
||||||
|
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||||
|
* @param [resizeWorld] {boolean} resize the world to make same as tilemap?
|
||||||
|
* @param [tileWidth] {number} width of each tile.
|
||||||
|
* @param [tileHeight] {number} height of each tile.
|
||||||
|
* @return {Tilemap} The newly created tilemap object.
|
||||||
|
*/
|
||||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||||
return <Tilemap> this.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
return <Tilemap> this.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Particle.
|
||||||
|
*
|
||||||
|
* @return {Particle} The newly created particle object.
|
||||||
|
*/
|
||||||
public createParticle(): Particle {
|
public createParticle(): Particle {
|
||||||
return new Particle(this._game);
|
return new Particle(this._game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Emitter.
|
||||||
|
*
|
||||||
|
* @param [x] {number} x position of the emitter.
|
||||||
|
* @param [y] {number} y position of the emitter.
|
||||||
|
* @param [size] {number} size of this emitter.
|
||||||
|
* @return {Emitter} The newly created emitter object.
|
||||||
|
*/
|
||||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||||
return <Emitter> this.group.add(new Emitter(this._game, x, y, size));
|
return <Emitter> this.group.add(new Emitter(this._game, x, y, size));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,17 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Creates a new <code>Emitter</code> object at a specific position.
|
* Creates a new <code>Emitter</code> object at a specific position.
|
||||||
* Does NOT automatically generate or attach particles!
|
* Does NOT automatically generate or attach particles!
|
||||||
*
|
*
|
||||||
* @param X The X position of the emitter.
|
* @param x {number} The X position of the emitter.
|
||||||
* @param Y The Y position of the emitter.
|
* @param y {number} The Y position of the emitter.
|
||||||
* @param Size Optional, specifies a maximum capacity for this emitter.
|
* @param [size] {number} Specifies a maximum capacity for this emitter.
|
||||||
*/
|
*/
|
||||||
constructor(game: Game, X: number = 0, Y: number = 0, Size: number = 0) {
|
constructor(game: Game, x: number = 0, y: number = 0, size: number = 0) {
|
||||||
super(game, Size);
|
|
||||||
this.x = X;
|
super(game, size);
|
||||||
this.y = Y;
|
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
this.minParticleSpeed = new MicroPoint(-100, -100);
|
this.minParticleSpeed = new MicroPoint(-100, -100);
|
||||||
@@ -42,6 +44,7 @@ module Phaser {
|
|||||||
this._explode = true;
|
this._explode = true;
|
||||||
this.on = false;
|
this.on = false;
|
||||||
this._point = new MicroPoint();
|
this._point = new MicroPoint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,24 +168,23 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function generates a new array of particle sprites to attach to the emitter.
|
* This function generates a new array of particle sprites to attach to the emitter.
|
||||||
*
|
*
|
||||||
* @param Graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet.
|
* @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet.
|
||||||
* @param Quantity The number of particles to generate when using the "create from image" option.
|
* @param quantity {number} The number of particles to generate when using the "create from image" option.
|
||||||
* @param BakedRotations How many frames of baked rotation to use (boosts performance). Set to zero to not use baked rotations.
|
* @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
|
||||||
* @param Multiple Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
|
* @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.
|
||||||
* @param Collide Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.
|
*
|
||||||
*
|
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
|
||||||
*/
|
*/
|
||||||
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0): Emitter {
|
public makeParticles(graphics, quantity: number = 50, multiple: bool = false, collide: number = 0): Emitter {
|
||||||
|
|
||||||
this.maxSize = Quantity;
|
this.maxSize = quantity;
|
||||||
|
|
||||||
var totalFrames: number = 1;
|
var totalFrames: number = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(Multiple)
|
if(Multiple)
|
||||||
{
|
{
|
||||||
var sprite:Sprite = new Sprite(this._game);
|
var sprite:Sprite = new Sprite(this._game);
|
||||||
sprite.loadGraphic(Graphics,true);
|
sprite.loadGraphic(Graphics,true);
|
||||||
totalFrames = sprite.frames;
|
totalFrames = sprite.frames;
|
||||||
@@ -194,7 +196,7 @@ module Phaser {
|
|||||||
var particle: Particle;
|
var particle: Particle;
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
|
|
||||||
while (i < Quantity)
|
while (i < quantity)
|
||||||
{
|
{
|
||||||
if (this.particleClass == null)
|
if (this.particleClass == null)
|
||||||
{
|
{
|
||||||
@@ -205,7 +207,7 @@ module Phaser {
|
|||||||
particle = new this.particleClass(this._game);
|
particle = new this.particleClass(this._game);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Multiple)
|
if (multiple)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
randomFrame = this._game.math.random()*totalFrames;
|
randomFrame = this._game.math.random()*totalFrames;
|
||||||
@@ -227,18 +229,18 @@ module Phaser {
|
|||||||
particle.loadGraphic(Graphics);
|
particle.loadGraphic(Graphics);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (Graphics)
|
if (graphics)
|
||||||
{
|
{
|
||||||
particle.loadGraphic(Graphics);
|
particle.loadGraphic(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Collide > 0)
|
if (collide > 0)
|
||||||
{
|
{
|
||||||
particle.allowCollisions = Collision.ANY;
|
particle.allowCollisions = Collision.ANY;
|
||||||
particle.width *= Collide;
|
particle.width *= collide;
|
||||||
particle.height *= Collide;
|
particle.height *= collide;
|
||||||
//particle.centerOffsets();
|
//particle.centerOffsets();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -318,23 +320,23 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this function to start emitting particles.
|
* Call this function to start emitting particles.
|
||||||
*
|
*
|
||||||
* @param Explode Whether the particles should all burst out at once.
|
* @param explode {boolean} Whether the particles should all burst out at once.
|
||||||
* @param Lifespan How long each particle lives once emitted. 0 = forever.
|
* @param lifespan {number} How long each particle lives once emitted. 0 = forever.
|
||||||
* @param Frequency Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds.
|
* @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds.
|
||||||
* @param Quantity How many particles to launch. 0 = "all of the particles".
|
* @param quantity {number} How many particles to launch. 0 = "all of the particles".
|
||||||
*/
|
*/
|
||||||
public start(Explode: bool = true, Lifespan: number = 0, Frequency: number = 0.1, Quantity: number = 0) {
|
public start(explode: bool = true, lifespan: number = 0, frequency: number = 0.1, quantity: number = 0) {
|
||||||
|
|
||||||
this.revive();
|
this.revive();
|
||||||
|
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
this.on = true;
|
this.on = true;
|
||||||
|
|
||||||
this._explode = Explode;
|
this._explode = explode;
|
||||||
this.lifespan = Lifespan;
|
this.lifespan = lifespan;
|
||||||
this.frequency = Frequency;
|
this.frequency = frequency;
|
||||||
this._quantity += Quantity;
|
this._quantity += quantity;
|
||||||
|
|
||||||
this._counter = 0;
|
this._counter = 0;
|
||||||
this._timer = 0;
|
this._timer = 0;
|
||||||
@@ -395,55 +397,55 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A more compact way of setting the width and height of the emitter.
|
* A more compact way of setting the width and height of the emitter.
|
||||||
*
|
*
|
||||||
* @param Width The desired width of the emitter (particles are spawned randomly within these dimensions).
|
* @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions).
|
||||||
* @param Height The desired height of the emitter.
|
* @param height {number} The desired height of the emitter.
|
||||||
*/
|
*/
|
||||||
public setSize(Width: number, Height: number) {
|
public setSize(width: number, height: number) {
|
||||||
this.width = Width;
|
this.width = width;
|
||||||
this.height = Height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A more compact way of setting the X velocity range of the emitter.
|
* A more compact way of setting the X velocity range of the emitter.
|
||||||
*
|
*
|
||||||
* @param Min The minimum value for this range.
|
* @param Min {number} The minimum value for this range.
|
||||||
* @param Max The maximum value for this range.
|
* @param Max {number} The maximum value for this range.
|
||||||
*/
|
*/
|
||||||
public setXSpeed(Min: number = 0, Max: number = 0) {
|
public setXSpeed(min: number = 0, max: number = 0) {
|
||||||
this.minParticleSpeed.x = Min;
|
this.minParticleSpeed.x = min;
|
||||||
this.maxParticleSpeed.x = Max;
|
this.maxParticleSpeed.x = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A more compact way of setting the Y velocity range of the emitter.
|
* A more compact way of setting the Y velocity range of the emitter.
|
||||||
*
|
*
|
||||||
* @param Min The minimum value for this range.
|
* @param Min {number} The minimum value for this range.
|
||||||
* @param Max The maximum value for this range.
|
* @param Max {number} The maximum value for this range.
|
||||||
*/
|
*/
|
||||||
public setYSpeed(Min: number = 0, Max: number = 0) {
|
public setYSpeed(min: number = 0, max: number = 0) {
|
||||||
this.minParticleSpeed.y = Min;
|
this.minParticleSpeed.y = min;
|
||||||
this.maxParticleSpeed.y = Max;
|
this.maxParticleSpeed.y = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A more compact way of setting the angular velocity constraints of the emitter.
|
* A more compact way of setting the angular velocity constraints of the emitter.
|
||||||
*
|
*
|
||||||
* @param Min The minimum value for this range.
|
* @param Min {number} The minimum value for this range.
|
||||||
* @param Max The maximum value for this range.
|
* @param Max {number} The maximum value for this range.
|
||||||
*/
|
*/
|
||||||
public setRotation(Min: number = 0, Max: number = 0) {
|
public setRotation(min: number = 0, max: number = 0) {
|
||||||
this.minRotation = Min;
|
this.minRotation = min;
|
||||||
this.maxRotation = Max;
|
this.maxRotation = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the emitter's midpoint to match the midpoint of a <code>Object</code>.
|
* Change the emitter's midpoint to match the midpoint of a <code>Object</code>.
|
||||||
*
|
*
|
||||||
* @param Object The <code>Object</code> that you want to sync up with.
|
* @param Object {object} The <code>Object</code> that you want to sync up with.
|
||||||
*/
|
*/
|
||||||
public at(Object) {
|
public at(object) {
|
||||||
Object.getMidpoint(this._point);
|
object.getMidpoint(this._point);
|
||||||
this.x = this._point.x - (this.width >> 1);
|
this.x = this._point.x - (this.width >> 1);
|
||||||
this.y = this._point.y - (this.height >> 1);
|
this.y = this._point.y - (this.height >> 1);
|
||||||
}
|
}
|
||||||
|
|||||||
+429
-132
@@ -1,6 +1,7 @@
|
|||||||
/// <reference path="../Game.ts" />
|
/// <reference path="../Game.ts" />
|
||||||
/// <reference path="../Basic.ts" />
|
/// <reference path="../Basic.ts" />
|
||||||
/// <reference path="../Signal.ts" />
|
/// <reference path="../Signal.ts" />
|
||||||
|
/// <reference path="../system/CollisionMask.ts" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phaser - GameObject
|
* Phaser - GameObject
|
||||||
@@ -13,11 +14,24 @@ module Phaser {
|
|||||||
|
|
||||||
export class GameObject extends Basic {
|
export class GameObject extends Basic {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameObject constructor
|
||||||
|
*
|
||||||
|
* Create a new <code>GameObject</code> object at specific position with specific width and height.
|
||||||
|
*
|
||||||
|
* @param [x] {number} The x position of the object.
|
||||||
|
* @param [y] {number} The y position of the object.
|
||||||
|
* @param [width] {number} The width of the object.
|
||||||
|
* @param [height] {number} The height of the object.
|
||||||
|
*/
|
||||||
constructor(game: Game, x?: number = 0, y?: number = 0, width?: number = 16, height?: number = 16) {
|
constructor(game: Game, x?: number = 0, y?: number = 0, width?: number = 16, height?: number = 16) {
|
||||||
|
|
||||||
super(game);
|
super(game);
|
||||||
|
|
||||||
this.bounds = new Rectangle(x, y, width, height);
|
this.canvas = game.stage.canvas;
|
||||||
|
this.context = game.stage.context;
|
||||||
|
|
||||||
|
this.frameBounds = new Rectangle(x, y, width, height);
|
||||||
this.exists = true;
|
this.exists = true;
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
@@ -27,7 +41,6 @@ module Phaser {
|
|||||||
this.scale = new MicroPoint(1, 1);
|
this.scale = new MicroPoint(1, 1);
|
||||||
|
|
||||||
this.last = new MicroPoint(x, y);
|
this.last = new MicroPoint(x, y);
|
||||||
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
|
|
||||||
this.align = GameObject.ALIGN_TOP_LEFT;
|
this.align = GameObject.ALIGN_TOP_LEFT;
|
||||||
this.mass = 1;
|
this.mass = 1;
|
||||||
this.elasticity = 0;
|
this.elasticity = 0;
|
||||||
@@ -53,69 +66,302 @@ module Phaser {
|
|||||||
|
|
||||||
this.cameraBlacklist = [];
|
this.cameraBlacklist = [];
|
||||||
this.scrollFactor = new MicroPoint(1, 1);
|
this.scrollFactor = new MicroPoint(1, 1);
|
||||||
|
this.collisionMask = new CollisionMask(game, this, x, y, width, height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Angle of this object.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _angle: number = 0;
|
private _angle: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the top-left corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_TOP_LEFT: number = 0;
|
public static ALIGN_TOP_LEFT: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the top-center corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_TOP_CENTER: number = 1;
|
public static ALIGN_TOP_CENTER: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the top-right corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_TOP_RIGHT: number = 2;
|
public static ALIGN_TOP_RIGHT: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the center-left corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_CENTER_LEFT: number = 3;
|
public static ALIGN_CENTER_LEFT: number = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the center corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_CENTER: number = 4;
|
public static ALIGN_CENTER: number = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the center-right corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_CENTER_RIGHT: number = 5;
|
public static ALIGN_CENTER_RIGHT: number = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the bottom-left corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_BOTTOM_LEFT: number = 6;
|
public static ALIGN_BOTTOM_LEFT: number = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the bottom-center corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_BOTTOM_CENTER: number = 7;
|
public static ALIGN_BOTTOM_CENTER: number = 7;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pivot position enum: at the bottom-right corner.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static ALIGN_BOTTOM_RIGHT: number = 8;
|
public static ALIGN_BOTTOM_RIGHT: number = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum value for outOfBoundsAction. Stop the object when is out of world bounds.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static OUT_OF_BOUNDS_STOP: number = 0;
|
public static OUT_OF_BOUNDS_STOP: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum value for outOfBoundsAction. Kill the object when is out of world bounds.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static OUT_OF_BOUNDS_KILL: number = 1;
|
public static OUT_OF_BOUNDS_KILL: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the Canvas this GameObject will render to
|
||||||
|
* @type {HTMLCanvasElement}
|
||||||
|
*/
|
||||||
|
public canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the Canvas Context2D this GameObject will render to
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
|
public context: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Position of this object after scrolling.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public _point: MicroPoint;
|
public _point: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Array of Cameras to which this GameObject won't render
|
||||||
|
* @type {Array}
|
||||||
|
*/
|
||||||
public cameraBlacklist: number[];
|
public cameraBlacklist: number[];
|
||||||
public bounds: Rectangle;
|
|
||||||
|
/**
|
||||||
|
* Rectangle container of this object.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
|
public frameBounds: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This objects CollisionMask
|
||||||
|
* @type {CollisionMask}
|
||||||
|
*/
|
||||||
|
public collisionMask: CollisionMask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A rectangular area which is object is allowed to exist within. If it travels outside of this area it will perform the outOfBoundsAction.
|
||||||
|
* @type {Quad}
|
||||||
|
*/
|
||||||
public worldBounds: Quad;
|
public worldBounds: Quad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What action will be performed when object is out of the worldBounds.
|
||||||
|
* This will default to GameObject.OUT_OF_BOUNDS_STOP.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public outOfBoundsAction: number = 0;
|
public outOfBoundsAction: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* At which point the graphic of this object will align to.
|
||||||
|
* Align of the object will default to GameObject.ALIGN_TOP_LEFT.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public align: number;
|
public align: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orientation of the object.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public facing: number;
|
public facing: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set alpha to a number between 0 and 1 to change the opacity.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public alpha: number;
|
public alpha: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale factor of the object.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public scale: MicroPoint;
|
public scale: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Origin is the anchor point that the object will rotate by.
|
||||||
|
* The origin will default to its center.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public origin: MicroPoint;
|
public origin: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Z-order value of the object.
|
||||||
|
*/
|
||||||
public z: number = 0;
|
public z: number = 0;
|
||||||
|
|
||||||
// This value is added to the angle of the GameObject.
|
/**
|
||||||
// For example if you had a sprite drawn facing straight up then you could set
|
* This value is added to the angle of the GameObject.
|
||||||
// rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
* For example if you had a sprite drawn facing straight up then you could set
|
||||||
|
* rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public rotationOffset: number = 0;
|
public rotationOffset: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls if the GameObject is rendered rotated or not.
|
||||||
|
* If renderRotation is false then the object can still rotate but it will never be rendered rotated.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public renderRotation: bool = true;
|
public renderRotation: bool = true;
|
||||||
|
|
||||||
// Physics properties
|
// Physics properties
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this object will be moved by impacts with other objects or not.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public immovable: bool;
|
public immovable: bool;
|
||||||
|
|
||||||
// Velocity is given in pixels per second. Therefore a velocity of
|
/**
|
||||||
// 100 will move at a rate of 100 pixels every 1000 ms (1sec). It's not balls-on
|
* Basic speed of this object.
|
||||||
// accurate due to the way timers work, but it's pretty close. Expect tolerance
|
*
|
||||||
// of +- 10 px. Also that speed assumes no drag
|
* Velocity is given in pixels per second. Therefore a velocity of
|
||||||
|
* 100 will move at a rate of 100 pixels every 1000 ms (1sec). It's not balls-on
|
||||||
|
* accurate due to the way timers work, but it's pretty close. Expect tolerance
|
||||||
|
* of +- 10 px. Also that speed assumes no drag.
|
||||||
|
*
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public velocity: MicroPoint;
|
public velocity: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The virtual mass of the object.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public mass: number;
|
public mass: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bounciness of the object.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public elasticity: number;
|
public elasticity: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How fast the speed of this object is changing.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public acceleration: MicroPoint;
|
public acceleration: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This isn't drag exactly, more like deceleration that is only applied
|
||||||
|
* when acceleration is not affecting the sprite.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public drag: MicroPoint;
|
public drag: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It will cap the speed automatically if you use the acceleration
|
||||||
|
* to change its velocity.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public maxVelocity: MicroPoint;
|
public maxVelocity: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How fast this object is rotating.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public angularVelocity: number;
|
public angularVelocity: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How fast angularVelocity of this object is changing.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public angularAcceleration: number;
|
public angularAcceleration: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deacceleration of angularVelocity will be applied when it's rotating.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public angularDrag: number;
|
public angularDrag: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It will cap the rotate speed automatically if you use the angularAcceleration
|
||||||
|
* to change its angularVelocity.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public maxAngular: number;
|
public maxAngular: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A point that can store numbers from 0 to 1 (for X and Y independently)
|
||||||
|
* which governs how much this object is affected by the camera .
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public scrollFactor: MicroPoint;
|
public scrollFactor: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handy for storing health percentage or armor points or whatever.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public health: number;
|
public health: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this to false if you want to skip the automatic motion/movement stuff
|
||||||
|
* (see updateMotion()).
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public moves: bool = true;
|
public moves: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public touching: number;
|
public touching: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public wasTouching: number;
|
public wasTouching: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public allowCollisions: number;
|
public allowCollisions: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Important variable for collision processing.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public last: MicroPoint;
|
public last: MicroPoint;
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
@@ -127,18 +373,27 @@ module Phaser {
|
|||||||
public onInputDown: Phaser.Signal;
|
public onInputDown: Phaser.Signal;
|
||||||
public onInputUp: Phaser.Signal;
|
public onInputUp: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-update is called right before update() on each object in the game loop.
|
||||||
|
*/
|
||||||
public preUpdate() {
|
public preUpdate() {
|
||||||
|
|
||||||
// flicker time
|
this.last.x = this.frameBounds.x;
|
||||||
|
this.last.y = this.frameBounds.y;
|
||||||
|
|
||||||
this.last.x = this.bounds.x;
|
this.collisionMask.preUpdate();
|
||||||
this.last.y = this.bounds.y;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override this function to update your class's position and appearance.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically called after update() by the game loop.
|
||||||
|
*/
|
||||||
public postUpdate() {
|
public postUpdate() {
|
||||||
|
|
||||||
if (this.moves)
|
if (this.moves)
|
||||||
@@ -176,6 +431,8 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.collisionMask.update();
|
||||||
|
|
||||||
if (this.inputEnabled)
|
if (this.inputEnabled)
|
||||||
{
|
{
|
||||||
@@ -187,9 +444,15 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update input.
|
||||||
|
*/
|
||||||
private updateInput() {
|
private updateInput() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function for updating the position and speed of this object.
|
||||||
|
*/
|
||||||
private updateMotion() {
|
private updateMotion() {
|
||||||
|
|
||||||
var delta: number;
|
var delta: number;
|
||||||
@@ -204,13 +467,13 @@ module Phaser {
|
|||||||
this.velocity.x += velocityDelta;
|
this.velocity.x += velocityDelta;
|
||||||
delta = this.velocity.x * this._game.time.elapsed;
|
delta = this.velocity.x * this._game.time.elapsed;
|
||||||
this.velocity.x += velocityDelta;
|
this.velocity.x += velocityDelta;
|
||||||
this.bounds.x += delta;
|
this.frameBounds.x += delta;
|
||||||
|
|
||||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
||||||
this.velocity.y += velocityDelta;
|
this.velocity.y += velocityDelta;
|
||||||
delta = this.velocity.y * this._game.time.elapsed;
|
delta = this.velocity.y * this._game.time.elapsed;
|
||||||
this.velocity.y += velocityDelta;
|
this.velocity.y += velocityDelta;
|
||||||
this.bounds.y += delta;
|
this.frameBounds.y += delta;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,24 +481,24 @@ module Phaser {
|
|||||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
|
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
|
||||||
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
|
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
|
||||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||||
*
|
*
|
||||||
* @param ObjectOrGroup The object or group being tested.
|
* @param objectOrGroup {object} The object or group being tested.
|
||||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
* @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 Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||||
*
|
*
|
||||||
* @return Whether or not the two objects overlap.
|
* @return {boolean} Whether or not the objects overlap this.
|
||||||
*/
|
*/
|
||||||
public overlaps(ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
public overlaps(objectOrGroup, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||||
|
|
||||||
if (ObjectOrGroup.isGroup)
|
if (objectOrGroup.isGroup)
|
||||||
{
|
{
|
||||||
var results: bool = false;
|
var results: bool = false;
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
var members = <Group> ObjectOrGroup.members;
|
var members = <Group> objectOrGroup.members;
|
||||||
|
|
||||||
while (i < length)
|
while (i < length)
|
||||||
{
|
{
|
||||||
if (this.overlaps(members[i++], InScreenSpace, Camera))
|
if (this.overlaps(members[i++], inScreenSpace, camera))
|
||||||
{
|
{
|
||||||
results = true;
|
results = true;
|
||||||
}
|
}
|
||||||
@@ -245,50 +508,50 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!InScreenSpace)
|
if (!inScreenSpace)
|
||||||
{
|
{
|
||||||
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
return (objectOrGroup.x + objectOrGroup.width > this.x) && (objectOrGroup.x < this.x + this.width) &&
|
||||||
(ObjectOrGroup.y + ObjectOrGroup.height > this.y) && (ObjectOrGroup.y < this.y + this.height);
|
(objectOrGroup.y + objectOrGroup.height > this.y) && (objectOrGroup.y < this.y + this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Camera == null)
|
if (camera == null)
|
||||||
{
|
{
|
||||||
Camera = this._game.camera;
|
camera = this._game.camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
var objectScreenPos: Point = objectOrGroup.getScreenXY(null, camera);
|
||||||
|
|
||||||
this.getScreenXY(this._point, Camera);
|
this.getScreenXY(this._point, camera);
|
||||||
|
|
||||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
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);
|
(objectScreenPos.y + objectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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>?
|
* 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.
|
* 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!
|
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||||
*
|
*
|
||||||
* @param X The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
* @param X {number} The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||||
* @param Y The Y 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 The object or group being tested.
|
* @param objectOrGroup {object} The object or group being tested.
|
||||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
* @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 Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||||
*
|
*
|
||||||
* @return Whether or not the two objects overlap.
|
* @return {boolean} Whether or not the two objects overlap.
|
||||||
*/
|
*/
|
||||||
public overlapsAt(X: number, Y: number, ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
public overlapsAt(X: number, Y: number, objectOrGroup, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||||
|
|
||||||
if (ObjectOrGroup.isGroup)
|
if (objectOrGroup.isGroup)
|
||||||
{
|
{
|
||||||
var results: bool = false;
|
var results: bool = false;
|
||||||
var basic;
|
var basic;
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
var members = ObjectOrGroup.members;
|
var members = objectOrGroup.members;
|
||||||
|
|
||||||
while (i < length)
|
while (i < length)
|
||||||
{
|
{
|
||||||
if (this.overlapsAt(X, Y, members[i++], InScreenSpace, Camera))
|
if (this.overlapsAt(X, Y, members[i++], inScreenSpace, camera))
|
||||||
{
|
{
|
||||||
results = true;
|
results = true;
|
||||||
}
|
}
|
||||||
@@ -297,53 +560,53 @@ module Phaser {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!InScreenSpace)
|
if (!inScreenSpace)
|
||||||
{
|
{
|
||||||
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
return (objectOrGroup.x + objectOrGroup.width > X) && (objectOrGroup.x < X + this.width) &&
|
||||||
(ObjectOrGroup.y + ObjectOrGroup.height > Y) && (ObjectOrGroup.y < Y + this.height);
|
(objectOrGroup.y + objectOrGroup.height > Y) && (objectOrGroup.y < Y + this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Camera == null)
|
if (camera == null)
|
||||||
{
|
{
|
||||||
Camera = this._game.camera;
|
camera = this._game.camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
var objectScreenPos: Point = objectOrGroup.getScreenXY(null, Camera);
|
||||||
|
|
||||||
this._point.x = X - Camera.scroll.x * this.scrollFactor.x; //copied from getScreenXY()
|
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.y = Y - camera.scroll.y * this.scrollFactor.y;
|
||||||
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
|
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
|
||||||
this._point.y += (this._point.y > 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) &&
|
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);
|
(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 a point in 2D world space overlaps this <code>GameObject</code>.
|
||||||
*
|
*
|
||||||
* @param Point The point in world space you want to check.
|
* @param point {Point} The point in world space you want to check.
|
||||||
* @param InScreenSpace Whether to take scroll factors into account when checking for overlap.
|
* @param inScreenSpace {boolean} Whether to take scroll factors into account when checking for overlap.
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||||
*
|
*
|
||||||
* @return Whether or not the point overlaps this object.
|
* @return Whether or not the point overlaps this object.
|
||||||
*/
|
*/
|
||||||
public overlapsPoint(point: Point, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
public overlapsPoint(point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
|
||||||
|
|
||||||
if (!InScreenSpace)
|
if (!inScreenSpace)
|
||||||
{
|
{
|
||||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Camera == null)
|
if (camera == null)
|
||||||
{
|
{
|
||||||
Camera = this._game.camera;
|
camera = this._game.camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
var X: number = point.x - Camera.scroll.x;
|
var X: number = point.x - camera.scroll.x;
|
||||||
var Y: number = point.y - Camera.scroll.y;
|
var Y: number = point.y - camera.scroll.y;
|
||||||
|
|
||||||
this.getScreenXY(this._point, Camera);
|
this.getScreenXY(this._point, camera);
|
||||||
|
|
||||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||||
|
|
||||||
@@ -351,46 +614,46 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check and see if this object is currently on screen.
|
* Check and see if this object is currently on screen.
|
||||||
*
|
*
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||||
*
|
*
|
||||||
* @return Whether the object is on screen or not.
|
* @return {boolean} Whether the object is on screen or not.
|
||||||
*/
|
*/
|
||||||
public onScreen(Camera: Camera = null): bool {
|
public onScreen(camera: Camera = null): bool {
|
||||||
|
|
||||||
if (Camera == null)
|
if (camera == null)
|
||||||
{
|
{
|
||||||
Camera = this._game.camera;
|
camera = this._game.camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getScreenXY(this._point, Camera);
|
this.getScreenXY(this._point, camera);
|
||||||
|
|
||||||
return (this._point.x + this.width > 0) && (this._point.x < Camera.width) && (this._point.y + this.height > 0) && (this._point.y < Camera.height);
|
return (this._point.x + this.width > 0) && (this._point.x < camera.width) && (this._point.y + this.height > 0) && (this._point.y < camera.height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this to figure out the on-screen position of the object.
|
* Call this to figure out the on-screen position of the object.
|
||||||
*
|
*
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
* @param point {Point} Takes a <code>MicroPoint</code> object and assigns the post-scrolled X and Y values of this object to it.
|
||||||
* @param Point Takes a <code>MicroPoint</code> object and assigns the post-scrolled X and Y values of this object to it.
|
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||||
*
|
*
|
||||||
* @return The <code>MicroPoint</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
|
* @return {MicroPoint} The <code>MicroPoint</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
|
||||||
*/
|
*/
|
||||||
public getScreenXY(point: MicroPoint = null, Camera: Camera = null): MicroPoint {
|
public getScreenXY(point: MicroPoint = null, camera: Camera = null): MicroPoint {
|
||||||
|
|
||||||
if (point == null)
|
if (point == null)
|
||||||
{
|
{
|
||||||
point = new MicroPoint();
|
point = new MicroPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Camera == null)
|
if (camera == null)
|
||||||
{
|
{
|
||||||
Camera = this._game.camera;
|
camera = this._game.camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
point.x = this.x - Camera.scroll.x * this.scrollFactor.x;
|
point.x = this.x - camera.scroll.x * this.scrollFactor.x;
|
||||||
point.y = this.y - Camera.scroll.y * this.scrollFactor.y;
|
point.y = this.y - camera.scroll.y * this.scrollFactor.y;
|
||||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||||
|
|
||||||
@@ -407,12 +670,9 @@ module Phaser {
|
|||||||
return (this.allowCollisions & Collision.ANY) > Collision.NONE;
|
return (this.allowCollisions & Collision.ANY) > Collision.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public set solid(value: bool) {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
public set solid(Solid: bool) {
|
|
||||||
|
|
||||||
if (Solid)
|
if (value)
|
||||||
{
|
{
|
||||||
this.allowCollisions = Collision.ANY;
|
this.allowCollisions = Collision.ANY;
|
||||||
}
|
}
|
||||||
@@ -425,10 +685,10 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the midpoint of this object in world coordinates.
|
* Retrieve the midpoint of this object in world coordinates.
|
||||||
*
|
*
|
||||||
* @Point Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
|
* @param point {Point} Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
|
||||||
*
|
*
|
||||||
* @return A <code>Point</code> object containing the midpoint of this object in world coordinates.
|
* @return {MicroPoint} A <code>Point</code> object containing the midpoint of this object in world coordinates.
|
||||||
*/
|
*/
|
||||||
public getMidpoint(point: MicroPoint = null): MicroPoint {
|
public getMidpoint(point: MicroPoint = null): MicroPoint {
|
||||||
|
|
||||||
@@ -437,7 +697,7 @@ module Phaser {
|
|||||||
point = new MicroPoint();
|
point = new MicroPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
point.copyFrom(this.bounds.center);
|
point.copyFrom(this.frameBounds.center);
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
|
|
||||||
@@ -446,19 +706,19 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Handy for reviving game objects.
|
* Handy for reviving game objects.
|
||||||
* Resets their existence flags and position.
|
* Resets their existence flags and position.
|
||||||
*
|
*
|
||||||
* @param X The new X position of this object.
|
* @param x {number} The new X position of this object.
|
||||||
* @param Y The new Y position of this object.
|
* @param y {number} The new Y position of this object.
|
||||||
*/
|
*/
|
||||||
public reset(X: number, Y: number) {
|
public reset(x: number, y: number) {
|
||||||
|
|
||||||
this.revive();
|
this.revive();
|
||||||
this.touching = Collision.NONE;
|
this.touching = Collision.NONE;
|
||||||
this.wasTouching = Collision.NONE;
|
this.wasTouching = Collision.NONE;
|
||||||
this.x = X;
|
this.x = x;
|
||||||
this.y = Y;
|
this.y = y;
|
||||||
this.last.x = X;
|
this.last.x = x;
|
||||||
this.last.y = Y;
|
this.last.y = y;
|
||||||
this.velocity.x = 0;
|
this.velocity.x = 0;
|
||||||
this.velocity.y = 0;
|
this.velocity.y = 0;
|
||||||
|
|
||||||
@@ -466,37 +726,37 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handy for checking if this object is touching a particular surface.
|
* Handy for checking if this object is touching a particular surface.
|
||||||
* For slightly better performance you can just & the value directly numbero <code>touching</code>.
|
* For slightly better performance you can just & the value directly into <code>touching</code>.
|
||||||
* However, this method is good for readability and accessibility.
|
* However, this method is good for readability and accessibility.
|
||||||
*
|
*
|
||||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
* @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||||
*
|
*
|
||||||
* @return Whether the object is touching an object in (any of) the specified direction(s) this frame.
|
* @return {boolean} Whether the object is touching an object in (any of) the specified direction(s) this frame.
|
||||||
*/
|
*/
|
||||||
public isTouching(Direction: number): bool {
|
public isTouching(direction: number): bool {
|
||||||
return (this.touching & Direction) > Collision.NONE;
|
return (this.touching & direction) > Collision.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handy for checking if this object is just landed on a particular surface.
|
* Handy function for checking if this object just landed on a particular surface.
|
||||||
*
|
*
|
||||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
* @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||||
*
|
*
|
||||||
* @return Whether the object just landed on (any of) the specified surface(s) this frame.
|
* @returns {boolean} Whether the object just landed on any specicied surfaces.
|
||||||
*/
|
*/
|
||||||
public justTouched(Direction: number): bool {
|
public justTouched(direction: number): bool {
|
||||||
return ((this.touching & Direction) > Collision.NONE) && ((this.wasTouching & Direction) <= Collision.NONE);
|
return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reduces the "health" variable of this sprite by the amount specified in Damage.
|
* Reduces the "health" variable of this sprite by the amount specified in Damage.
|
||||||
* Calls kill() if health drops to or below zero.
|
* Calls kill() if health drops to or below zero.
|
||||||
*
|
*
|
||||||
* @param Damage How much health to take away (use a negative number to give a health bonus).
|
* @param Damage {number} How much health to take away (use a negative number to give a health bonus).
|
||||||
*/
|
*/
|
||||||
public hurt(Damage: number) {
|
public hurt(damage: number) {
|
||||||
|
|
||||||
this.health = this.health - Damage;
|
this.health = this.health - damage;
|
||||||
|
|
||||||
if (this.health <= 0)
|
if (this.health <= 0)
|
||||||
{
|
{
|
||||||
@@ -509,6 +769,11 @@ module Phaser {
|
|||||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
* 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)
|
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
||||||
* it can be stopped from leaving the world, or a section of it.
|
* it can be stopped from leaving the world, or a section of it.
|
||||||
|
*
|
||||||
|
* @param x {number} x position of the bound
|
||||||
|
* @param y {number} y position of the bound
|
||||||
|
* @param width {number} width of its bound
|
||||||
|
* @param height {number} height of its bound
|
||||||
*/
|
*/
|
||||||
public setBounds(x: number, y: number, width: number, height: number) {
|
public setBounds(x: number, y: number, width: number, height: number) {
|
||||||
|
|
||||||
@@ -516,8 +781,22 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
|
||||||
|
*
|
||||||
|
* @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
|
||||||
|
*/
|
||||||
|
public setBoundsFromWorld(action?: number = GameObject.OUT_OF_BOUNDS_STOP) {
|
||||||
|
|
||||||
|
this.setBounds(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
|
||||||
|
this.outOfBoundsAction = action;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If you do not wish this object to be visible to a specific camera, pass the camera here.
|
* If you do not wish this object to be visible to a specific camera, pass the camera here.
|
||||||
|
*
|
||||||
|
* @param camera {Camera} The specific camera.
|
||||||
*/
|
*/
|
||||||
public hideFromCamera(camera: Camera) {
|
public hideFromCamera(camera: Camera) {
|
||||||
|
|
||||||
@@ -528,6 +807,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make this object only visible to a specific camera.
|
||||||
|
*
|
||||||
|
* @param camera {Camera} The camera you wish it to be visible.
|
||||||
|
*/
|
||||||
public showToCamera(camera: Camera) {
|
public showToCamera(camera: Camera) {
|
||||||
|
|
||||||
if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
|
if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
|
||||||
@@ -537,30 +822,42 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This clears the camera black list, making the GameObject visible to all cameras.
|
||||||
|
*/
|
||||||
public clearCameraList() {
|
public clearCameraList() {
|
||||||
|
|
||||||
this.cameraBlacklist.length = 0;
|
this.cameraBlacklist.length = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up memory.
|
||||||
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public setPosition(x: number, y: number) {
|
||||||
|
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get x(): number {
|
public get x(): number {
|
||||||
return this.bounds.x;
|
return this.frameBounds.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set x(value: number) {
|
public set x(value: number) {
|
||||||
this.bounds.x = value;
|
this.frameBounds.x = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get y(): number {
|
public get y(): number {
|
||||||
return this.bounds.y;
|
return this.frameBounds.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set y(value: number) {
|
public set y(value: number) {
|
||||||
this.bounds.y = value;
|
this.frameBounds.y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get rotation(): number {
|
public get rotation(): number {
|
||||||
@@ -580,19 +877,19 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public set width(value:number) {
|
public set width(value:number) {
|
||||||
this.bounds.width = value;
|
this.frameBounds.width = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set height(value:number) {
|
public set height(value:number) {
|
||||||
this.bounds.height = value;
|
this.frameBounds.height = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get width(): number {
|
public get width(): number {
|
||||||
return this.bounds.width;
|
return this.frameBounds.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get height(): number {
|
public get height(): number {
|
||||||
return this.bounds.height;
|
return this.frameBounds.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/// <reference path="../Game.ts" />
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="../geom/Polygon.ts" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phaser - GeomSprite
|
* Phaser - GeomSprite
|
||||||
@@ -12,6 +13,14 @@ module Phaser {
|
|||||||
|
|
||||||
export class GeomSprite extends GameObject {
|
export class GeomSprite extends GameObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GeomSprite constructor
|
||||||
|
* Create a new <code>GeomSprite</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param [x] {number} the initial x position of the sprite.
|
||||||
|
* @param [y] {number} the initial y position of the sprite.
|
||||||
|
*/
|
||||||
constructor(game: Game, x?: number = 0, y?: number = 0) {
|
constructor(game: Game, x?: number = 0, y?: number = 0) {
|
||||||
|
|
||||||
super(game, x, y);
|
super(game, x, y);
|
||||||
@@ -28,26 +37,112 @@ module Phaser {
|
|||||||
private _dw: number = 0;
|
private _dw: number = 0;
|
||||||
private _dh: number = 0;
|
private _dh: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Geom type of this sprite. (available: UNASSIGNED, CIRCLE, LINE, POINT, RECTANGLE)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public type: number = 0;
|
public type: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not completely set yet. (the default type)
|
||||||
|
*/
|
||||||
public static UNASSIGNED: number = 0;
|
public static UNASSIGNED: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Circle.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static CIRCLE: number = 1;
|
public static CIRCLE: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Line.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static LINE: number = 2;
|
public static LINE: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static POINT: number = 3;
|
public static POINT: number = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rectangle.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static RECTANGLE: number = 4;
|
public static RECTANGLE: number = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polygon.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static POLYGON: number = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Circle shape container. A Circle instance.
|
||||||
|
* @type {Circle}
|
||||||
|
*/
|
||||||
public circle: Circle;
|
public circle: Circle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Line shape container. A Line instance.
|
||||||
|
* @type {Line}
|
||||||
|
*/
|
||||||
public line: Line;
|
public line: Line;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point shape container. A Point instance.
|
||||||
|
* @type {Point}
|
||||||
|
*/
|
||||||
public point: Point;
|
public point: Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rectangle shape container. A Rectangle instance.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public rect: Rectangle;
|
public rect: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polygon shape container. A Polygon instance.
|
||||||
|
* @type {Polygon}
|
||||||
|
*/
|
||||||
|
public polygon: Polygon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render outline of this sprite or not. (default is true)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public renderOutline: bool = true;
|
public renderOutline: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill the shape or not. (default is true)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public renderFill: bool = true;
|
public renderFill: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of outline. (default is 1)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public lineWidth: number = 1;
|
public lineWidth: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of outline. (default is 1)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public lineColor: string = 'rgb(0,255,0)';
|
public lineColor: string = 'rgb(0,255,0)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color of the filled area in rgb or rgba string format
|
||||||
|
* @type {string} Defaults to rgb(0,100,0) - a green color
|
||||||
|
*/
|
||||||
public fillColor: string = 'rgb(0,100,0)';
|
public fillColor: string = 'rgb(0,100,0)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just like Sprite.loadGraphic(), this will load a circle and set its shape to Circle.
|
||||||
|
* @param circle {Circle} Circle geometry define.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
loadCircle(circle:Circle): GeomSprite {
|
loadCircle(circle:Circle): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
@@ -57,7 +152,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just like Sprite.loadGraphic(), this will load a line and set its shape to Line.
|
||||||
|
* @param line {Line} Line geometry define.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
loadLine(line:Line): GeomSprite {
|
loadLine(line:Line): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
@@ -67,6 +166,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just like Sprite.loadGraphic(), this will load a point and set its shape to Point.
|
||||||
|
* @param point {Point} Point geometry define.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
loadPoint(point:Point): GeomSprite {
|
loadPoint(point:Point): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
@@ -76,6 +180,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just like Sprite.loadGraphic(), this will load a rect and set its shape to Rectangle.
|
||||||
|
* @param rect {Rectangle} Rectangle geometry define.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
loadRectangle(rect:Rectangle): GeomSprite {
|
loadRectangle(rect:Rectangle): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
@@ -85,47 +194,87 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a circle shape with specific diameter.
|
||||||
|
* @param diameter {number} Diameter of the circle.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
createCircle(diameter: number): GeomSprite {
|
createCircle(diameter: number): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.circle = new Circle(this.x, this.y, diameter);
|
this.circle = new Circle(this.x, this.y, diameter);
|
||||||
this.type = GeomSprite.CIRCLE;
|
this.type = GeomSprite.CIRCLE;
|
||||||
this.bounds.setTo(this.circle.x - this.circle.radius, this.circle.y - this.circle.radius, this.circle.diameter, this.circle.diameter);
|
this.frameBounds.setTo(this.circle.x - this.circle.radius, this.circle.y - this.circle.radius, this.circle.diameter, this.circle.diameter);
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a line shape with specific end point.
|
||||||
|
* @param x {number} X position of the end point.
|
||||||
|
* @param y {number} Y position of the end point.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
createLine(x: number, y: number): GeomSprite {
|
createLine(x: number, y: number): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.line = new Line(this.x, this.y, x, y);
|
this.line = new Line(this.x, this.y, x, y);
|
||||||
this.type = GeomSprite.LINE;
|
this.type = GeomSprite.LINE;
|
||||||
this.bounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a point shape at spriter's position.
|
||||||
|
* @return {GeomSprite} GeomSprite instance itself.
|
||||||
|
*/
|
||||||
createPoint(): GeomSprite {
|
createPoint(): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.point = new Point(this.x, this.y);
|
this.point = new Point(this.x, this.y);
|
||||||
this.type = GeomSprite.POINT;
|
this.type = GeomSprite.POINT;
|
||||||
this.bounds.width = 1;
|
this.frameBounds.width = 1;
|
||||||
this.bounds.height = 1;
|
this.frameBounds.height = 1;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a rectangle shape of the given width and height size
|
||||||
|
* @param width {Number} Width of the rectangle
|
||||||
|
* @param height {Number} Height of the rectangle
|
||||||
|
* @return {GeomSprite} GeomSprite instance.
|
||||||
|
*/
|
||||||
createRectangle(width: number, height: number): GeomSprite {
|
createRectangle(width: number, height: number): GeomSprite {
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.rect = new Rectangle(this.x, this.y, width, height);
|
this.rect = new Rectangle(this.x, this.y, width, height);
|
||||||
this.type = GeomSprite.RECTANGLE;
|
this.type = GeomSprite.RECTANGLE;
|
||||||
this.bounds.copyFrom(this.rect);
|
this.frameBounds.copyFrom(this.rect);
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a polygon object
|
||||||
|
* @param width {Number} Width of the rectangle
|
||||||
|
* @param height {Number} Height of the rectangle
|
||||||
|
* @return {GeomSprite} GeomSprite instance.
|
||||||
|
*/
|
||||||
|
createPolygon(points?: Vector2[] = []): GeomSprite {
|
||||||
|
|
||||||
|
this.refresh();
|
||||||
|
this.polygon = new Polygon(new Vector2(this.x, this.y), points);
|
||||||
|
this.type = GeomSprite.POLYGON;
|
||||||
|
//this.frameBounds.copyFrom(this.rect);
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy all geom shapes of this sprite.
|
||||||
|
*/
|
||||||
refresh() {
|
refresh() {
|
||||||
|
|
||||||
this.circle = null;
|
this.circle = null;
|
||||||
@@ -135,6 +284,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update bounds.
|
||||||
|
*/
|
||||||
update() {
|
update() {
|
||||||
|
|
||||||
// Update bounds and position?
|
// Update bounds and position?
|
||||||
@@ -146,14 +298,14 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
this.circle.x = this.x;
|
this.circle.x = this.x;
|
||||||
this.circle.y = this.y;
|
this.circle.y = this.y;
|
||||||
this.bounds.width = this.circle.diameter;
|
this.frameBounds.width = this.circle.diameter;
|
||||||
this.bounds.height = this.circle.diameter;
|
this.frameBounds.height = this.circle.diameter;
|
||||||
}
|
}
|
||||||
else if (this.type == GeomSprite.LINE)
|
else if (this.type == GeomSprite.LINE)
|
||||||
{
|
{
|
||||||
this.line.x1 = this.x;
|
this.line.x1 = this.x;
|
||||||
this.line.y1 = this.y;
|
this.line.y1 = this.y;
|
||||||
this.bounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
||||||
}
|
}
|
||||||
else if (this.type == GeomSprite.POINT)
|
else if (this.type == GeomSprite.POINT)
|
||||||
{
|
{
|
||||||
@@ -164,29 +316,41 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
this.rect.x = this.x;
|
this.rect.x = this.x;
|
||||||
this.rect.y = this.y;
|
this.rect.y = this.y;
|
||||||
this.bounds.copyFrom(this.rect);
|
this.frameBounds.copyFrom(this.rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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: Rectangle): bool {
|
public inCamera(camera: Rectangle): bool {
|
||||||
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||||
{
|
{
|
||||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
this._dx = this.frameBounds.x - (camera.x * this.scrollFactor.x);
|
||||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
this._dy = this.frameBounds.y - (camera.y * this.scrollFactor.x);
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
this._dw = this.frameBounds.width * this.scale.x;
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
this._dh = this.frameBounds.height * this.scale.y;
|
||||||
|
|
||||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return camera.intersects(this.bounds);
|
return camera.intersects(this.frameBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render this sprite to specific camera. Called by game loop after update().
|
||||||
|
* @param camera {Camera} Camera this sprite will be rendered to.
|
||||||
|
* @cameraOffsetX {number} X offset to the camera.
|
||||||
|
* @cameraOffsetY {number} Y offset to the camera.
|
||||||
|
* @return {boolean} Return false if not rendered, otherwise return true.
|
||||||
|
*/
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||||
|
|
||||||
// Render checks
|
// Render checks
|
||||||
@@ -198,21 +362,14 @@ module Phaser {
|
|||||||
// Alpha
|
// Alpha
|
||||||
if (this.alpha !== 1)
|
if (this.alpha !== 1)
|
||||||
{
|
{
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
var globalAlpha = this.context.globalAlpha;
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
this.context.globalAlpha = this.alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
this._dx = cameraOffsetX + (this.frameBounds.x - camera.worldView.x);
|
||||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
this._dy = cameraOffsetY + (this.frameBounds.y - camera.worldView.y);
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
this._dw = this.frameBounds.width * this.scale.x;
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
this._dh = this.frameBounds.height * this.scale.y;
|
||||||
|
|
||||||
// Circles are drawn center based
|
|
||||||
if (this.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
this._dx += this.circle.radius;
|
|
||||||
this._dy += this.circle.radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply camera difference
|
// Apply camera difference
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||||
@@ -225,9 +382,9 @@ module Phaser {
|
|||||||
/*
|
/*
|
||||||
if (this.angle !== 0)
|
if (this.angle !== 0)
|
||||||
{
|
{
|
||||||
this._game.stage.context.save();
|
this.context.save();
|
||||||
this._game.stage.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
this.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
||||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
this.context.rotate(this.angle * (Math.PI / 180));
|
||||||
this._dx = -(this._dw / 2);
|
this._dx = -(this._dw / 2);
|
||||||
this._dy = -(this._dh / 2);
|
this._dy = -(this._dh / 2);
|
||||||
}
|
}
|
||||||
@@ -241,12 +398,12 @@ module Phaser {
|
|||||||
this._game.stage.saveCanvasValues();
|
this._game.stage.saveCanvasValues();
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
//this._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
//this.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||||
//this._game.stage.context.fillRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
//this.context.fillRect(this.frameBounds.x, this.frameBounds.y, this.frameBounds.width, this.frameBounds.height);
|
||||||
|
|
||||||
this._game.stage.context.lineWidth = this.lineWidth;
|
this.context.lineWidth = this.lineWidth;
|
||||||
this._game.stage.context.strokeStyle = this.lineColor;
|
this.context.strokeStyle = this.lineColor;
|
||||||
this._game.stage.context.fillStyle = this.fillColor;
|
this.context.fillStyle = this.fillColor;
|
||||||
|
|
||||||
if (this._game.stage.fillStyle !== this.fillColor)
|
if (this._game.stage.fillStyle !== this.fillColor)
|
||||||
{
|
{
|
||||||
@@ -255,52 +412,56 @@ module Phaser {
|
|||||||
// Primitive Renderer
|
// Primitive Renderer
|
||||||
if (this.type == GeomSprite.CIRCLE)
|
if (this.type == GeomSprite.CIRCLE)
|
||||||
{
|
{
|
||||||
this._game.stage.context.beginPath();
|
this.context.beginPath();
|
||||||
this._game.stage.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
this.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
||||||
this._game.stage.context.stroke();
|
|
||||||
|
if (this.renderOutline)
|
||||||
|
{
|
||||||
|
this.context.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.renderFill)
|
if (this.renderFill)
|
||||||
{
|
{
|
||||||
this._game.stage.context.fill();
|
this.context.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._game.stage.context.closePath();
|
this.context.closePath();
|
||||||
}
|
}
|
||||||
else if (this.type == GeomSprite.LINE)
|
else if (this.type == GeomSprite.LINE)
|
||||||
{
|
{
|
||||||
this._game.stage.context.beginPath();
|
this.context.beginPath();
|
||||||
this._game.stage.context.moveTo(this._dx, this._dy);
|
this.context.moveTo(this._dx, this._dy);
|
||||||
this._game.stage.context.lineTo(this.line.x2, this.line.y2);
|
this.context.lineTo(this.line.x2, this.line.y2);
|
||||||
this._game.stage.context.stroke();
|
this.context.stroke();
|
||||||
this._game.stage.context.closePath();
|
this.context.closePath();
|
||||||
}
|
}
|
||||||
else if (this.type == GeomSprite.POINT)
|
else if (this.type == GeomSprite.POINT)
|
||||||
{
|
{
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, 2, 2);
|
this.context.fillRect(this._dx, this._dy, 2, 2);
|
||||||
}
|
}
|
||||||
else if (this.type == GeomSprite.RECTANGLE)
|
else if (this.type == GeomSprite.RECTANGLE)
|
||||||
{
|
{
|
||||||
// We can use the faster fillRect if we don't need the outline
|
// We can use the faster fillRect if we don't need the outline
|
||||||
if (this.renderOutline == false)
|
if (this.renderOutline == false)
|
||||||
{
|
{
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
this.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._game.stage.context.beginPath();
|
this.context.beginPath();
|
||||||
this._game.stage.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
this.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||||
this._game.stage.context.stroke();
|
this.context.stroke();
|
||||||
|
|
||||||
if (this.renderFill)
|
if (this.renderFill)
|
||||||
{
|
{
|
||||||
this._game.stage.context.fill();
|
this.context.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._game.stage.context.closePath();
|
this.context.closePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// And now the edge points
|
// And now the edge points
|
||||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
this.context.fillStyle = 'rgb(255,255,255)';
|
||||||
//this.renderPoint(this.rect.topLeft, this._dx, this._dy, 2);
|
//this.renderPoint(this.rect.topLeft, this._dx, this._dy, 2);
|
||||||
//this.renderPoint(this.rect.topCenter, this._dx, this._dy, 2);
|
//this.renderPoint(this.rect.topCenter, this._dx, this._dy, 2);
|
||||||
//this.renderPoint(this.rect.topRight, this._dx, this._dy, 2);
|
//this.renderPoint(this.rect.topRight, this._dx, this._dy, 2);
|
||||||
@@ -326,37 +487,54 @@ module Phaser {
|
|||||||
|
|
||||||
if (this.rotation !== 0)
|
if (this.rotation !== 0)
|
||||||
{
|
{
|
||||||
this._game.stage.context.translate(0, 0);
|
this.context.translate(0, 0);
|
||||||
this._game.stage.context.restore();
|
this.context.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalAlpha > -1)
|
if (globalAlpha > -1)
|
||||||
{
|
{
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
this.context.globalAlpha = globalAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a point of geometry.
|
||||||
|
* @param point {Point} Position of the point.
|
||||||
|
* @param offsetX {number} X offset to its position.
|
||||||
|
* @param offsetY {number} Y offset to its position.
|
||||||
|
* @param [size] {number} point size.
|
||||||
|
*/
|
||||||
public renderPoint(point, offsetX?: number = 0, offsetY?: number = 0, size?: number = 1) {
|
public renderPoint(point, offsetX?: number = 0, offsetY?: number = 0, size?: number = 1) {
|
||||||
|
|
||||||
this._game.stage.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
|
this.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render debug infos. (this method does not work now)
|
||||||
|
* @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)') {
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||||
|
|
||||||
//this._game.stage.context.fillStyle = color;
|
//this.context.fillStyle = color;
|
||||||
//this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
//this.context.fillText('Sprite: ' + this.name + ' (' + this.frameBounds.width + ' x ' + this.frameBounds.height + ')', x, y);
|
||||||
//this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
//this.context.fillText('x: ' + this.frameBounds.x.toFixed(1) + ' y: ' + this.frameBounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||||
//this._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);
|
//this.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);
|
||||||
//this._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);
|
//this.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gives a basic boolean response to a geometric collision.
|
/**
|
||||||
// If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
* Gives a basic boolean response to a geometric collision.
|
||||||
|
* If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
||||||
|
* @param source {GeomSprite} Sprite you want to check.
|
||||||
|
* @return {boolean} Whether they overlaps or not.
|
||||||
|
*/
|
||||||
public collide(source: GeomSprite): bool {
|
public collide(source: GeomSprite): bool {
|
||||||
|
|
||||||
// Circle vs. Circle
|
// Circle vs. Circle
|
||||||
|
|||||||
@@ -10,8 +10,19 @@
|
|||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
|
|
||||||
export class ScrollRegion{
|
export class ScrollRegion {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ScrollRegion constructor
|
||||||
|
* Create a new <code>ScrollRegion</code>.
|
||||||
|
*
|
||||||
|
* @param x {number} X position in world coordinate.
|
||||||
|
* @param y {number} Y position in world coordinate.
|
||||||
|
* @param width {number} Width of this object.
|
||||||
|
* @param height {number} Height of this object.
|
||||||
|
* @param speedX {number} X-axis scrolling speed.
|
||||||
|
* @param speedY {number} Y-axis scrolling speed.
|
||||||
|
*/
|
||||||
constructor(x: number, y: number, width: number, height: number, speedX:number, speedY:number) {
|
constructor(x: number, y: number, width: number, height: number, speedX:number, speedY:number) {
|
||||||
|
|
||||||
// Our seamless scrolling quads
|
// Our seamless scrolling quads
|
||||||
@@ -38,9 +49,22 @@ module Phaser {
|
|||||||
private _inverseWidth: number = 0;
|
private _inverseWidth: number = 0;
|
||||||
private _inverseHeight: number = 0;
|
private _inverseHeight: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will this region be rendered? (default to true)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public visible: bool = true;
|
public visible: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Region scrolling speed.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public scrollSpeed: MicroPoint;
|
public scrollSpeed: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update region scrolling with tick time.
|
||||||
|
* @param delta {number} Elapsed time since last update.
|
||||||
|
*/
|
||||||
public update(delta: number) {
|
public update(delta: number) {
|
||||||
|
|
||||||
this._scroll.x += this.scrollSpeed.x;
|
this._scroll.x += this.scrollSpeed.x;
|
||||||
@@ -102,6 +126,15 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render this region to specific context.
|
||||||
|
* @param context {CanvasRenderingContext2D} Canvas context this region will be rendered to.
|
||||||
|
* @param texture {object} The texture to be rendered.
|
||||||
|
* @param dx {number} X position in world coordinate.
|
||||||
|
* @param dy {number} Y position in world coordinate.
|
||||||
|
* @param width {number} Width of this region to be rendered.
|
||||||
|
* @param height {number} Height of this region to be rendered.
|
||||||
|
*/
|
||||||
public render(context:CanvasRenderingContext2D, texture, dx: number, dy: number, dw: number, dh: number) {
|
public render(context:CanvasRenderingContext2D, texture, dx: number, dy: number, dw: number, dh: number) {
|
||||||
|
|
||||||
if (this.visible == false)
|
if (this.visible == false)
|
||||||
@@ -126,6 +159,21 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crop part of the texture and render it to the given context.
|
||||||
|
* @param context {CanvasRenderingContext2D} Canvas context the texture will be rendered to.
|
||||||
|
* @param texture {object} Texture to be rendered.
|
||||||
|
* @param srcX {number} Target region top-left x coordinate in the texture.
|
||||||
|
* @param srcX {number} Target region top-left y coordinate in the texture.
|
||||||
|
* @param srcW {number} Target region width in the texture.
|
||||||
|
* @param srcH {number} Target region height in the texture.
|
||||||
|
* @param destX {number} Render region top-left x coordinate in the context.
|
||||||
|
* @param destX {number} Render region top-left y coordinate in the context.
|
||||||
|
* @param destW {number} Target region width in the context.
|
||||||
|
* @param destH {number} Target region height in the context.
|
||||||
|
* @param offsetX {number} X offset to the context.
|
||||||
|
* @param offsetY {number} Y offset to the context.
|
||||||
|
*/
|
||||||
private crop(context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
|
private crop(context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
|
||||||
|
|
||||||
offsetX += destX;
|
offsetX += destX;
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ module Phaser {
|
|||||||
|
|
||||||
export class ScrollZone extends GameObject {
|
export class ScrollZone extends GameObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ScrollZone constructor
|
||||||
|
* Create a new <code>ScrollZone</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param key {string} Asset key for image texture of this object.
|
||||||
|
* @param x {number} X position in world coordinate.
|
||||||
|
* @param y {number} Y position in world coordinate.
|
||||||
|
* @param [width] {number} width of this object.
|
||||||
|
* @param [height] {number} height of this object.
|
||||||
|
*/
|
||||||
constructor(game: Game, key:string, x: number = 0, y: number = 0, width?: number = 0, height?: number = 0) {
|
constructor(game: Game, key:string, x: number = 0, y: number = 0, width?: number = 0, height?: number = 0) {
|
||||||
|
|
||||||
super(game, x, y, width, height);
|
super(game, x, y, width, height);
|
||||||
@@ -49,19 +60,69 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture of this object.
|
||||||
|
*/
|
||||||
private _texture;
|
private _texture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this zone is larger than texture image, this will be filled with a pattern of texture.
|
||||||
|
* @type {DynamicTexture}
|
||||||
|
*/
|
||||||
private _dynamicTexture: DynamicTexture = null;
|
private _dynamicTexture: DynamicTexture = null;
|
||||||
|
|
||||||
// local rendering related temp vars to help avoid gc spikes
|
/**
|
||||||
|
* Local rendering related temp vars to help avoid gc spikes.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _dx: number = 0;
|
private _dx: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local rendering related temp vars to help avoid gc spikes.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _dy: number = 0;
|
private _dy: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local rendering related temp vars to help avoid gc spikes.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _dw: number = 0;
|
private _dw: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local rendering related temp vars to help avoid gc spikes.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _dh: number = 0;
|
private _dh: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current region this zone is scrolling.
|
||||||
|
* @type {ScrollRegion}
|
||||||
|
*/
|
||||||
public currentRegion: ScrollRegion;
|
public currentRegion: ScrollRegion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array contains all added regions.
|
||||||
|
* @type {ScrollRegion[]}
|
||||||
|
*/
|
||||||
public regions: ScrollRegion[];
|
public regions: ScrollRegion[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flip this zone vertically? (default to false)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public flipped: bool = false;
|
public flipped: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new region to this zone.
|
||||||
|
* @param x {number} X position of the new region.
|
||||||
|
* @param y {number} Y position of the new region.
|
||||||
|
* @param width {number} Width of the new region.
|
||||||
|
* @param height {number} Height of the new region.
|
||||||
|
* @param [speedX] {number} x-axis scrolling speed.
|
||||||
|
* @param [speedY] {number} y-axis scrolling speed.
|
||||||
|
* @return {ScrollRegion} The newly added region.
|
||||||
|
*/
|
||||||
public addRegion(x: number, y: number, width: number, height: number, speedX?:number = 0, speedY?:number = 0):ScrollRegion {
|
public addRegion(x: number, y: number, width: number, height: number, speedX?:number = 0, speedY?:number = 0):ScrollRegion {
|
||||||
|
|
||||||
if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height)
|
if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height)
|
||||||
@@ -78,6 +139,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set scrolling speed of current region.
|
||||||
|
* @param x {number} X speed of current region.
|
||||||
|
* @param y {number} Y speed of current region.
|
||||||
|
*/
|
||||||
public setSpeed(x: number, y: number) {
|
public setSpeed(x: number, y: number) {
|
||||||
|
|
||||||
if (this.currentRegion)
|
if (this.currentRegion)
|
||||||
@@ -89,6 +155,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update regions.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
for (var i = 0; i < this.regions.length; i++)
|
for (var i = 0; i < this.regions.length; i++)
|
||||||
@@ -98,24 +167,36 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this zone is visible in a specific camera rectangle.
|
||||||
|
* @param camera {Rectangle} The rectangle you want to check.
|
||||||
|
* @return {boolean} Return true if bound of this zone intersects the given rectangle, otherwise return false.
|
||||||
|
*/
|
||||||
public inCamera(camera: Rectangle): bool {
|
public inCamera(camera: Rectangle): bool {
|
||||||
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||||
{
|
{
|
||||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
this._dx = this.frameBounds.x - (camera.x * this.scrollFactor.x);
|
||||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
this._dy = this.frameBounds.y - (camera.y * this.scrollFactor.x);
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
this._dw = this.frameBounds.width * this.scale.x;
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
this._dh = this.frameBounds.height * this.scale.y;
|
||||||
|
|
||||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return camera.intersects(this.bounds, this.bounds.length);
|
return camera.intersects(this.frameBounds, this.frameBounds.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render this zone object to a specific camera.
|
||||||
|
* @param camera {Camera} The camera this object will be render to.
|
||||||
|
* @param cameraOffsetX {number} X offset of camera.
|
||||||
|
* @param cameraOffsetY {number} Y offset of camera.
|
||||||
|
* @return Return false if not rendered, otherwise return true.
|
||||||
|
*/
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||||
|
|
||||||
// Render checks
|
// Render checks
|
||||||
@@ -127,14 +208,14 @@ module Phaser {
|
|||||||
// Alpha
|
// Alpha
|
||||||
if (this.alpha !== 1)
|
if (this.alpha !== 1)
|
||||||
{
|
{
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
var globalAlpha = this.context.globalAlpha;
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
this.context.globalAlpha = this.alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x);
|
||||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y);
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
this._dw = this.frameBounds.width * this.scale.x;
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
this._dh = this.frameBounds.height * this.scale.y;
|
||||||
|
|
||||||
// Apply camera difference
|
// Apply camera difference
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||||
@@ -146,12 +227,12 @@ module Phaser {
|
|||||||
// Rotation - needs to work from origin point really, but for now from center
|
// Rotation - needs to work from origin point really, but for now from center
|
||||||
if (this.angle !== 0 || this.flipped == true)
|
if (this.angle !== 0 || this.flipped == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.save();
|
this.context.save();
|
||||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
this.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||||
|
|
||||||
if (this.angle !== 0)
|
if (this.angle !== 0)
|
||||||
{
|
{
|
||||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
this.context.rotate(this.angle * (Math.PI / 180));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dx = -(this._dw / 2);
|
this._dx = -(this._dw / 2);
|
||||||
@@ -159,7 +240,7 @@ module Phaser {
|
|||||||
|
|
||||||
if (this.flipped == true)
|
if (this.flipped == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.scale(-1, 1);
|
this.context.scale(-1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,23 +253,27 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (this._dynamicTexture)
|
if (this._dynamicTexture)
|
||||||
{
|
{
|
||||||
this.regions[i].render(this._game.stage.context, this._dynamicTexture.canvas, this._dx, this._dy, this._dw, this._dh);
|
this.regions[i].render(this.context, this._dynamicTexture.canvas, this._dx, this._dy, this._dw, this._dh);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.regions[i].render(this._game.stage.context, this._texture, this._dx, this._dy, this._dw, this._dh);
|
this.regions[i].render(this.context, this._texture, this._dx, this._dy, this._dw, this._dh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalAlpha > -1)
|
if (globalAlpha > -1)
|
||||||
{
|
{
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
this.context.globalAlpha = globalAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create repeating texture with _texture, and store it into the _dynamicTexture.
|
||||||
|
* Used to create texture when texture image is small than size of the zone.
|
||||||
|
*/
|
||||||
private createRepeatingTexture(regionWidth: number, regionHeight: number) {
|
private createRepeatingTexture(regionWidth: number, regionHeight: number) {
|
||||||
|
|
||||||
// Work out how many we'll need of the source image to make it tile properly
|
// Work out how many we'll need of the source image to make it tile properly
|
||||||
|
|||||||
+188
-81
@@ -14,6 +14,15 @@ module Phaser {
|
|||||||
|
|
||||||
export class Sprite extends GameObject {
|
export class Sprite extends GameObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sprite constructor
|
||||||
|
* Create a new <code>Sprite</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null) {
|
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null) {
|
||||||
|
|
||||||
super(game, x, y);
|
super(game, x, y);
|
||||||
@@ -24,17 +33,26 @@ module Phaser {
|
|||||||
|
|
||||||
if (key !== null)
|
if (key !== null)
|
||||||
{
|
{
|
||||||
|
this.cacheKey = key;
|
||||||
this.loadGraphic(key);
|
this.loadGraphic(key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.bounds.width = 16;
|
this.frameBounds.width = 16;
|
||||||
this.bounds.height = 16;
|
this.frameBounds.height = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture of this sprite to be rendered.
|
||||||
|
*/
|
||||||
private _texture;
|
private _texture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture of this sprite is DynamicTexture? (default to false)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
private _dynamicTexture: bool = false;
|
private _dynamicTexture: bool = false;
|
||||||
|
|
||||||
// local rendering related temp vars to help avoid gc spikes
|
// local rendering related temp vars to help avoid gc spikes
|
||||||
@@ -47,27 +65,76 @@ module Phaser {
|
|||||||
private _dw: number = 0;
|
private _dw: number = 0;
|
||||||
private _dh: number = 0;
|
private _dh: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This manages animations of the sprite. You can modify animations though it. (see AnimationManager)
|
||||||
|
* @type AnimationManager
|
||||||
|
*/
|
||||||
public animations: AnimationManager;
|
public animations: AnimationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cache key that was used for this texture (if any)
|
||||||
|
*/
|
||||||
|
public cacheKey: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render bound of this sprite for debugging? (default to false)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public renderDebug: bool = false;
|
public renderDebug: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color of the Sprite when no image is present. Format is a css color string.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
public fillColor: string = 'rgb(255,255,255)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color of bound when render debug. (see renderDebug) Format is a css color string.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public renderDebugColor: string = 'rgba(0,255,0,0.5)';
|
public renderDebugColor: string = 'rgba(0,255,0,0.5)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color of points when render debug. (see renderDebug) Format is a css color string.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public renderDebugPointColor: string = 'rgba(255,255,255,1)';
|
public renderDebugPointColor: string = 'rgba(255,255,255,1)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flip the graphic horizontally? (defaults to false)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public flipped: bool = false;
|
public flipped: bool = false;
|
||||||
|
|
||||||
public loadGraphic(key: string): Sprite {
|
/**
|
||||||
|
* Load graphic for this sprite. (graphic can be SpriteSheet or Texture)
|
||||||
|
* @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
|
||||||
|
* @return {Sprite} Sprite instance itself.
|
||||||
|
*/
|
||||||
|
public loadGraphic(key: string, clearAnimations: bool = true): Sprite {
|
||||||
|
|
||||||
|
if (clearAnimations && this.animations.frameData !== null)
|
||||||
|
{
|
||||||
|
this.animations.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
if (this._game.cache.getImage(key) !== null)
|
if (this._game.cache.getImage(key) !== null)
|
||||||
{
|
{
|
||||||
if (this._game.cache.isSpriteSheet(key) == false)
|
if (this._game.cache.isSpriteSheet(key) == false)
|
||||||
{
|
{
|
||||||
this._texture = this._game.cache.getImage(key);
|
this._texture = this._game.cache.getImage(key);
|
||||||
this.bounds.width = this._texture.width;
|
this.frameBounds.width = this._texture.width;
|
||||||
this.bounds.height = this._texture.height;
|
this.frameBounds.height = this._texture.height;
|
||||||
|
this.collisionMask.width = this._texture.width;
|
||||||
|
this.collisionMask.height = this._texture.height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._texture = this._game.cache.getImage(key);
|
this._texture = this._game.cache.getImage(key);
|
||||||
this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
||||||
|
this.collisionMask.width = this.animations.currentFrame.width;
|
||||||
|
this.collisionMask.height = this.animations.currentFrame.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dynamicTexture = false;
|
this._dynamicTexture = false;
|
||||||
@@ -77,12 +144,17 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a DynamicTexture as its texture.
|
||||||
|
* @param texture {DynamicTexture} The texture object to be used by this sprite.
|
||||||
|
* @return {Sprite} Sprite instance itself.
|
||||||
|
*/
|
||||||
public loadDynamicTexture(texture: DynamicTexture): Sprite {
|
public loadDynamicTexture(texture: DynamicTexture): Sprite {
|
||||||
|
|
||||||
this._texture = texture;
|
this._texture = texture;
|
||||||
|
|
||||||
this.bounds.width = this._texture.width;
|
this.frameBounds.width = this._texture.width;
|
||||||
this.bounds.height = this._texture.height;
|
this.frameBounds.height = this._texture.height;
|
||||||
|
|
||||||
this._dynamicTexture = true;
|
this._dynamicTexture = true;
|
||||||
|
|
||||||
@@ -90,35 +162,49 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public makeGraphic(width: number, height: number, color: number = 0xffffffff): Sprite {
|
/**
|
||||||
|
* This function creates a flat colored square image dynamically.
|
||||||
|
* @param width {number} The width of the sprite you want to generate.
|
||||||
|
* @param height {number} The height of the sprite you want to generate.
|
||||||
|
* @param [color] {number} specifies the color of the generated block. (format is 0xAARRGGBB)
|
||||||
|
* @return {Sprite} Sprite instance itself.
|
||||||
|
*/
|
||||||
|
public makeGraphic(width: number, height: number, color: string = 'rgb(255,255,255)'): Sprite {
|
||||||
|
|
||||||
this._texture = null;
|
this._texture = null;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
this.fillColor = color;
|
||||||
this._dynamicTexture = false;
|
this._dynamicTexture = false;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inCamera(camera: Rectangle): bool {
|
/**
|
||||||
|
* Check whether this object is visible in a specific camera rectangle.
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
* @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.
|
||||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
*/
|
||||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
public inCamera(camera: Rectangle, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||||
}
|
if (this.scrollFactor.x == 0 && this.scrollFactor.y == 0)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return camera.intersects(this.bounds, this.bounds.length);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._dx = (this.frameBounds.x - camera.x);
|
||||||
|
this._dy = (this.frameBounds.y - camera.y);
|
||||||
|
this._dw = this.frameBounds.width * this.scale.x;
|
||||||
|
this._dh = this.frameBounds.height * this.scale.y;
|
||||||
|
|
||||||
|
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically called after update() by the game loop, this function just updates animations.
|
||||||
|
*/
|
||||||
public postUpdate() {
|
public postUpdate() {
|
||||||
|
|
||||||
this.animations.update();
|
this.animations.update();
|
||||||
@@ -143,10 +229,17 @@ module Phaser {
|
|||||||
return this.animations.frameName;
|
return this.animations.frameName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render this sprite to specific camera. Called by game loop after update().
|
||||||
|
* @param camera {Camera} Camera this sprite will be rendered to.
|
||||||
|
* @cameraOffsetX {number} X offset to the camera.
|
||||||
|
* @cameraOffsetY {number} Y offset to the camera.
|
||||||
|
* @return {boolean} Return false if not rendered, otherwise return true.
|
||||||
|
*/
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||||
|
|
||||||
// Render checks
|
// Render checks
|
||||||
if (this.visible == false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
|
if (this.visible == false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView, cameraOffsetX, cameraOffsetY) == false)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -154,54 +247,55 @@ module Phaser {
|
|||||||
// Alpha
|
// Alpha
|
||||||
if (this.alpha !== 1)
|
if (this.alpha !== 1)
|
||||||
{
|
{
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
var globalAlpha = this.context.globalAlpha;
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
this.context.globalAlpha = this.alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._sx = 0;
|
this._sx = 0;
|
||||||
this._sy = 0;
|
this._sy = 0;
|
||||||
this._sw = this.bounds.width;
|
this._sw = this.frameBounds.width;
|
||||||
this._sh = this.bounds.height;
|
this._sh = this.frameBounds.height;
|
||||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
|
||||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
this._dx = (cameraOffsetX * this.scrollFactor.x) + this.frameBounds.topLeft.x - (camera.worldView.x * this.scrollFactor.x);
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
this._dy = (cameraOffsetY * this.scrollFactor.y) + this.frameBounds.topLeft.y - (camera.worldView.y * this.scrollFactor.y);
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
this._dw = this.frameBounds.width * this.scale.x;
|
||||||
|
this._dh = this.frameBounds.height * this.scale.y;
|
||||||
|
|
||||||
if (this.align == GameObject.ALIGN_TOP_CENTER)
|
if (this.align == GameObject.ALIGN_TOP_CENTER)
|
||||||
{
|
{
|
||||||
this._dx -= this.bounds.halfWidth * this.scale.x;
|
this._dx -= this.frameBounds.halfWidth * this.scale.x;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_TOP_RIGHT)
|
else if (this.align == GameObject.ALIGN_TOP_RIGHT)
|
||||||
{
|
{
|
||||||
this._dx -= this.bounds.width * this.scale.x;
|
this._dx -= this.frameBounds.width * this.scale.x;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_CENTER_LEFT)
|
else if (this.align == GameObject.ALIGN_CENTER_LEFT)
|
||||||
{
|
{
|
||||||
this._dy -= this.bounds.halfHeight * this.scale.y;
|
this._dy -= this.frameBounds.halfHeight * this.scale.y;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_CENTER)
|
else if (this.align == GameObject.ALIGN_CENTER)
|
||||||
{
|
{
|
||||||
this._dx -= this.bounds.halfWidth * this.scale.x;
|
this._dx -= this.frameBounds.halfWidth * this.scale.x;
|
||||||
this._dy -= this.bounds.halfHeight * this.scale.y;
|
this._dy -= this.frameBounds.halfHeight * this.scale.y;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_CENTER_RIGHT)
|
else if (this.align == GameObject.ALIGN_CENTER_RIGHT)
|
||||||
{
|
{
|
||||||
this._dx -= this.bounds.width * this.scale.x;
|
this._dx -= this.frameBounds.width * this.scale.x;
|
||||||
this._dy -= this.bounds.halfHeight * this.scale.y;
|
this._dy -= this.frameBounds.halfHeight * this.scale.y;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_BOTTOM_LEFT)
|
else if (this.align == GameObject.ALIGN_BOTTOM_LEFT)
|
||||||
{
|
{
|
||||||
this._dy -= this.bounds.height * this.scale.y;
|
this._dy -= this.frameBounds.height * this.scale.y;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_BOTTOM_CENTER)
|
else if (this.align == GameObject.ALIGN_BOTTOM_CENTER)
|
||||||
{
|
{
|
||||||
this._dx -= this.bounds.halfWidth * this.scale.x;
|
this._dx -= this.frameBounds.halfWidth * this.scale.x;
|
||||||
this._dy -= this.bounds.height * this.scale.y;
|
this._dy -= this.frameBounds.height * this.scale.y;
|
||||||
}
|
}
|
||||||
else if (this.align == GameObject.ALIGN_BOTTOM_RIGHT)
|
else if (this.align == GameObject.ALIGN_BOTTOM_RIGHT)
|
||||||
{
|
{
|
||||||
this._dx -= this.bounds.width * this.scale.x;
|
this._dx -= this.frameBounds.width * this.scale.x;
|
||||||
this._dy -= this.bounds.height * this.scale.y;
|
this._dy -= this.frameBounds.height * this.scale.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
|
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
|
||||||
@@ -217,21 +311,21 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply camera difference
|
// Apply camera difference
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
if (this.scrollFactor.x !== 1 || this.scrollFactor.y !== 1)
|
||||||
{
|
{
|
||||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
//this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
||||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
//this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotation - needs to work from origin point really, but for now from center
|
// Rotation - needs to work from origin point really, but for now from center
|
||||||
if (this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true)
|
if (this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.save();
|
this.context.save();
|
||||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
this.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||||
|
|
||||||
if (this.renderRotation == true && (this.angle !== 0 || this.rotationOffset !== 0))
|
if (this.renderRotation == true && (this.angle !== 0 || this.rotationOffset !== 0))
|
||||||
{
|
{
|
||||||
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
this.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._dx = -(this._dw / 2);
|
this._dx = -(this._dw / 2);
|
||||||
@@ -239,7 +333,7 @@ module Phaser {
|
|||||||
|
|
||||||
if (this.flipped == true)
|
if (this.flipped == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.scale(-1, 1);
|
this.context.scale(-1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +350,7 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (this._dynamicTexture)
|
if (this._dynamicTexture)
|
||||||
{
|
{
|
||||||
this._game.stage.context.drawImage(
|
this.context.drawImage(
|
||||||
this._texture.canvas, // Source Image
|
this._texture.canvas, // Source Image
|
||||||
this._sx, // Source X (location within the source image)
|
this._sx, // Source X (location within the source image)
|
||||||
this._sy, // Source Y
|
this._sy, // Source Y
|
||||||
@@ -270,7 +364,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._game.stage.context.drawImage(
|
this.context.drawImage(
|
||||||
this._texture, // Source Image
|
this._texture, // Source Image
|
||||||
this._sx, // Source X (location within the source image)
|
this._sx, // Source X (location within the source image)
|
||||||
this._sy, // Source Y
|
this._sy, // Source Y
|
||||||
@@ -285,64 +379,77 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
this.context.fillStyle = this.fillColor;
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
this.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0)
|
if (this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0)
|
||||||
{
|
{
|
||||||
//this._game.stage.context.translate(0, 0);
|
//this.context.translate(0, 0);
|
||||||
this._game.stage.context.restore();
|
this.context.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.renderDebug)
|
if (this.renderDebug)
|
||||||
{
|
{
|
||||||
this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
|
this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
|
||||||
|
//this.collisionMask.render(camera, cameraOffsetX, cameraOffsetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalAlpha > -1)
|
if (globalAlpha > -1)
|
||||||
{
|
{
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
this.context.globalAlpha = globalAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
|
/**
|
||||||
|
* Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
|
||||||
|
* @param camera {Camera} Camera the bound will be rendered to.
|
||||||
|
* @param cameraOffsetX {number} X offset of bound to the camera.
|
||||||
|
* @param cameraOffsetY {number} Y offset of bound to the camera.
|
||||||
|
*/
|
||||||
private renderBounds(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) {
|
private renderBounds(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) {
|
||||||
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x);
|
||||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y);
|
||||||
|
|
||||||
this._game.stage.context.fillStyle = this.renderDebugColor;
|
this.context.fillStyle = this.renderDebugColor;
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
this.context.fillRect(this._dx, this._dy, this.frameBounds.width, this.frameBounds.height);
|
||||||
this._game.stage.context.fillStyle = this.renderDebugPointColor;
|
|
||||||
|
|
||||||
var hw = this.bounds.halfWidth * this.scale.x;
|
|
||||||
var hh = this.bounds.halfHeight * this.scale.y;
|
|
||||||
var sw = (this.bounds.width * this.scale.x) - 1;
|
|
||||||
var sh = (this.bounds.height * this.scale.y) - 1;
|
|
||||||
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, 1, 1); // top left
|
//this.context.fillStyle = this.renderDebugPointColor;
|
||||||
this._game.stage.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center
|
|
||||||
this._game.stage.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right
|
//var hw = this.frameBounds.halfWidth * this.scale.x;
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center
|
//var hh = this.frameBounds.halfHeight * this.scale.y;
|
||||||
this._game.stage.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center
|
//var sw = (this.frameBounds.width * this.scale.x) - 1;
|
||||||
this._game.stage.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center
|
//var sh = (this.frameBounds.height * this.scale.y) - 1;
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left
|
|
||||||
this._game.stage.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center
|
//this.context.fillRect(this._dx, this._dy, 1, 1); // top left
|
||||||
this._game.stage.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right
|
//this.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center
|
||||||
|
//this.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right
|
||||||
|
//this.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center
|
||||||
|
//this.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center
|
||||||
|
//this.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center
|
||||||
|
//this.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left
|
||||||
|
//this.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center
|
||||||
|
//this.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render debug infos. (including name, bounds info, position 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)') {
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||||
|
|
||||||
this._game.stage.context.fillStyle = color;
|
this.context.fillStyle = color;
|
||||||
this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
this.context.fillText('Sprite: ' + this.name + ' (' + this.frameBounds.width + ' x ' + this.frameBounds.height + ')', x, y);
|
||||||
this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
this.context.fillText('x: ' + this.frameBounds.x.toFixed(1) + ' y: ' + this.frameBounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||||
this._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);
|
this.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);
|
||||||
this._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);
|
this.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,18 @@ module Phaser {
|
|||||||
|
|
||||||
export class Tilemap extends GameObject {
|
export class Tilemap extends GameObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tilemap constructor
|
||||||
|
* Create a new <code>Tilemap</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param key {string} Asset key for this map.
|
||||||
|
* @param mapData {string} Data of this map. (a big 2d array, normally in csv)
|
||||||
|
* @param format {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||||
|
* @param resizeWorld {boolean} Resize the world bound automatically based on this tilemap?
|
||||||
|
* @param tileWidth {number} Width of tiles in this map.
|
||||||
|
* @param tileHeight {number} Height of tiles in this map.
|
||||||
|
*/
|
||||||
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) {
|
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) {
|
||||||
|
|
||||||
super(game);
|
super(game);
|
||||||
@@ -45,20 +57,64 @@ module Phaser {
|
|||||||
|
|
||||||
private _tempCollisionData;
|
private _tempCollisionData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tilemap data format enum: CSV.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static FORMAT_CSV: number = 0;
|
public static FORMAT_CSV: number = 0;
|
||||||
|
/**
|
||||||
|
* Tilemap data format enum: Tiled JSON.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static FORMAT_TILED_JSON: number = 1;
|
public static FORMAT_TILED_JSON: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array contains tile objects of this map.
|
||||||
|
* @type {Tile[]}
|
||||||
|
*/
|
||||||
public tiles : Tile[];
|
public tiles : Tile[];
|
||||||
|
/**
|
||||||
|
* Array contains tilemap layer objects of this map.
|
||||||
|
* @type {TilemapLayer[]}
|
||||||
|
*/
|
||||||
public layers : TilemapLayer[];
|
public layers : TilemapLayer[];
|
||||||
|
/**
|
||||||
|
* Current tilemap layer.
|
||||||
|
* @type {TilemapLayer}
|
||||||
|
*/
|
||||||
public currentLayer: TilemapLayer;
|
public currentLayer: TilemapLayer;
|
||||||
|
/**
|
||||||
|
* The tilemap layer for collision.
|
||||||
|
* @type {TilemapLayer}
|
||||||
|
*/
|
||||||
public collisionLayer: TilemapLayer;
|
public collisionLayer: TilemapLayer;
|
||||||
|
/**
|
||||||
|
* Tilemap collision callback.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
public collisionCallback = null;
|
public collisionCallback = null;
|
||||||
|
/**
|
||||||
|
* Context for the collision callback called with.
|
||||||
|
*/
|
||||||
public collisionCallbackContext;
|
public collisionCallbackContext;
|
||||||
|
/**
|
||||||
|
* Format of this tilemap data. Available values: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public mapFormat: number;
|
public mapFormat: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inherited update method.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render this tilemap to a specific camera with specific offset.
|
||||||
|
* @param camera {Camera} The camera this tilemap will be rendered to.
|
||||||
|
* @param cameraOffsetX {number} X offset of the camera.
|
||||||
|
* @param cameraOffsetY {number} Y offset of the camera.
|
||||||
|
*/
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||||
|
|
||||||
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
|
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
|
||||||
@@ -72,6 +128,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parset csv map data and generate tiles.
|
||||||
|
* @param data {string} CSV map data.
|
||||||
|
* @param key {string} Asset key for tileset image.
|
||||||
|
* @param tileWidth {number} Width of its tile.
|
||||||
|
* @param tileHeight {number} Height of its tile.
|
||||||
|
*/
|
||||||
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
|
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
|
||||||
|
|
||||||
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
|
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
|
||||||
@@ -103,6 +166,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parset JSON map data and generate tiles.
|
||||||
|
* @param data {string} JSON map data.
|
||||||
|
* @param key {string} Asset key for tileset image.
|
||||||
|
*/
|
||||||
private parseTiledJSON(data: string, key: string) {
|
private parseTiledJSON(data: string, key: string) {
|
||||||
|
|
||||||
// Trim any rogue whitespace from the data
|
// Trim any rogue whitespace from the data
|
||||||
@@ -113,7 +181,7 @@ module Phaser {
|
|||||||
for (var i = 0; i < json.layers.length; i++)
|
for (var i = 0; i < json.layers.length; i++)
|
||||||
{
|
{
|
||||||
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
||||||
|
|
||||||
layer.alpha = json.layers[i].opacity;
|
layer.alpha = json.layers[i].opacity;
|
||||||
layer.visible = json.layers[i].visible;
|
layer.visible = json.layers[i].visible;
|
||||||
layer.tileMargin = json.tilesets[0].margin;
|
layer.tileMargin = json.tilesets[0].margin;
|
||||||
@@ -155,6 +223,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create tiles of given quantity.
|
||||||
|
* @param qty {number} Quentity of tiles to be generated.
|
||||||
|
*/
|
||||||
private generateTiles(qty:number) {
|
private generateTiles(qty:number) {
|
||||||
|
|
||||||
for (var i = 0; i < qty; i++)
|
for (var i = 0; i < qty; i++)
|
||||||
@@ -174,6 +246,11 @@ module Phaser {
|
|||||||
|
|
||||||
// Tile Collision
|
// Tile Collision
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set callback to be called when this tilemap collides.
|
||||||
|
* @param context {object} Callback will be called with this context.
|
||||||
|
* @param callback {function} Callback function.
|
||||||
|
*/
|
||||||
public setCollisionCallback(context, callback) {
|
public setCollisionCallback(context, callback) {
|
||||||
|
|
||||||
this.collisionCallbackContext = context;
|
this.collisionCallbackContext = context;
|
||||||
@@ -181,6 +258,15 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set collision configs of tiles in a range index.
|
||||||
|
* @param start {number} First index of tiles.
|
||||||
|
* @param end {number} Last index of tiles.
|
||||||
|
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||||
|
* @param resetCollisions {boolean} Reset collision flags before set.
|
||||||
|
* @param separateX {boolean} Enable seprate at x-axis.
|
||||||
|
* @param separateY {boolean} Enable seprate at y-axis.
|
||||||
|
*/
|
||||||
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
||||||
|
|
||||||
for (var i = start; i < end; i++)
|
for (var i = start; i < end; i++)
|
||||||
@@ -190,6 +276,14 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set collision configs of tiles with given index.
|
||||||
|
* @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters.
|
||||||
|
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||||
|
* @param resetCollisions {boolean} Reset collision flags before set.
|
||||||
|
* @param separateX {boolean} Enable seprate at x-axis.
|
||||||
|
* @param separateY {boolean} Enable seprate at y-axis.
|
||||||
|
*/
|
||||||
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
|
||||||
|
|
||||||
for (var i = 0; i < values.length; i++)
|
for (var i = 0; i < values.length; i++)
|
||||||
@@ -201,6 +295,11 @@ module Phaser {
|
|||||||
|
|
||||||
// Tile Management
|
// Tile Management
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile by its index.
|
||||||
|
* @param value {number} Index of the tile you want to get.
|
||||||
|
* @return {Tile} The tile with given index.
|
||||||
|
*/
|
||||||
public getTileByIndex(value: number):Tile {
|
public getTileByIndex(value: number):Tile {
|
||||||
|
|
||||||
if (this.tiles[value])
|
if (this.tiles[value])
|
||||||
@@ -212,12 +311,26 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile located at specific position and layer.
|
||||||
|
* @param x {number} X position of this tile located.
|
||||||
|
* @param y {number} Y position of this tile located.
|
||||||
|
* @param [layer] {number} layer of this tile located.
|
||||||
|
* @return {Tile} The tile with specific properties.
|
||||||
|
*/
|
||||||
public getTile(x: number, y: number, layer?: number = 0):Tile {
|
public getTile(x: number, y: number, layer?: number = 0):Tile {
|
||||||
|
|
||||||
return this.tiles[this.layers[layer].getTileIndex(x, y)];
|
return this.tiles[this.layers[layer].getTileIndex(x, y)];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile)
|
||||||
|
* @param x {number} X position of the point in target tile.
|
||||||
|
* @param x {number} Y position of the point in target tile.
|
||||||
|
* @param [layer] {number} layer of this tile located.
|
||||||
|
* @return {Tile} The tile with specific properties.
|
||||||
|
*/
|
||||||
public getTileFromWorldXY(x: number, y: number, layer?: number = 0):Tile {
|
public getTileFromWorldXY(x: number, y: number, layer?: number = 0):Tile {
|
||||||
|
|
||||||
return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
|
return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
|
||||||
@@ -226,10 +339,15 @@ module Phaser {
|
|||||||
|
|
||||||
public getTileFromInputXY(layer?: number = 0):Tile {
|
public getTileFromInputXY(layer?: number = 0):Tile {
|
||||||
|
|
||||||
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.worldX, this._game.input.worldY)];
|
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.getWorldX(), this._game.input.getWorldY())];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tiles overlaps the given object.
|
||||||
|
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||||
|
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||||
|
*/
|
||||||
public getTileOverlaps(object: GameObject) {
|
public getTileOverlaps(object: GameObject) {
|
||||||
|
|
||||||
return this.currentLayer.getTileOverlaps(object);
|
return this.currentLayer.getTileOverlaps(object);
|
||||||
@@ -237,6 +355,13 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// COLLIDE
|
// COLLIDE
|
||||||
|
/**
|
||||||
|
* Check whether this tilemap collides with the given game object or group of objects.
|
||||||
|
* @param objectOrGroup {function} Target object of group you want to check.
|
||||||
|
* @param callback {function} This is called if objectOrGroup collides the tilemap.
|
||||||
|
* @param context {object} Callback will be called with this context.
|
||||||
|
* @return {boolean} Return true if this collides with given object, otherwise return false.
|
||||||
|
*/
|
||||||
public collide(objectOrGroup = null, callback = null, context = null) {
|
public collide(objectOrGroup = null, callback = null, context = null) {
|
||||||
|
|
||||||
if (callback !== null && context !== null)
|
if (callback !== null && context !== null)
|
||||||
@@ -262,6 +387,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this tilemap collides with the given game object.
|
||||||
|
* @param object {GameObject} Target object you want to check.
|
||||||
|
* @return {boolean} Return true if this collides with given object, otherwise return false.
|
||||||
|
*/
|
||||||
public collideGameObject(object: GameObject): bool {
|
public collideGameObject(object: GameObject): bool {
|
||||||
|
|
||||||
if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
|
if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
|
||||||
@@ -282,6 +412,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a tile to a specific layer.
|
||||||
|
* @param x {number} X position of this tile.
|
||||||
|
* @param y {number} Y position of this tile.
|
||||||
|
* @param index {number} The index of this tile type in the core map data.
|
||||||
|
* @param [layer] {number} which layer you want to set the tile to.
|
||||||
|
*/
|
||||||
public putTile(x: number, y: number, index: number, layer?: number = 0) {
|
public putTile(x: number, y: number, index: number, layer?: number = 0) {
|
||||||
|
|
||||||
this.layers[layer].putTile(x, y, index);
|
this.layers[layer].putTile(x, y, index);
|
||||||
|
|||||||
+21
-11
@@ -14,42 +14,52 @@ module Phaser {
|
|||||||
* Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
|
* Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
|
||||||
* @class Circle
|
* @class Circle
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {Number} x The x coordinate of the center of the circle.
|
* @param {Number} [x] The x coordinate of the center of the circle.
|
||||||
* @param {Number} y The y coordinate of the center of the circle.
|
* @param {Number} [y] The y coordinate of the center of the circle.
|
||||||
|
* @param {Number} [diameter] The diameter of the circle.
|
||||||
* @return {Circle} This circle object
|
* @return {Circle} This circle object
|
||||||
**/
|
**/
|
||||||
constructor(x: number = 0, y: number = 0, diameter: number = 0) {
|
constructor(x: number = 0, y: number = 0, diameter: number = 0) {
|
||||||
|
|
||||||
|
this._pos = new Vector2;
|
||||||
this.setTo(x, y, diameter);
|
this.setTo(x, y, diameter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _diameter: number = 0;
|
private _diameter: number = 0;
|
||||||
private _radius: number = 0;
|
private _radius: number = 0;
|
||||||
|
private _pos: Vector2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x coordinate of the center of the circle
|
* The x coordinate of the center of the circle
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type Number
|
||||||
**/
|
**/
|
||||||
public x: number = 0;
|
public x: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The y coordinate of the center of the circle
|
* The y coordinate of the center of the circle
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type Number
|
||||||
**/
|
**/
|
||||||
public y: number = 0;
|
public y: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The position of this Circle object represented by a Vector2
|
||||||
|
* @property pos
|
||||||
|
* @type Vector2
|
||||||
|
**/
|
||||||
|
public get pos(): Vector2 {
|
||||||
|
return this._pos.setTo(this.x, this.y);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
||||||
* @method diameter
|
* @method diameter
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
**/
|
**/
|
||||||
get diameter(): number {
|
get diameter(): number {
|
||||||
|
|
||||||
return this._diameter;
|
return this._diameter;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,7 +297,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Returns a new Circle object with the same values for the x, y, width, and height properties as the original Circle object.
|
* Returns a new Circle object with the same values for the x, y, width, and height properties as the original Circle object.
|
||||||
* @method clone
|
* @method clone
|
||||||
* @param {Circle} output Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
|
* @param {Circle} [optional] output Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
|
||||||
* @return {Phaser.Circle}
|
* @return {Phaser.Circle}
|
||||||
**/
|
**/
|
||||||
public clone(output?: Circle = new Circle): Circle {
|
public clone(output?: Circle = new Circle): Circle {
|
||||||
@@ -364,7 +374,7 @@ module Phaser {
|
|||||||
* Returns the distance from the center of this Circle object to the given object (can be Circle, Point or anything with x/y values)
|
* Returns the distance from the center of this Circle object to the given object (can be Circle, Point or anything with x/y values)
|
||||||
* @method distanceFrom
|
* @method distanceFrom
|
||||||
* @param {Circle/Point} target - The destination Point object.
|
* @param {Circle/Point} target - The destination Point object.
|
||||||
* @param {Boolean} round - Round the distance to the nearest integer (default false)
|
* @param {Boolean} [optional] round - Round the distance to the nearest integer (default false)
|
||||||
* @return {Number} The distance between this Point object and the destination Point object.
|
* @return {Number} The distance between this Point object and the destination Point object.
|
||||||
**/
|
**/
|
||||||
public distanceTo(target: any, round?: bool = false): number {
|
public distanceTo(target: any, round?: bool = false): number {
|
||||||
@@ -418,9 +428,9 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Returns a Point object containing the coordinates of a point on the circumference of this Circle based on the given angle.
|
* Returns a Point object containing the coordinates of a point on the circumference of this Circle based on the given angle.
|
||||||
* @method circumferencePoint
|
* @method circumferencePoint
|
||||||
* @param {Number} The angle in radians (unless asDegrees is true) to return the point from.
|
* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
|
||||||
* @param {Boolean} Is the given angle in radians (false) or degrees (true)?
|
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
|
||||||
* @param {Phaser.Point} An optional Point object to put the result in to. If none specified a new Point object will be created.
|
* @param {Phaser.Point} [optional] output An optional Point object to put the result in to. If none specified a new Point object will be created.
|
||||||
* @return {Phaser.Point} The Point object holding the result.
|
* @return {Phaser.Point} The Point object holding the result.
|
||||||
**/
|
**/
|
||||||
public circumferencePoint(angle: number, asDegrees: bool = false, output?: Point = new Point): Point {
|
public circumferencePoint(angle: number, asDegrees: bool = false, output?: Point = new Point): Point {
|
||||||
|
|||||||
@@ -13,55 +13,55 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Did they intersect or not?
|
* Did they intersect or not?
|
||||||
* @property result
|
* @property result
|
||||||
* @type Boolean
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
result: bool = false;
|
result: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
x: number;
|
x: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
y: number;
|
y: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property x1
|
* @property x1
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
x1: number;
|
x1: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property y1
|
* @property y1
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
y1: number;
|
y1: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property x2
|
* @property x2
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
x2: number;
|
x2: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property y2
|
* @property y2
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
y2: number;
|
y2: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property width
|
* @property width
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
width: number;
|
width: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property height
|
* @property height
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
height: number;
|
height: number;
|
||||||
|
|
||||||
|
|||||||
+25
-25
@@ -11,7 +11,7 @@ module Phaser {
|
|||||||
export class Line {
|
export class Line {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {Number} x1
|
* @param {Number} x1
|
||||||
* @param {Number} y1
|
* @param {Number} y1
|
||||||
@@ -26,35 +26,35 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @property x1
|
* @property x1
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
public x1: number = 0;
|
public x1: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @property y1
|
* @property y1
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
public y1: number = 0;
|
public y1: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @property x2
|
* @property x2
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
public x2: number = 0;
|
public x2: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @property y2
|
* @property y2
|
||||||
* @type Number
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
public y2: number = 0;
|
public y2: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method clone
|
* @method clone
|
||||||
* @param {Phaser.Line} [output]
|
* @param {Phaser.Line} [output]
|
||||||
* @return {Phaser.Line}
|
* @return {Phaser.Line}
|
||||||
@@ -66,7 +66,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method copyFrom
|
* @method copyFrom
|
||||||
* @param {Phaser.Line} source
|
* @param {Phaser.Line} source
|
||||||
* @return {Phaser.Line}
|
* @return {Phaser.Line}
|
||||||
@@ -78,7 +78,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method copyTo
|
* @method copyTo
|
||||||
* @param {Phaser.Line} target
|
* @param {Phaser.Line} target
|
||||||
* @return {Phaser.Line}
|
* @return {Phaser.Line}
|
||||||
@@ -90,7 +90,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method setTo
|
* @method setTo
|
||||||
* @param {Number} x1
|
* @param {Number} x1
|
||||||
* @param {Number} y1
|
* @param {Number} y1
|
||||||
@@ -122,7 +122,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method length
|
* @method length
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
@@ -133,7 +133,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method getY
|
* @method getY
|
||||||
* @param {Number} x
|
* @param {Number} x
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
@@ -145,7 +145,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method angle
|
* @method angle
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
@@ -156,7 +156,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method slope
|
* @method slope
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
@@ -167,7 +167,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method perpSlope
|
* @method perpSlope
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
@@ -178,7 +178,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method yIntercept
|
* @method yIntercept
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
@@ -189,7 +189,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method isPointOnLine
|
* @method isPointOnLine
|
||||||
* @param {Number} x
|
* @param {Number} x
|
||||||
* @param {Number} y
|
* @param {Number} y
|
||||||
@@ -209,7 +209,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method isPointOnLineSegment
|
* @method isPointOnLineSegment
|
||||||
* @param {Number} x
|
* @param {Number} x
|
||||||
* @param {Number} y
|
* @param {Number} y
|
||||||
@@ -234,7 +234,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method intersectLineLine
|
* @method intersectLineLine
|
||||||
* @param {Any} line
|
* @param {Any} line
|
||||||
* @return {Any}
|
* @return {Any}
|
||||||
@@ -244,7 +244,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method perp
|
* @method perp
|
||||||
* @param {Number} x
|
* @param {Number} x
|
||||||
* @param {Number} y
|
* @param {Number} y
|
||||||
@@ -285,12 +285,12 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
var perp = this.perp()
|
var perp = this.perp()
|
||||||
return Phaser.intersectLineCircle(this,circle);
|
return Phaser.intersectLineCircle(this,circle);
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method toString
|
* @method toString
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ module Phaser {
|
|||||||
|
|
||||||
public parent: any;
|
public parent: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x coordinate of the top-left corner of the rectangle
|
* The x coordinate of the top-left corner of the rectangle
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get x(): number {
|
public get x(): number {
|
||||||
|
|
||||||
@@ -44,10 +44,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
* The y coordinate of the top-left corner of the rectangle
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get y(): number {
|
public get y(): number {
|
||||||
|
|
||||||
@@ -55,10 +55,10 @@ 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
|
* @property x
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public set x(value: number) {
|
public set x(value: number) {
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
* The y coordinate of the top-left corner of the rectangle
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public set y(value:number) {
|
public set y(value:number) {
|
||||||
|
|
||||||
|
|||||||
+30
-4
@@ -23,17 +23,17 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The horizontal position of this point (default 0)
|
* The horizontal position of this point (default 0)
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public x: number;
|
public x: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The vertical position of this point (default 0)
|
* The vertical position of this point (default 0)
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public y: number;
|
public y: number;
|
||||||
|
|
||||||
@@ -296,6 +296,32 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates the point around the x/y coordinates given to the desired angle
|
||||||
|
* @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} distance An optional distance constraint between the point and the anchor
|
||||||
|
* @return The modified point object
|
||||||
|
*/
|
||||||
|
public rotate(cx: number, cy: number, angle: number, asDegrees: bool = false, distance?:number = null) {
|
||||||
|
|
||||||
|
if (asDegrees)
|
||||||
|
{
|
||||||
|
angle = angle * GameMath.DEG_TO_RAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get distance from origin (cx/cy) to this point
|
||||||
|
if (distance === null)
|
||||||
|
{
|
||||||
|
distance = Math.sqrt(((cx - this.x) * (cx - this.x)) + ((cy - this.y) * (cy - this.y)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.setTo(cx + distance * Math.cos(angle), cy + distance * Math.sin(angle));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the x and y values of this Point object to the given coordinates.
|
* Sets the x and y values of this Point object to the given coordinates.
|
||||||
* @method setTo
|
* @method setTo
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Polygon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class Polygon {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A *convex* clockwise polygon
|
||||||
|
* @class Polygon
|
||||||
|
* @constructor
|
||||||
|
* @param {Vector2} pos A vector representing the origin of the polygon (all other points are relative to this one)
|
||||||
|
* @param {Array.<Vector2>} points An Array of vectors representing the points in the polygon, in clockwise order.
|
||||||
|
**/
|
||||||
|
constructor(pos?: Vector2 = new Vector2, points?: Vector2[] = [], parent?:any = null) {
|
||||||
|
|
||||||
|
this.pos = pos;
|
||||||
|
this.points = points;
|
||||||
|
this.parent = parent;
|
||||||
|
this.recalc();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public parent: any;
|
||||||
|
public pos: Vector2;
|
||||||
|
public points: Vector2[];
|
||||||
|
public edges: Vector2[];
|
||||||
|
public normals: Vector2[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculate the edges and normals of the polygon. This
|
||||||
|
* MUST be called if the points array is modified at all and
|
||||||
|
* the edges or normals are to be accessed.
|
||||||
|
*/
|
||||||
|
public recalc() {
|
||||||
|
|
||||||
|
var points = this.points;
|
||||||
|
var len = points.length;
|
||||||
|
|
||||||
|
this.edges = [];
|
||||||
|
this.normals = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
var p1 = points[i];
|
||||||
|
var p2 = i < len - 1 ? points[i + 1] : points[0];
|
||||||
|
var e = new Vector2().copyFrom(p2).sub(p1);
|
||||||
|
var n = new Vector2().copyFrom(e).perp().normalize();
|
||||||
|
this.edges.push(e);
|
||||||
|
this.normals.push(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+79
-5
@@ -1,4 +1,5 @@
|
|||||||
/// <reference path="../Game.ts" />
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="Polygon.ts" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phaser - Quad
|
* Phaser - Quad
|
||||||
@@ -19,7 +20,7 @@ module Phaser {
|
|||||||
* @param {Number} y The y coordinate of the top-left corner of the quad.
|
* @param {Number} y The y coordinate of the top-left corner of the quad.
|
||||||
* @param {Number} width The width of the quad.
|
* @param {Number} width The width of the quad.
|
||||||
* @param {Number} height The height of the quad.
|
* @param {Number} height The height of the quad.
|
||||||
* @return {Quad } This object
|
* @return {Quad} This object
|
||||||
**/
|
**/
|
||||||
constructor(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
constructor(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
||||||
|
|
||||||
@@ -80,13 +81,86 @@ module Phaser {
|
|||||||
* Determines whether the object specified intersects (overlaps) with this Quad object.
|
* Determines whether the object specified intersects (overlaps) with this Quad object.
|
||||||
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
|
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
|
||||||
* @method intersects
|
* @method intersects
|
||||||
* @param {Object} q The object to check for intersection with this Quad. Must have left/right/top/bottom properties (Rectangle, Quad).
|
* @param {Object} quad The object to check for intersection with this Quad. Must have left/right/top/bottom properties (Rectangle, Quad).
|
||||||
* @param {Number} t A tolerance value to allow for an intersection test with padding, default to 0
|
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
|
||||||
* @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false.
|
* @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false.
|
||||||
**/
|
**/
|
||||||
public intersects(q, t?: number = 0): bool {
|
public intersects(quad, tolerance?: number = 0): bool {
|
||||||
|
|
||||||
return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t);
|
return !(quad.left > this.right + tolerance || quad.right < this.left - tolerance || quad.top > this.bottom + tolerance || quad.bottom < this.top - tolerance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the object specified intersects (overlaps) with the given values.
|
||||||
|
* @method intersectsProps
|
||||||
|
* @param {Number} left
|
||||||
|
* @param {Number} right
|
||||||
|
* @param {Number} top
|
||||||
|
* @param {Number} bottomt
|
||||||
|
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
|
||||||
|
* @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false.
|
||||||
|
**/
|
||||||
|
public intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance?: number = 0): bool {
|
||||||
|
|
||||||
|
return !(left > this.right + tolerance || right < this.left - tolerance || top > this.bottom + tolerance || bottom < this.top - tolerance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the specified coordinates are contained within the region defined by this Quad object.
|
||||||
|
* @method contains
|
||||||
|
* @param {Number} x The x coordinate of the point to test.
|
||||||
|
* @param {Number} y The y coordinate of the point to test.
|
||||||
|
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
|
||||||
|
**/
|
||||||
|
public contains(x: number, y: number): bool {
|
||||||
|
|
||||||
|
if (x >= this.x && x <= this.right && y >= this.y && y <= this.bottom)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the x/y/width/height values from the source object into this Quad
|
||||||
|
* @method copyFrom
|
||||||
|
* @param {Any} source The source object to copy from. Can be a Quad, Rectangle or any object with exposed x/y/width/height properties
|
||||||
|
* @return {Quad} This object
|
||||||
|
**/
|
||||||
|
public copyFrom(source): Quad {
|
||||||
|
|
||||||
|
return this.setTo(source.x, source.y, source.width, source.height);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the x/y/width/height values from this Quad into the given target object
|
||||||
|
* @method copyTo
|
||||||
|
* @param {Any} target The object to copy this quads values in to. Can be a Quad, Rectangle or any object with exposed x/y/width/height properties
|
||||||
|
* @return {Any} The target object
|
||||||
|
**/
|
||||||
|
public copyTo(target): any {
|
||||||
|
|
||||||
|
return target.copyFrom(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a Polygon that is the same as this Quad.
|
||||||
|
* @method toPolygon
|
||||||
|
* @return {Polygon} A new Polygon that represents this quad.
|
||||||
|
**/
|
||||||
|
public toPolygon(): Polygon {
|
||||||
|
|
||||||
|
return new Polygon(new Vector2(this.x, this.y), [
|
||||||
|
new Vector2(), new Vector2(this.width, 0),
|
||||||
|
new Vector2(this.width, this.height), new Vector2(0, this.height)
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+60
-60
@@ -57,10 +57,10 @@ module Phaser {
|
|||||||
private _tempWidth: number = null;
|
private _tempWidth: number = null;
|
||||||
private _tempHeight: number = null;
|
private _tempHeight: number = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x coordinate of the top-left corner of the rectangle
|
* The x coordinate of the top-left corner of the rectangle
|
||||||
* @property x
|
* @property x
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get x(): number {
|
public get x(): number {
|
||||||
|
|
||||||
@@ -68,10 +68,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
* The y coordinate of the top-left corner of the rectangle
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get y(): number {
|
public get y(): number {
|
||||||
|
|
||||||
@@ -79,10 +79,10 @@ 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
|
* @property x
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public set x(value: number) {
|
public set x(value: number) {
|
||||||
|
|
||||||
@@ -90,10 +90,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
* The y coordinate of the top-left corner of the rectangle
|
||||||
* @property y
|
* @property y
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public set y(value:number) {
|
public set y(value:number) {
|
||||||
|
|
||||||
@@ -101,105 +101,105 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the top-left corner of the rectangle (same as x/y)
|
* The x and y coordinate of the top-left corner of the rectangle (same as x/y)
|
||||||
* @property topLeft
|
* @property topLeft
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public topLeft: MicroPoint;
|
public topLeft: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the top-center of the rectangle
|
* The x and y coordinate of the top-center of the rectangle
|
||||||
* @property topCenter
|
* @property topCenter
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public topCenter: MicroPoint;
|
public topCenter: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the top-right corner of the rectangle
|
* The x and y coordinate of the top-right corner of the rectangle
|
||||||
* @property topRight
|
* @property topRight
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public topRight: MicroPoint;
|
public topRight: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the left-center of the rectangle
|
* The x and y coordinate of the left-center of the rectangle
|
||||||
* @property leftCenter
|
* @property leftCenter
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public leftCenter: MicroPoint;
|
public leftCenter: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the center of the rectangle
|
* The x and y coordinate of the center of the rectangle
|
||||||
* @property center
|
* @property center
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public center: MicroPoint;
|
public center: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the right-center of the rectangle
|
* The x and y coordinate of the right-center of the rectangle
|
||||||
* @property rightCenter
|
* @property rightCenter
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public rightCenter: MicroPoint;
|
public rightCenter: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the bottom-left corner of the rectangle
|
* The x and y coordinate of the bottom-left corner of the rectangle
|
||||||
* @property bottomLeft
|
* @property bottomLeft
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public bottomLeft: MicroPoint;
|
public bottomLeft: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the bottom-center of the rectangle
|
* The x and y coordinate of the bottom-center of the rectangle
|
||||||
* @property bottomCenter
|
* @property bottomCenter
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public bottomCenter: MicroPoint;
|
public bottomCenter: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x and y coordinate of the bottom-right corner of the rectangle
|
* The x and y coordinate of the bottom-right corner of the rectangle
|
||||||
* @property bottomRight
|
* @property bottomRight
|
||||||
* @type MicroPoint
|
* @type {MicroPoint}
|
||||||
**/
|
**/
|
||||||
public bottomRight: MicroPoint;
|
public bottomRight: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the rectangle
|
* The width of the rectangle
|
||||||
* @property width
|
* @property width
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
private _width: number = 0;
|
private _width: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The height of the rectangle
|
* The height of the rectangle
|
||||||
* @property height
|
* @property height
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
private _height: number = 0;
|
private _height: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Half of the width of the rectangle
|
* Half of the width of the rectangle
|
||||||
* @property halfWidth
|
* @property halfWidth
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
private _halfWidth: number = 0;
|
private _halfWidth: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Half of the height of the rectangle
|
* Half of the height of the rectangle
|
||||||
* @property halfHeight
|
* @property halfHeight
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
private _halfHeight: number = 0;
|
private _halfHeight: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of the longest side (width or height)
|
* The size of the longest side (width or height)
|
||||||
* @property length
|
* @property length
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public length: number = 0;
|
public length: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates all of the MicroPoints based on the values of width and height.
|
* Updates all of the MicroPoints based on the values of width and height.
|
||||||
* You should not normally call this directly.
|
* You should not normally call this directly.
|
||||||
**/
|
**/
|
||||||
@@ -264,10 +264,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the rectangle
|
* The width of the rectangle
|
||||||
* @property width
|
* @property width
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public set width(value: number) {
|
public set width(value: number) {
|
||||||
|
|
||||||
@@ -277,10 +277,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The height of the rectangle
|
* The height of the rectangle
|
||||||
* @property height
|
* @property height
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public set height(value: number) {
|
public set height(value: number) {
|
||||||
|
|
||||||
@@ -290,10 +290,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the rectangle
|
* The width of the rectangle
|
||||||
* @property width
|
* @property width
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get width(): number {
|
public get width(): number {
|
||||||
|
|
||||||
@@ -301,10 +301,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The height of the rectangle
|
* The height of the rectangle
|
||||||
* @property height
|
* @property height
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get height(): number {
|
public get height(): number {
|
||||||
|
|
||||||
@@ -312,10 +312,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Half of the width of the rectangle
|
* Half of the width of the rectangle
|
||||||
* @property halfWidth
|
* @property halfWidth
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get halfWidth(): number {
|
public get halfWidth(): number {
|
||||||
|
|
||||||
@@ -323,10 +323,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Half of the height of the rectangle
|
* Half of the height of the rectangle
|
||||||
* @property halfHeight
|
* @property halfHeight
|
||||||
* @type Number
|
* @type {Number}
|
||||||
**/
|
**/
|
||||||
public get halfHeight(): number {
|
public get halfHeight(): number {
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ module Phaser {
|
|||||||
* The sum of the y and height properties.
|
* The sum of the y and height properties.
|
||||||
* Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
* Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
||||||
* @method bottom
|
* @method bottom
|
||||||
* @param {Number} value
|
* @param {Number} value
|
||||||
**/
|
**/
|
||||||
public set bottom(value: number) {
|
public set bottom(value: number) {
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ module Phaser {
|
|||||||
* Changing the left property of a Rectangle object has no effect on the y and height properties.
|
* Changing the left property of a Rectangle object has no effect on the y and height properties.
|
||||||
* However it does affect the width property, whereas changing the x value does not affect the width property.
|
* However it does affect the width property, whereas changing the x value does not affect the width property.
|
||||||
* @method left
|
* @method left
|
||||||
* @ return {number}
|
* @ return {Number}
|
||||||
**/
|
**/
|
||||||
public get left(): number {
|
public get left(): number {
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ module Phaser {
|
|||||||
* Changing the left property of a Rectangle object has no effect on the y and height properties.
|
* Changing the left property of a Rectangle object has no effect on the y and height properties.
|
||||||
* However it does affect the width property, whereas changing the x value does not affect the width property.
|
* However it does affect the width property, whereas changing the x value does not affect the width property.
|
||||||
* @method left
|
* @method left
|
||||||
* @param {Number} value
|
* @param {Number} value
|
||||||
**/
|
**/
|
||||||
public set left(value: number) {
|
public set left(value: number) {
|
||||||
|
|
||||||
@@ -411,7 +411,7 @@ module Phaser {
|
|||||||
* Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
* Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
||||||
* However it does affect the width property.
|
* However it does affect the width property.
|
||||||
* @method right
|
* @method right
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
**/
|
**/
|
||||||
public get right(): number {
|
public get right(): number {
|
||||||
|
|
||||||
@@ -424,7 +424,7 @@ module Phaser {
|
|||||||
* Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
* Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
||||||
* However it does affect the width property.
|
* However it does affect the width property.
|
||||||
* @method right
|
* @method right
|
||||||
* @param {Number} value
|
* @param {Number} value
|
||||||
**/
|
**/
|
||||||
public set right(value: number) {
|
public set right(value: number) {
|
||||||
|
|
||||||
@@ -456,7 +456,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* The volume of the Rectangle object in pixels, derived from width * height
|
* The volume of the Rectangle object in pixels, derived from width * height
|
||||||
* @method volume
|
* @method volume
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
**/
|
**/
|
||||||
public get volume(): number {
|
public get volume(): number {
|
||||||
|
|
||||||
@@ -467,7 +467,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* The perimeter size of the Rectangle object in pixels. This is the sum of all 4 sides.
|
* The perimeter size of the Rectangle object in pixels. This is the sum of all 4 sides.
|
||||||
* @method perimeter
|
* @method perimeter
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
**/
|
**/
|
||||||
public get perimeter(): number {
|
public get perimeter(): number {
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ module Phaser {
|
|||||||
* Changing the top property of a Rectangle object has no effect on the x and width properties.
|
* Changing the top property of a Rectangle object has no effect on the x and width properties.
|
||||||
* However it does affect the height property, whereas changing the y value does not affect the height property.
|
* However it does affect the height property, whereas changing the y value does not affect the height property.
|
||||||
* @method top
|
* @method top
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
**/
|
**/
|
||||||
public get top(): number {
|
public get top(): number {
|
||||||
|
|
||||||
@@ -626,7 +626,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Increases the size of the Rectangle object by the specified amounts.
|
* Increases the size of the Rectangle object by the specified amounts.
|
||||||
* The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value,
|
* The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value,
|
||||||
* and to the top and the bottom by the dy value.
|
* and to the top and the bottom by the dy value.
|
||||||
* @method inflate
|
* @method inflate
|
||||||
* @param {Number} dx The amount to be added to the left side of this Rectangle.
|
* @param {Number} dx The amount to be added to the left side of this Rectangle.
|
||||||
@@ -661,7 +661,7 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object,
|
* 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 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.
|
* returns an empty Rectangle object with its properties set to 0.
|
||||||
* @method intersection
|
* @method intersection
|
||||||
* @param {Rectangle} toIntersect The Rectangle object to compare against to see if it intersects with this Rectangle object.
|
* @param {Rectangle} toIntersect The Rectangle object to compare against to see if it intersects with this Rectangle object.
|
||||||
@@ -797,7 +797,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Returns a string representation of this object.
|
* Returns a string representation of this object.
|
||||||
* @method toString
|
* @method toString
|
||||||
* @return {string} a string representation of the instance.
|
* @return {String} a string representation of the instance.
|
||||||
**/
|
**/
|
||||||
public toString(): string {
|
public toString(): string {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="Polygon.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Response
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class Response {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object representing the result of an intersection. Contain information about:
|
||||||
|
* - The two objects participating in the intersection
|
||||||
|
* - The vector representing the minimum change necessary to extract the first object
|
||||||
|
* from the second one.
|
||||||
|
* - Whether the first object is entirely inside the second, or vice versa.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
this.a = null;
|
||||||
|
this.b = null;
|
||||||
|
this.overlapN = new Vector2;
|
||||||
|
this.overlapV = new Vector2;
|
||||||
|
|
||||||
|
this.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first object in the collision
|
||||||
|
*/
|
||||||
|
public a;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The second object in the collision
|
||||||
|
*/
|
||||||
|
public b;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The shortest colliding axis (unit-vector)
|
||||||
|
*/
|
||||||
|
public overlapN: Vector2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The overlap vector (i.e. overlapN.scale(overlap, overlap)).
|
||||||
|
* If this vector is subtracted from the position of `a`, `a` and `b` will no longer be colliding.
|
||||||
|
*/
|
||||||
|
public overlapV: Vector2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the first object is completely inside the second.
|
||||||
|
*/
|
||||||
|
public aInB: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the second object is completely inside the first.
|
||||||
|
*/
|
||||||
|
public bInA: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magnitude of the overlap on the shortest colliding axis
|
||||||
|
*/
|
||||||
|
public overlap: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set some values of the response back to their defaults. Call this between tests if
|
||||||
|
* you are going to reuse a single Response object for multiple intersection tests (recommented)
|
||||||
|
*
|
||||||
|
* @return {Response} This for chaining
|
||||||
|
*/
|
||||||
|
public clear() {
|
||||||
|
|
||||||
|
this.aInB = true;
|
||||||
|
this.bInA = true;
|
||||||
|
this.overlap = Number.MAX_VALUE;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,457 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Vector2
|
||||||
|
*
|
||||||
|
* A two dimensional vector.
|
||||||
|
* Contains methods and ideas from verlet-js by Sub Protocol, SAT.js by Jim Riecken and N by Metanet Software. Brandon Jones, Colin MacKenzie IV
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class Vector2 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Vector2 object.
|
||||||
|
* @class Vector2
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x position of the vector
|
||||||
|
* @param {Number} y The y position of the vector
|
||||||
|
* @return {Vector2} This object
|
||||||
|
**/
|
||||||
|
constructor(x: number = 0, y: number = 0) {
|
||||||
|
|
||||||
|
//var GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public x: number;
|
||||||
|
public y: number;
|
||||||
|
|
||||||
|
public setTo(x: number, y: number): Vector2 {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add this vector to the given one and return the result.
|
||||||
|
*
|
||||||
|
* @param {Vector2} v The other Vector.
|
||||||
|
* @param {Vector2} The output Vector.
|
||||||
|
* @return {Vector2} The new Vector
|
||||||
|
*/
|
||||||
|
public add(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||||
|
return output.setTo(this.x + v.x, this.y + v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtract this vector to the given one and return the result.
|
||||||
|
*
|
||||||
|
* @param {Vector2} v The other Vector.
|
||||||
|
* @param {Vector2} The output Vector.
|
||||||
|
* @return {Vector2} The new Vector
|
||||||
|
*/
|
||||||
|
public sub(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||||
|
return output.setTo(this.x - v.x, this.y - v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiply this vector with the given one and return the result.
|
||||||
|
*
|
||||||
|
* @param {Vector2} v The other Vector.
|
||||||
|
* @param {Vector2} The output Vector.
|
||||||
|
* @return {Vector2} The new Vector
|
||||||
|
*/
|
||||||
|
public mul(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||||
|
return output.setTo(this.x * v.x, this.y * v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divide this vector by the given one and return the result.
|
||||||
|
*
|
||||||
|
* @param {Vector2} v The other Vector.
|
||||||
|
* @param {Vector2} The output Vector.
|
||||||
|
* @return {Vector2} The new Vector
|
||||||
|
*/
|
||||||
|
public div(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||||
|
return output.setTo(this.x / v.x, this.y / v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale this vector by the given values and return the result.
|
||||||
|
*
|
||||||
|
* @param {number} x The scaling factor in the x direction.
|
||||||
|
* @param {?number=} y The scaling factor in the y direction. If this
|
||||||
|
* is not specified, the x scaling factor will be used.
|
||||||
|
* @return {Vector} The new Vector
|
||||||
|
*/
|
||||||
|
public scale(x: number, y?:number = null, output?:Vector2 = new Vector2): Vector2 {
|
||||||
|
|
||||||
|
if (y === null)
|
||||||
|
{
|
||||||
|
y = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.setTo(this.x * x, this.y * y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate this vector by 90 degrees
|
||||||
|
*
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public perp(output?: Vector2 = this): Vector2 {
|
||||||
|
var x = this.x;
|
||||||
|
return output.setTo(this.y, -x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same as copyFrom, used by VerletManager
|
||||||
|
public mutableSet(v: Vector2): Vector2 {
|
||||||
|
this.x = v.x;
|
||||||
|
this.y = v.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add another vector to this one.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The other Vector.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableAdd(v: Vector2): Vector2 {
|
||||||
|
this.x += v.x;
|
||||||
|
this.y += v.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtract another vector from this one.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The other Vector.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableSub(v: Vector2): Vector2 {
|
||||||
|
this.x -= v.x;
|
||||||
|
this.y -= v.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiply another vector with this one.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The other Vector.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableMul(v: Vector2): Vector2 {
|
||||||
|
this.x *= v.x;
|
||||||
|
this.y *= v.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divide this vector by another one.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The other Vector.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableDiv(v: Vector2): Vector2 {
|
||||||
|
this.x /= v.x;
|
||||||
|
this.y /= v.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale this vector.
|
||||||
|
*
|
||||||
|
* @param {number} x The scaling factor in the x direction.
|
||||||
|
* @param {?number=} y The scaling factor in the y direction. If this
|
||||||
|
* is not specified, the x scaling factor will be used.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableScale(x: number, y?:number): Vector2 {
|
||||||
|
this.x *= x;
|
||||||
|
this.y *= y || x;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiply this vector by the given scalar.
|
||||||
|
*
|
||||||
|
* @param {number} scalar
|
||||||
|
* @return {Vector2} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableMultiplyByScalar(scalar: number): Vector2 {
|
||||||
|
this.x *= scalar;
|
||||||
|
this.y *= scalar;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divide this vector by the given scalar.
|
||||||
|
*
|
||||||
|
* @param {number} scalar
|
||||||
|
* @return {Vector2} This for chaining.
|
||||||
|
*/
|
||||||
|
public mutableDivideByScalar(scalar: number): Vector2 {
|
||||||
|
this.x /= scalar;
|
||||||
|
this.y /= scalar;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse this vector.
|
||||||
|
*
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public reverse(): Vector2 {
|
||||||
|
this.x = -this.x;
|
||||||
|
this.y = -this.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public edge(v: Vector2, output?: Vector2 = new Vector2): Vector2 {
|
||||||
|
return this.sub(v, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public equals(v: Vector2): bool {
|
||||||
|
return this.x == v.x && this.y == v.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public epsilonEquals(v: Vector2, epsilon:number): bool {
|
||||||
|
return Math.abs(this.x - v.x) <= epsilon && Math.abs(this.y - v.y) <= epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the length of this vector.
|
||||||
|
*
|
||||||
|
* @return {number} The length of this vector.
|
||||||
|
*/
|
||||||
|
public length(): number {
|
||||||
|
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the length^2 of this vector.
|
||||||
|
*
|
||||||
|
* @return {number} The length^2 of this vector.
|
||||||
|
*/
|
||||||
|
public length2(): number {
|
||||||
|
return (this.x * this.x) + (this.y * this.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the distance between this vector and the given vector.
|
||||||
|
*
|
||||||
|
* @return {Vector2} v The vector to check
|
||||||
|
*/
|
||||||
|
public distance(v: Vector2): number {
|
||||||
|
return Math.sqrt(this.distance2(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the distance^2 between this vector and the given vector.
|
||||||
|
*
|
||||||
|
* @return {Vector2} v The vector to check
|
||||||
|
*/
|
||||||
|
public distance2(v: Vector2): number {
|
||||||
|
return ((v.x - this.x) * (v.x - this.x)) + ((v.y - this.y) * (v.y - this.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project this vector on to another vector.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The vector to project onto.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public project(other: Vector2): Vector2 {
|
||||||
|
|
||||||
|
var amt = this.dot(other) / other.length2();
|
||||||
|
|
||||||
|
if (amt != 0)
|
||||||
|
{
|
||||||
|
this.x = amt * other.x;
|
||||||
|
this.y = amt * other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project this vector onto a vector of unit length.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The unit vector to project onto.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public projectN(other: Vector2): Vector2 {
|
||||||
|
|
||||||
|
var amt = this.dot(other);
|
||||||
|
|
||||||
|
if (amt != 0)
|
||||||
|
{
|
||||||
|
this.x = amt * other.x;
|
||||||
|
this.y = amt * other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflect this vector on an arbitrary axis.
|
||||||
|
*
|
||||||
|
* @param {Vector} axis The vector representing the axis.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public reflect(axis): Vector2 {
|
||||||
|
|
||||||
|
var x = this.x;
|
||||||
|
var y = this.y;
|
||||||
|
this.project(axis).scale(2);
|
||||||
|
this.x -= x;
|
||||||
|
this.y -= y;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflect this vector on an arbitrary axis (represented by a unit vector)
|
||||||
|
*
|
||||||
|
* @param {Vector} axis The unit vector representing the axis.
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public reflectN(axis): Vector2 {
|
||||||
|
|
||||||
|
var x = this.x;
|
||||||
|
var y = this.y;
|
||||||
|
this.projectN(axis).scale(2);
|
||||||
|
this.x -= x;
|
||||||
|
this.y -= y;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public getProjectionMagnitude(v: Vector2): number {
|
||||||
|
|
||||||
|
var den = v.dot(v);
|
||||||
|
|
||||||
|
if (den == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Math.abs(this.dot(v) / den);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public direction(output?: Vector2 = new Vector2): Vector2 {
|
||||||
|
|
||||||
|
output.copyFrom(this);
|
||||||
|
return this.normalize(output);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public normalRightHand(output?: Vector2 = this): Vector2 {
|
||||||
|
return output.setTo(this.y * -1, this.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize (make unit length) this vector.
|
||||||
|
*
|
||||||
|
* @return {Vector} This for chaining.
|
||||||
|
*/
|
||||||
|
public normalize(output?: Vector2 = this): Vector2 {
|
||||||
|
|
||||||
|
var m = this.length();
|
||||||
|
|
||||||
|
if (m != 0)
|
||||||
|
{
|
||||||
|
output.setTo(this.x / m, this.y / m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMagnitude(): number {
|
||||||
|
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the dot product of this vector against another.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The vector to dot this one against.
|
||||||
|
* @return {number} The dot product.
|
||||||
|
*/
|
||||||
|
public dot(v: Vector2): number {
|
||||||
|
return ((this.x * v.x) + (this.y * v.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cross product of this vector against another.
|
||||||
|
*
|
||||||
|
* @param {Vector} other The vector to cross this one against.
|
||||||
|
* @return {number} The cross product.
|
||||||
|
*/
|
||||||
|
public cross(v: Vector2): number {
|
||||||
|
return ((this.x * v.y) - (this.y * v.x));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the angle between this vector and the given vector.
|
||||||
|
*
|
||||||
|
* @return {Vector2} v The vector to check
|
||||||
|
*/
|
||||||
|
public angle(v: Vector2): number {
|
||||||
|
return Math.atan2(this.x * v.y - this.y * v.x, this.x * v.x + this.y * v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public angle2(vLeft: Vector2, vRight: Vector2): number {
|
||||||
|
return vLeft.sub(this).angle(vRight.sub(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate this vector around the origin to the given angle (theta) and return the result in a new Vector
|
||||||
|
*
|
||||||
|
* @return {Vector2} v The vector to check
|
||||||
|
*/
|
||||||
|
public rotate(origin, theta, output?: Vector2 = new Vector2): Vector2 {
|
||||||
|
var x = this.x - origin.x;
|
||||||
|
var y = this.y - origin.y;
|
||||||
|
return output.setTo(x * Math.cos(theta) - y * Math.sin(theta) + origin.x, x * Math.sin(theta) + y * Math.cos(theta) + origin.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public clone(output?: Vector2 = new Vector2): Vector2 {
|
||||||
|
return output.setTo(this.x, this.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public copyFrom(v: Vector2): Vector2 {
|
||||||
|
this.x = v.x;
|
||||||
|
this.y = v.y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public copyTo(v: Vector2): Vector2 {
|
||||||
|
return v.setTo(this.x, this.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of this object.
|
||||||
|
* @method toString
|
||||||
|
* @return {string} a string representation of the object.
|
||||||
|
**/
|
||||||
|
public toString(): string {
|
||||||
|
return "[{Vector2 (x=" + this.x + " y=" + this.y + ")}]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Phaser
|
* Phaser
|
||||||
*
|
*
|
||||||
* v0.9.5 - April 28th 2013
|
* v0.9.6 - May 21st 2013
|
||||||
*
|
*
|
||||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||||
*
|
*
|
||||||
@@ -15,5 +15,5 @@
|
|||||||
*/
|
*/
|
||||||
var Phaser;
|
var Phaser;
|
||||||
(function (Phaser) {
|
(function (Phaser) {
|
||||||
Phaser.VERSION = 'Phaser version 0.9.5';
|
Phaser.VERSION = 'Phaser version 0.9.6';
|
||||||
})(Phaser || (Phaser = {}));
|
})(Phaser || (Phaser = {}));
|
||||||
|
|||||||
+212
-28
@@ -14,14 +14,16 @@ module Phaser {
|
|||||||
export class Camera {
|
export class Camera {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new camera at the specified location, with the specified size and zoom level.
|
*Sprite constructor
|
||||||
*
|
* Instantiates a new camera at the specified location, with the specified size and zoom level.
|
||||||
* @param X X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
*
|
||||||
* @param Y Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
* @param game {Phaser.Game} Current game instance.
|
||||||
* @param Width The width of the camera display in pixels.
|
* @param id {number} Unique identity.
|
||||||
* @param Height The height of the camera display in pixels.
|
* @param x {number} X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
||||||
* @param Zoom The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.
|
* @param y {number} Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
||||||
*/
|
* @param width {number} The width of the camera display in pixels.
|
||||||
|
* @param height {number} The height of the camera display in pixels.
|
||||||
|
*/
|
||||||
constructor(game: Game, id: number, x: number, y: number, width: number, height: number) {
|
constructor(game: Game, id: number, x: number, y: number, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -38,6 +40,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to Game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
private _clip: bool = false;
|
private _clip: bool = false;
|
||||||
@@ -48,45 +53,180 @@ module Phaser {
|
|||||||
private _sx: number = 0;
|
private _sx: number = 0;
|
||||||
private _sy: number = 0;
|
private _sy: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static STYLE_LOCKON: number = 0;
|
public static STYLE_LOCKON: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera "follow" style preset: camera deadzone is narrow but tall.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static STYLE_PLATFORMER: number = 1;
|
public static STYLE_PLATFORMER: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera "follow" style preset: camera deadzone is a medium-size square around the focus object.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static STYLE_TOPDOWN: number = 2;
|
public static STYLE_TOPDOWN: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera "follow" style preset: camera deadzone is a small square around the focus object.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static STYLE_TOPDOWN_TIGHT: number = 3;
|
public static STYLE_TOPDOWN_TIGHT: number = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identity of this camera.
|
||||||
|
*/
|
||||||
public ID: number;
|
public ID: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera view rectangle in world coordinate.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public worldView: Rectangle;
|
public worldView: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many sprites will be rendered by this camera.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public totalSpritesRendered: number;
|
public totalSpritesRendered: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale factor of the camera.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public scale: MicroPoint = new MicroPoint(1, 1);
|
public scale: MicroPoint = new MicroPoint(1, 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scrolling factor.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public scroll: MicroPoint = new MicroPoint(0, 0);
|
public scroll: MicroPoint = new MicroPoint(0, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera bounds.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public bounds: Rectangle = null;
|
public bounds: Rectangle = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sprite moving inside this rectangle will not cause camera moving.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public deadzone: Rectangle = null;
|
public deadzone: Rectangle = null;
|
||||||
|
|
||||||
// Camera Border
|
// Camera Border
|
||||||
public disableClipping: bool = false;
|
public disableClipping: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether render border of this camera or not. (default is false)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public showBorder: bool = false;
|
public showBorder: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color of border of this camera. (in css color string)
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public borderColor: string = 'rgb(255,255,255)';
|
public borderColor: string = 'rgb(255,255,255)';
|
||||||
|
|
||||||
// Camera Background Color
|
/**
|
||||||
public opaque: bool = true;
|
* Whether the camera background is opaque or not. If set to true the Camera is filled with
|
||||||
|
* the value of Camera.backgroundColor every frame.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
public opaque: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the camera every frame using a canvas clearRect call (default to true).
|
||||||
|
* Note that this erases anything below the camera as well, so do not use it in conjuction with a camera
|
||||||
|
* that uses alpha or that needs to be able to manage opacity. Equally if Camera.opaque is set to true
|
||||||
|
* then set Camera.clear to false to save rendering time.
|
||||||
|
* By default the Stage will clear itself every frame, so be sure not to double-up clear calls.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
public clear: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background color in css color string.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
private _bgColor: string = 'rgb(0,0,0)';
|
private _bgColor: string = 'rgb(0,0,0)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background texture to be rendered if background is visible.
|
||||||
|
*/
|
||||||
private _bgTexture;
|
private _bgTexture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background texture repeat style. (default is 'repeat')
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
private _bgTextureRepeat: string = 'repeat';
|
private _bgTextureRepeat: string = 'repeat';
|
||||||
|
|
||||||
// Camera Shadow
|
// Camera Shadow
|
||||||
|
/**
|
||||||
|
* Render camera shadow or not. (default is false)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public showShadow: bool = false;
|
public showShadow: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color of shadow, in css color string.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public shadowColor: string = 'rgb(0,0,0)';
|
public shadowColor: string = 'rgb(0,0,0)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blur factor of shadow.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public shadowBlur: number = 10;
|
public shadowBlur: number = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offset of the shadow from camera's position.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
public shadowOffset: MicroPoint = new MicroPoint(4, 4);
|
public shadowOffset: MicroPoint = new MicroPoint(4, 4);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this camera visible or not. (default is true)
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public visible: bool = true;
|
public visible: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alpha of the camera. (everything rendered to this camera will be affected)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public alpha: number = 1;
|
public alpha: number = 1;
|
||||||
|
|
||||||
// The x/y position of the current input event in world coordinates
|
/**
|
||||||
|
* The x position of the current input event in world coordinates.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public inputX: number = 0;
|
public inputX: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The y position of the current input event in world coordinates.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public inputY: number = 0;
|
public inputY: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effects manager.
|
||||||
|
* @type {FXManager}
|
||||||
|
*/
|
||||||
public fx: FXManager;
|
public fx: FXManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells this camera object what sprite to track.
|
||||||
|
* @param target {Sprite} The object you want the camera to track. Set to null to not follow anything.
|
||||||
|
* @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
|
||||||
|
*/
|
||||||
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
|
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
|
||||||
|
|
||||||
this._target = target;
|
this._target = target;
|
||||||
@@ -116,6 +256,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the camera focus to this location instantly.
|
||||||
|
* @param x {number} X position.
|
||||||
|
* @param y {number} Y position.
|
||||||
|
*/
|
||||||
public focusOnXY(x: number, y: number) {
|
public focusOnXY(x: number, y: number) {
|
||||||
|
|
||||||
x += (x > 0) ? 0.0000001 : -0.0000001;
|
x += (x > 0) ? 0.0000001 : -0.0000001;
|
||||||
@@ -126,6 +271,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the camera focus to this location instantly.
|
||||||
|
* @param point {any} Point you want to focus.
|
||||||
|
*/
|
||||||
public focusOn(point) {
|
public focusOn(point) {
|
||||||
|
|
||||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||||
@@ -138,11 +287,11 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the boundaries of the world or where the camera is allowed to move.
|
* Specify the boundaries of the world or where the camera is allowed to move.
|
||||||
*
|
*
|
||||||
* @param x The smallest X value of your world (usually 0).
|
* @param x {number} The smallest X value of your world (usually 0).
|
||||||
* @param y The smallest Y value of your world (usually 0).
|
* @param y {number} The smallest Y value of your world (usually 0).
|
||||||
* @param width The largest X value of your world (usually the world width).
|
* @param width {number} The largest X value of your world (usually the world width).
|
||||||
* @param height The largest Y value of your world (usually the world height).
|
* @param height {number} The largest Y value of your world (usually the world height).
|
||||||
*/
|
*/
|
||||||
public setBounds(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
public setBounds(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
||||||
|
|
||||||
@@ -158,6 +307,9 @@ module Phaser {
|
|||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update focusing and scrolling.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
this.fx.preUpdate();
|
this.fx.preUpdate();
|
||||||
@@ -166,7 +318,7 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (this.deadzone == null)
|
if (this.deadzone == null)
|
||||||
{
|
{
|
||||||
this.focusOnXY(this._target.x + this._target.origin.x, this._target.y + this._target.origin.y);
|
this.focusOnXY(this._target.x, this._target.y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -240,6 +392,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw background, shadow, effects, and objects if this is visible.
|
||||||
|
*/
|
||||||
public render() {
|
public render() {
|
||||||
|
|
||||||
if (this.visible === false || this.alpha < 0.1)
|
if (this.visible === false || this.alpha < 0.1)
|
||||||
@@ -247,13 +402,13 @@ module Phaser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
|
if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
|
||||||
//{
|
{
|
||||||
//this._game.stage.context.save();
|
this._game.stage.context.save();
|
||||||
//}
|
}
|
||||||
|
|
||||||
// It may be safer/quicker to just save the context every frame regardless (needs testing on mobile)
|
// It may be safer/quicker to just save the context every frame regardless (needs testing on mobile - sucked on Android 2.x)
|
||||||
this._game.stage.context.save();
|
//this._game.stage.context.save();
|
||||||
|
|
||||||
this.fx.preRender(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
|
this.fx.preRender(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
|
||||||
|
|
||||||
@@ -266,7 +421,7 @@ module Phaser {
|
|||||||
this._sy = this._stageY;
|
this._sy = this._stageY;
|
||||||
|
|
||||||
// Shadow
|
// Shadow
|
||||||
if (this.showShadow)
|
if (this.showShadow == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.shadowColor = this.shadowColor;
|
this._game.stage.context.shadowColor = this.shadowColor;
|
||||||
this._game.stage.context.shadowBlur = this.shadowBlur;
|
this._game.stage.context.shadowBlur = this.shadowBlur;
|
||||||
@@ -292,6 +447,11 @@ module Phaser {
|
|||||||
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
|
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.clear == true)
|
||||||
|
{
|
||||||
|
this._game.stage.context.clearRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||||
|
}
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
if (this.opaque == true)
|
if (this.opaque == true)
|
||||||
{
|
{
|
||||||
@@ -308,7 +468,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shadow off
|
// Shadow off
|
||||||
if (this.showShadow)
|
if (this.showShadow == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.shadowBlur = 0;
|
this._game.stage.context.shadowBlur = 0;
|
||||||
this._game.stage.context.shadowOffsetX = 0;
|
this._game.stage.context.shadowOffsetX = 0;
|
||||||
@@ -318,7 +478,7 @@ module Phaser {
|
|||||||
this.fx.render(this, this._stageX, this._stageY, 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
|
// Clip the camera so we don't get sprites appearing outside the edges
|
||||||
if (this._clip && this.disableClipping == false)
|
if (this._clip == true && this.disableClipping == false)
|
||||||
{
|
{
|
||||||
this._game.stage.context.beginPath();
|
this._game.stage.context.beginPath();
|
||||||
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||||
@@ -328,7 +488,7 @@ module Phaser {
|
|||||||
|
|
||||||
this._game.world.group.render(this, this._sx, this._sy);
|
this._game.world.group.render(this, this._sx, this._sy);
|
||||||
|
|
||||||
if (this.showBorder)
|
if (this.showBorder == true)
|
||||||
{
|
{
|
||||||
this._game.stage.context.strokeStyle = this.borderColor;
|
this._game.stage.context.strokeStyle = this.borderColor;
|
||||||
this._game.stage.context.lineWidth = 1;
|
this._game.stage.context.lineWidth = 1;
|
||||||
@@ -349,7 +509,10 @@ module Phaser {
|
|||||||
this._game.stage.context.translate(0, 0);
|
this._game.stage.context.translate(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._game.stage.context.restore();
|
if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
|
||||||
|
{
|
||||||
|
this._game.stage.context.restore();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.alpha !== 1)
|
if (this.alpha !== 1)
|
||||||
{
|
{
|
||||||
@@ -368,6 +531,11 @@ module Phaser {
|
|||||||
return this._bgColor;
|
return this._bgColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set camera background texture.
|
||||||
|
* @param key {string} Asset key of the texture.
|
||||||
|
* @param [repeat] {string} what kind of repeat will this texture used for background.
|
||||||
|
*/
|
||||||
public setTexture(key: string, repeat?: string = 'repeat') {
|
public setTexture(key: string, repeat?: string = 'repeat') {
|
||||||
|
|
||||||
this._bgTexture = this._game.stage.context.createPattern(this._game.cache.getImage(key), repeat);
|
this._bgTexture = this._game.stage.context.createPattern(this._game.cache.getImage(key), repeat);
|
||||||
@@ -375,6 +543,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set position of this camera.
|
||||||
|
* @param x {number} X position.
|
||||||
|
* @param y {number} Y position.
|
||||||
|
*/
|
||||||
public setPosition(x: number, y: number) {
|
public setPosition(x: number, y: number) {
|
||||||
|
|
||||||
this._stageX = x;
|
this._stageX = x;
|
||||||
@@ -384,6 +557,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
public setSize(width: number, height: number) {
|
||||||
|
|
||||||
this.worldView.width = width;
|
this.worldView.width = width;
|
||||||
@@ -392,6 +570,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render debug infos. (including id, position, rotation, scrolling factor, bounds 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)') {
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||||
|
|
||||||
this._game.stage.context.fillStyle = color;
|
this._game.stage.context.fillStyle = color;
|
||||||
|
|||||||
@@ -0,0 +1,501 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - CollisionMask
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class CollisionMask {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CollisionMask constructor. Creates a new <code>CollisionMask</code> for the given GameObject.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param parent {Phaser.GameObject} The GameObject this CollisionMask belongs to.
|
||||||
|
* @param x {number} The initial x position of the CollisionMask.
|
||||||
|
* @param y {number} The initial y position of the CollisionMask.
|
||||||
|
* @param width {number} The width of the CollisionMask.
|
||||||
|
* @param height {number} The height of the CollisionMask.
|
||||||
|
*/
|
||||||
|
constructor(game: Game, parent: GameObject, x: number, y: number, width: number, height: number) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
this._parent = parent;
|
||||||
|
|
||||||
|
// By default the CollisionMask is a quad
|
||||||
|
this.type = CollisionMask.QUAD;
|
||||||
|
|
||||||
|
this.quad = new Phaser.Quad(this._parent.x, this._parent.y, this._parent.width, this._parent.height);
|
||||||
|
this.offset = new MicroPoint(0, 0);
|
||||||
|
this.last = new MicroPoint(0, 0);
|
||||||
|
|
||||||
|
this._ref = this.quad;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private _game;
|
||||||
|
private _parent;
|
||||||
|
|
||||||
|
// An internal reference to the active collision shape
|
||||||
|
private _ref;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Geom type of this sprite. (available: QUAD, POINT, CIRCLE, LINE, RECTANGLE, POLYGON)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public type: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quad (a smaller version of Rectangle).
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static QUAD: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static POINT: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Circle.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static CIRCLE: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Line.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static LINE: number = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rectangle.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static RECTANGLE: number = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polygon.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public static POLYGON: number = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rectangle shape container. A Rectangle instance.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
|
public quad: Quad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Point shape container. A Point instance.
|
||||||
|
* @type {Point}
|
||||||
|
*/
|
||||||
|
public point: Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Circle shape container. A Circle instance.
|
||||||
|
* @type {Circle}
|
||||||
|
*/
|
||||||
|
public circle: Circle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Line shape container. A Line instance.
|
||||||
|
* @type {Line}
|
||||||
|
*/
|
||||||
|
public line: Line;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rectangle shape container. A Rectangle instance.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
|
public rect: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value from the top-left of the GameObject frame that this collisionMask is offset to.
|
||||||
|
* If the CollisionMask is a Quad/Rectangle the offset relates to the top-left of that Quad.
|
||||||
|
* If the CollisionMask is a Circle the offset relates to the center of the circle.
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
|
public offset: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The previous x/y coordinates of the CollisionMask, used for hull calculations
|
||||||
|
* @type {MicroPoint}
|
||||||
|
*/
|
||||||
|
public last: MicroPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a circle shape with specific diameter.
|
||||||
|
* @param diameter {number} Diameter of the circle.
|
||||||
|
* @return {CollisionMask} This
|
||||||
|
*/
|
||||||
|
createCircle(diameter: number): CollisionMask {
|
||||||
|
|
||||||
|
this.type = CollisionMask.CIRCLE;
|
||||||
|
this.circle = new Circle(this.last.x, this.last.y, diameter);
|
||||||
|
this._ref = this.circle;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-update is called right before update() on each object in the game loop.
|
||||||
|
*/
|
||||||
|
public preUpdate() {
|
||||||
|
|
||||||
|
this.last.x = this.x;
|
||||||
|
this.last.y = this.y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
|
||||||
|
this._ref.x = this._parent.x + this.offset.x;
|
||||||
|
this._ref.y = this._parent.y + this.offset.y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
|
||||||
|
* @param camera {Camera} Camera the bound will be rendered to.
|
||||||
|
* @param cameraOffsetX {number} X offset of bound to the camera.
|
||||||
|
* @param cameraOffsetY {number} Y offset of bound to the camera.
|
||||||
|
*/
|
||||||
|
public render(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) {
|
||||||
|
|
||||||
|
var _dx = cameraOffsetX + (this.x - camera.worldView.x);
|
||||||
|
var _dy = cameraOffsetY + (this.y - camera.worldView.y);
|
||||||
|
|
||||||
|
this._parent.context.fillStyle = this._parent.renderDebugColor;
|
||||||
|
|
||||||
|
if (this.type == CollisionMask.QUAD)
|
||||||
|
{
|
||||||
|
this._parent.context.fillRect(_dx, _dy, this.width, this.height);
|
||||||
|
}
|
||||||
|
else if (this.type == CollisionMask.CIRCLE)
|
||||||
|
{
|
||||||
|
this._parent.context.beginPath();
|
||||||
|
this._parent.context.arc(_dx, _dy, this.circle.radius, 0, Math.PI * 2);
|
||||||
|
this._parent.context.fill();
|
||||||
|
this._parent.context.closePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy all objects and references belonging to this CollisionMask
|
||||||
|
*/
|
||||||
|
public destroy() {
|
||||||
|
|
||||||
|
this._game = null;
|
||||||
|
this._parent = null;
|
||||||
|
this._ref = null;
|
||||||
|
this.quad = null;
|
||||||
|
this.point = null;
|
||||||
|
this.circle = null;
|
||||||
|
this.rect = null;
|
||||||
|
this.line = null;
|
||||||
|
this.offset = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public intersectsRaw(left: number, right: number, top: number, bottom: number): bool {
|
||||||
|
|
||||||
|
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public intersectsVector(vector: Phaser.Vector2): bool {
|
||||||
|
|
||||||
|
if (this.type == CollisionMask.QUAD)
|
||||||
|
{
|
||||||
|
return this.quad.contains(vector.x, vector.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives a basic boolean response to a geometric collision.
|
||||||
|
* If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
||||||
|
* @param source {GeomSprite} Sprite you want to check.
|
||||||
|
* @return {boolean} Whether they overlaps or not.
|
||||||
|
*/
|
||||||
|
public intersects(source: CollisionMask): bool {
|
||||||
|
|
||||||
|
// Quad vs. Quad
|
||||||
|
if (this.type == CollisionMask.QUAD && source.type == CollisionMask.QUAD)
|
||||||
|
{
|
||||||
|
return this.quad.intersects(source.quad);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Circle vs. Circle
|
||||||
|
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.CIRCLE)
|
||||||
|
{
|
||||||
|
return Collision.circleToCircle(this.circle, source.circle).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Circle vs. Rect
|
||||||
|
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.RECTANGLE)
|
||||||
|
{
|
||||||
|
return Collision.circleToRectangle(this.circle, source.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Circle vs. Point
|
||||||
|
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.POINT)
|
||||||
|
{
|
||||||
|
return Collision.circleContainsPoint(this.circle, source.point).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Circle vs. Line
|
||||||
|
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.LINE)
|
||||||
|
{
|
||||||
|
return Collision.lineToCircle(source.line, this.circle).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rect vs. Rect
|
||||||
|
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.RECTANGLE)
|
||||||
|
{
|
||||||
|
return Collision.rectangleToRectangle(this.rect, source.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rect vs. Circle
|
||||||
|
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.CIRCLE)
|
||||||
|
{
|
||||||
|
return Collision.circleToRectangle(source.circle, this.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rect vs. Point
|
||||||
|
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.POINT)
|
||||||
|
{
|
||||||
|
return Collision.pointToRectangle(source.point, this.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rect vs. Line
|
||||||
|
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.LINE)
|
||||||
|
{
|
||||||
|
return Collision.lineToRectangle(source.line, this.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Point vs. Point
|
||||||
|
if (this.type == CollisionMask.POINT && source.type == CollisionMask.POINT)
|
||||||
|
{
|
||||||
|
return this.point.equals(source.point);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Point vs. Circle
|
||||||
|
if (this.type == CollisionMask.POINT && source.type == CollisionMask.CIRCLE)
|
||||||
|
{
|
||||||
|
return Collision.circleContainsPoint(source.circle, this.point).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Point vs. Rect
|
||||||
|
if (this.type == CollisionMask.POINT && source.type == CollisionMask.RECTANGLE)
|
||||||
|
{
|
||||||
|
return Collision.pointToRectangle(this.point, source.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Point vs. Line
|
||||||
|
if (this.type == CollisionMask.POINT && source.type == CollisionMask.LINE)
|
||||||
|
{
|
||||||
|
return source.line.isPointOnLine(this.point.x, this.point.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line vs. Line
|
||||||
|
if (this.type == CollisionMask.LINE && source.type == CollisionMask.LINE)
|
||||||
|
{
|
||||||
|
return Collision.lineSegmentToLineSegment(this.line, source.line).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line vs. Circle
|
||||||
|
if (this.type == CollisionMask.LINE && source.type == CollisionMask.CIRCLE)
|
||||||
|
{
|
||||||
|
return Collision.lineToCircle(this.line, source.circle).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line vs. Rect
|
||||||
|
if (this.type == CollisionMask.LINE && source.type == CollisionMask.RECTANGLE)
|
||||||
|
{
|
||||||
|
return Collision.lineSegmentToRectangle(this.line, source.rect).result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line vs. Point
|
||||||
|
if (this.type == CollisionMask.LINE && source.type == CollisionMask.POINT)
|
||||||
|
{
|
||||||
|
return this.line.isPointOnLine(source.point.x, source.point.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public checkHullIntersection(mask: CollisionMask): bool {
|
||||||
|
|
||||||
|
if ((this.hullX + this.hullWidth > mask.hullX) && (this.hullX < mask.hullX + mask.width) && (this.hullY + this.hullHeight > mask.hullY) && (this.hullY < mask.hullY + mask.hullHeight))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public get hullWidth(): number {
|
||||||
|
|
||||||
|
if (this.deltaX > 0)
|
||||||
|
{
|
||||||
|
return this.width + this.deltaX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.width - this.deltaX;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public get hullHeight(): number {
|
||||||
|
|
||||||
|
if (this.deltaY > 0)
|
||||||
|
{
|
||||||
|
return this.height + this.deltaY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.height - this.deltaY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public get hullX(): number {
|
||||||
|
|
||||||
|
if (this.x < this.last.x)
|
||||||
|
{
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.last.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public get hullY(): number {
|
||||||
|
|
||||||
|
if (this.y < this.last.y)
|
||||||
|
{
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.last.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public get deltaXAbs(): number {
|
||||||
|
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get deltaYAbs(): number {
|
||||||
|
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get deltaX(): number {
|
||||||
|
return this.x - this.last.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get deltaY(): number {
|
||||||
|
return this.y - this.last.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get x(): number {
|
||||||
|
return this._ref.x;
|
||||||
|
//return this.quad.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set x(value: number) {
|
||||||
|
this._ref.x = value;
|
||||||
|
//this.quad.x = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get y(): number {
|
||||||
|
return this._ref.y;
|
||||||
|
//return this.quad.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set y(value: number) {
|
||||||
|
this._ref.y = value;
|
||||||
|
//this.quad.y = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public get rotation(): number {
|
||||||
|
// return this._angle;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public set rotation(value: number) {
|
||||||
|
// this._angle = this._game.math.wrap(value, 360, 0);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public get angle(): number {
|
||||||
|
// return this._angle;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public set angle(value: number) {
|
||||||
|
// this._angle = this._game.math.wrap(value, 360, 0);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public set width(value:number) {
|
||||||
|
//this.quad.width = value;
|
||||||
|
this._ref.width = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set height(value:number) {
|
||||||
|
//this.quad.height = value;
|
||||||
|
this._ref.height = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get width(): number {
|
||||||
|
//return this.quad.width;
|
||||||
|
return this._ref.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get height(): number {
|
||||||
|
//return this.quad.height;
|
||||||
|
return this._ref.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get left(): number {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get right(): number {
|
||||||
|
return this.x + this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get top(): number {
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get bottom(): number {
|
||||||
|
return this.y + this.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get halfWidth(): number {
|
||||||
|
return this.width / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get halfHeight(): number {
|
||||||
|
return this.height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+163
-169
@@ -12,10 +12,8 @@ module Phaser {
|
|||||||
export class Device {
|
export class Device {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Device constructor
|
||||||
* @constructor
|
*/
|
||||||
* @return {Device} This Object
|
|
||||||
*/
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
this._checkAudio();
|
this._checkAudio();
|
||||||
@@ -29,260 +27,235 @@ module Phaser {
|
|||||||
|
|
||||||
// Operating System
|
// Operating System
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is running desktop?
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public desktop: bool = false;
|
public desktop: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on iOS?
|
||||||
* @property iOS
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public iOS: bool = false;
|
public iOS: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on android?
|
||||||
* @property android
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public android: bool = false;
|
public android: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on chromeOS?
|
||||||
* @property chromeOS
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public chromeOS: bool = false;
|
public chromeOS: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on linux?
|
||||||
* @property linux
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public linux: bool = false;
|
public linux: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on maxOS?
|
||||||
* @property maxOS
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public macOS: bool = false;
|
public macOS: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on windows?
|
||||||
* @property windows
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public windows: bool = false;
|
public windows: bool = false;
|
||||||
|
|
||||||
// Features
|
// Features
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is canvas available?
|
||||||
* @property canvas
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public canvas: bool = false;
|
public canvas: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is file available?
|
||||||
* @property file
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public file: bool = false;
|
public file: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is fileSystem available?
|
||||||
* @property fileSystem
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public fileSystem: bool = false;
|
public fileSystem: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is localStorage available?
|
||||||
* @property localStorage
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public localStorage: bool = false;
|
public localStorage: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is webGL available?
|
||||||
* @property webGL
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public webGL: bool = false;
|
public webGL: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is worker available?
|
||||||
* @property worker
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public worker: bool = false;
|
public worker: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is touch available?
|
||||||
* @property touch
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public touch: bool = false;
|
public touch: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is mspointer available?
|
||||||
* @property css3D
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
public mspointer: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is css3D available?
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public css3D: bool = false;
|
public css3D: bool = false;
|
||||||
|
|
||||||
// Browser
|
// Browser
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in arora?
|
||||||
* @property arora
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public arora: bool = false;
|
public arora: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in chrome?
|
||||||
* @property chrome
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public chrome: bool = false;
|
public chrome: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in epiphany?
|
||||||
* @property epiphany
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public epiphany: bool = false;
|
public epiphany: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in firefox?
|
||||||
* @property firefox
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public firefox: bool = false;
|
public firefox: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in ie?
|
||||||
* @property ie
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public ie: bool = false;
|
public ie: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Version of ie?
|
||||||
* @property ieVersion
|
* @type Number
|
||||||
* @type Number
|
*/
|
||||||
*/
|
|
||||||
public ieVersion: number = 0;
|
public ieVersion: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in mobileSafari?
|
||||||
* @property mobileSafari
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public mobileSafari: bool = false;
|
public mobileSafari: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in midori?
|
||||||
* @property midori
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public midori: bool = false;
|
public midori: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in opera?
|
||||||
* @property opera
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public opera: bool = false;
|
public opera: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running in safari?
|
||||||
* @property safari
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public safari: bool = false;
|
public safari: bool = false;
|
||||||
public webApp: bool = false;
|
public webApp: bool = false;
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is audioData available?
|
||||||
* @property audioData
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public audioData: bool = false;
|
public audioData: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is webaudio available?
|
||||||
* @property webaudio
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public webaudio: bool = false;
|
public webaudio: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is ogg available?
|
||||||
* @property ogg
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public ogg: bool = false;
|
public ogg: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is mp3 available?
|
||||||
* @property mp3
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public mp3: bool = false;
|
public mp3: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is wav available?
|
||||||
* @property wav
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public wav: bool = false;
|
public wav: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is m4a available?
|
||||||
* @property m4a
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public m4a: bool = false;
|
public m4a: bool = false;
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on iPhone?
|
||||||
* @property iPhone
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public iPhone: bool = false;
|
public iPhone: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on iPhone4?
|
||||||
* @property iPhone4
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public iPhone4: bool = false;
|
public iPhone4: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Is running on iPad?
|
||||||
* @property iPad
|
* @type {boolean}
|
||||||
* @type Boolean
|
*/
|
||||||
*/
|
|
||||||
public iPad: bool = false;
|
public iPad: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* PixelRatio of the host device?
|
||||||
* @property pixelRatio
|
* @type Number
|
||||||
* @type Number
|
*/
|
||||||
*/
|
|
||||||
public pixelRatio: number = 0;
|
public pixelRatio: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Check which OS is game running on.
|
||||||
* @method _checkOS
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
|
||||||
private _checkOS() {
|
private _checkOS() {
|
||||||
|
|
||||||
var ua = navigator.userAgent;
|
var ua = navigator.userAgent;
|
||||||
@@ -320,10 +293,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Check HTML5 features of the host environment.
|
||||||
* @method _checkFeatures
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
|
||||||
private _checkFeatures() {
|
private _checkFeatures() {
|
||||||
|
|
||||||
this.canvas = !!window['CanvasRenderingContext2D'];
|
this.canvas = !!window['CanvasRenderingContext2D'];
|
||||||
@@ -347,13 +319,17 @@ module Phaser {
|
|||||||
this.touch = true;
|
this.touch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window.navigator.msPointerEnabled)
|
||||||
|
{
|
||||||
|
this.mspointer = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Check what browser is game running in.
|
||||||
* @method _checkBrowser
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
|
||||||
private _checkBrowser() {
|
private _checkBrowser() {
|
||||||
|
|
||||||
var ua = navigator.userAgent;
|
var ua = navigator.userAgent;
|
||||||
@@ -405,10 +381,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Check audio support.
|
||||||
* @method _checkAudio
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
|
||||||
private _checkAudio() {
|
private _checkAudio() {
|
||||||
|
|
||||||
this.audioData = !!(window['Audio']);
|
this.audioData = !!(window['Audio']);
|
||||||
@@ -449,10 +424,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Check PixelRatio of devices.
|
||||||
* @method _checkDevice
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
|
||||||
private _checkDevice() {
|
private _checkDevice() {
|
||||||
|
|
||||||
this.pixelRatio = window['devicePixelRatio'] || 1;
|
this.pixelRatio = window['devicePixelRatio'] || 1;
|
||||||
@@ -463,10 +437,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Check whether the host environment support 3D CSS.
|
||||||
* @method _checkCSS3D
|
* @private
|
||||||
* @private
|
*/
|
||||||
*/
|
|
||||||
private _checkCSS3D() {
|
private _checkCSS3D() {
|
||||||
|
|
||||||
var el = document.createElement('p');
|
var el = document.createElement('p');
|
||||||
@@ -497,11 +470,31 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isConsoleOpen(): bool {
|
||||||
|
|
||||||
|
if (window.console && window.console['firebug'])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.console)
|
||||||
|
{
|
||||||
|
console.profile();
|
||||||
|
console.profileEnd();
|
||||||
|
|
||||||
|
if (console.clear) console.clear();
|
||||||
|
|
||||||
|
return console['profiles'].length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get all informations of host device.
|
||||||
* @method getAll
|
* @return {string} Informations in a string.
|
||||||
* @return {String}
|
*/
|
||||||
*/
|
|
||||||
public getAll(): string {
|
public getAll(): string {
|
||||||
|
|
||||||
var output: string = '';
|
var output: string = '';
|
||||||
@@ -541,6 +534,7 @@ module Phaser {
|
|||||||
output = output.concat('WebGL: ' + this.webGL + '\n');
|
output = output.concat('WebGL: ' + this.webGL + '\n');
|
||||||
output = output.concat('Worker: ' + this.worker + '\n');
|
output = output.concat('Worker: ' + this.worker + '\n');
|
||||||
output = output.concat('Touch: ' + this.touch + '\n');
|
output = output.concat('Touch: ' + this.touch + '\n');
|
||||||
|
output = output.concat('MSPointer: ' + this.mspointer + '\n');
|
||||||
output = output.concat('CSS 3D: ' + this.css3D + '\n');
|
output = output.concat('CSS 3D: ' + this.css3D + '\n');
|
||||||
|
|
||||||
output = output.concat('\n');
|
output = output.concat('\n');
|
||||||
|
|||||||
+65
-184
@@ -15,33 +15,29 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a new Quad Tree node.
|
* Instantiate a new Quad Tree node.
|
||||||
*
|
*
|
||||||
* @param X The X-coordinate of the point in space.
|
* @param {Number} x The X-coordinate of the point in space.
|
||||||
* @param Y The Y-coordinate of the point in space.
|
* @param {Number} y The Y-coordinate of the point in space.
|
||||||
* @param Width Desired width of this node.
|
* @param {Number} width Desired width of this node.
|
||||||
* @param Height Desired height of this node.
|
* @param {Number} height Desired height of this node.
|
||||||
* @param Parent The parent branch or node. Pass null to create a root.
|
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||||
*/
|
*/
|
||||||
constructor(X: number, Y: number, Width: number, Height: number, Parent: QuadTree = null) {
|
constructor(x: number, y: number, width: number, height: number, parent: QuadTree = null) {
|
||||||
|
|
||||||
super(X, Y, Width, Height);
|
super(x, y, width, height);
|
||||||
|
|
||||||
//console.log('-------- QuadTree',X,Y,Width,Height);
|
|
||||||
|
|
||||||
this._headA = this._tailA = new LinkedList();
|
this._headA = this._tailA = new LinkedList();
|
||||||
this._headB = this._tailB = new LinkedList();
|
this._headB = this._tailB = new LinkedList();
|
||||||
|
|
||||||
//Copy the parent's children (if there are any)
|
//Copy the parent's children (if there are any)
|
||||||
if (Parent != null)
|
if (parent != null)
|
||||||
{
|
{
|
||||||
//console.log('Parent not null');
|
|
||||||
var iterator: LinkedList;
|
var iterator: LinkedList;
|
||||||
var ot: LinkedList;
|
var ot: LinkedList;
|
||||||
|
|
||||||
if (Parent._headA.object != null)
|
if (parent._headA.object != null)
|
||||||
{
|
{
|
||||||
iterator = Parent._headA;
|
iterator = parent._headA;
|
||||||
//console.log('iterator set to parent headA');
|
|
||||||
|
|
||||||
while (iterator != null)
|
while (iterator != null)
|
||||||
{
|
{
|
||||||
@@ -57,10 +53,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Parent._headB.object != null)
|
if (parent._headB.object != null)
|
||||||
{
|
{
|
||||||
iterator = Parent._headB;
|
iterator = parent._headB;
|
||||||
//console.log('iterator set to parent headB');
|
|
||||||
|
|
||||||
while (iterator != null)
|
while (iterator != null)
|
||||||
{
|
{
|
||||||
@@ -83,8 +78,6 @@ module Phaser {
|
|||||||
|
|
||||||
this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
|
this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
|
||||||
|
|
||||||
//console.log('canSubdivided', this._canSubdivide);
|
|
||||||
|
|
||||||
//Set up comparison/sort helpers
|
//Set up comparison/sort helpers
|
||||||
this._northWestTree = null;
|
this._northWestTree = null;
|
||||||
this._northEastTree = null;
|
this._northEastTree = null;
|
||||||
@@ -215,26 +208,6 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
private static _object;
|
private static _object;
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, used to reduce recursive method parameters during object placement and tree formation.
|
|
||||||
*/
|
|
||||||
private static _objectLeftEdge: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, used to reduce recursive method parameters during object placement and tree formation.
|
|
||||||
*/
|
|
||||||
private static _objectTopEdge: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, used to reduce recursive method parameters during object placement and tree formation.
|
|
||||||
*/
|
|
||||||
private static _objectRightEdge: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, used to reduce recursive method parameters during object placement and tree formation.
|
|
||||||
*/
|
|
||||||
private static _objectBottomEdge: number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal, used during tree processing and overlap checks.
|
* Internal, used during tree processing and overlap checks.
|
||||||
*/
|
*/
|
||||||
@@ -255,51 +228,16 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
private static _notifyCallback;
|
private static _notifyCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal, used during tree processing and overlap checks.
|
||||||
|
*/
|
||||||
|
private static _callbackContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal, used during tree processing and overlap checks.
|
* Internal, used during tree processing and overlap checks.
|
||||||
*/
|
*/
|
||||||
private static _iterator: LinkedList;
|
private static _iterator: LinkedList;
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _objectHullX: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _objectHullY: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _objectHullWidth: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _objectHullHeight: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _checkObjectHullX: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _checkObjectHullY: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _checkObjectHullWidth: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal, helpers for comparing actual object-to-object overlap - see <code>overlapNode()</code>.
|
|
||||||
*/
|
|
||||||
private static _checkObjectHullHeight: number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up memory.
|
* Clean up memory.
|
||||||
*/
|
*/
|
||||||
@@ -348,21 +286,20 @@ module Phaser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load objects and/or groups into the quad tree, and register notify and processing callbacks.
|
* Load objects and/or groups into the quad tree, and register notify and processing callbacks.
|
||||||
*
|
*
|
||||||
* @param ObjectOrGroup1 Any object that is or extends GameObject or Group.
|
* @param {Basic} objectOrGroup1 Any object that is or extends GameObject or Group.
|
||||||
* @param ObjectOrGroup2 Any object that is or extends GameObject or Group. If null, the first parameter will be checked against itself.
|
* @param {Basic} objectOrGroup2 Any object that is or extends GameObject or Group. If null, the first parameter will be checked against itself.
|
||||||
* @param NotifyCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject)</code> that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
|
* @param {Function} notifyCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject)</code> that is called whenever two objects are found to overlap in world space, and either no processCallback is specified, or the processCallback returns true.
|
||||||
* @param ProcessCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject):bool</code> that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
|
* @param {Function} processCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject):bool</code> that is called whenever two objects are found to overlap in world space. The notifyCallback is only called if this function returns true. See GameObject.separate().
|
||||||
|
* @param context The context in which the callbacks will be called
|
||||||
*/
|
*/
|
||||||
public load(ObjectOrGroup1: Basic, ObjectOrGroup2: Basic = null, NotifyCallback = null, ProcessCallback = null) {
|
public load(objectOrGroup1: Basic, objectOrGroup2: Basic = null, notifyCallback = null, processCallback = null, context = null) {
|
||||||
|
|
||||||
//console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
|
this.add(objectOrGroup1, QuadTree.A_LIST);
|
||||||
|
|
||||||
this.add(ObjectOrGroup1, QuadTree.A_LIST);
|
if (objectOrGroup2 != null)
|
||||||
|
|
||||||
if (ObjectOrGroup2 != null)
|
|
||||||
{
|
{
|
||||||
this.add(ObjectOrGroup2, QuadTree.B_LIST);
|
this.add(objectOrGroup2, QuadTree.B_LIST);
|
||||||
QuadTree._useBothLists = true;
|
QuadTree._useBothLists = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -370,11 +307,9 @@ module Phaser {
|
|||||||
QuadTree._useBothLists = false;
|
QuadTree._useBothLists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuadTree._notifyCallback = NotifyCallback;
|
QuadTree._notifyCallback = notifyCallback;
|
||||||
QuadTree._processingCallback = ProcessCallback;
|
QuadTree._processingCallback = processCallback;
|
||||||
|
QuadTree._callbackContext = context;
|
||||||
//console.log('use both', QuadTree._useBothLists);
|
|
||||||
//console.log('------------ end of load');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,20 +317,20 @@ module Phaser {
|
|||||||
* Call this function to add an object to the root of the tree.
|
* Call this function to add an object to the root of the tree.
|
||||||
* This function will recursively add all group members, but
|
* This function will recursively add all group members, but
|
||||||
* not the groups themselves.
|
* not the groups themselves.
|
||||||
*
|
*
|
||||||
* @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
|
* @param {Basic} objectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
|
||||||
* @param List A <code>uint</code> flag indicating the list to which you want to add the objects. Options are <code>QuadTree.A_LIST</code> and <code>QuadTree.B_LIST</code>.
|
* @param {Number} list A <code>uint</code> flag indicating the list to which you want to add the objects. Options are <code>QuadTree.A_LIST</code> and <code>QuadTree.B_LIST</code>.
|
||||||
*/
|
*/
|
||||||
public add(ObjectOrGroup: Basic, List: number) {
|
public add(objectOrGroup: Basic, list: number) {
|
||||||
|
|
||||||
QuadTree._list = List;
|
QuadTree._list = list;
|
||||||
|
|
||||||
if (ObjectOrGroup.isGroup == true)
|
if (objectOrGroup.isGroup == true)
|
||||||
{
|
{
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
var basic: Basic;
|
var basic: Basic;
|
||||||
var members = <Group> ObjectOrGroup['members'];
|
var members = <Group> objectOrGroup['members'];
|
||||||
var l: number = ObjectOrGroup['length'];
|
var l: number = objectOrGroup['length'];
|
||||||
|
|
||||||
while (i < l)
|
while (i < l)
|
||||||
{
|
{
|
||||||
@@ -405,7 +340,7 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (basic.isGroup)
|
if (basic.isGroup)
|
||||||
{
|
{
|
||||||
this.add(basic, List);
|
this.add(basic, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -413,10 +348,6 @@ module Phaser {
|
|||||||
|
|
||||||
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
|
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
|
||||||
{
|
{
|
||||||
QuadTree._objectLeftEdge = QuadTree._object.x;
|
|
||||||
QuadTree._objectTopEdge = QuadTree._object.y;
|
|
||||||
QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
|
|
||||||
QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
|
|
||||||
this.addObject();
|
this.addObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,17 +356,10 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QuadTree._object = ObjectOrGroup;
|
QuadTree._object = objectOrGroup;
|
||||||
|
|
||||||
//console.log('add - not group:', ObjectOrGroup.name);
|
|
||||||
|
|
||||||
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
|
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
|
||||||
{
|
{
|
||||||
QuadTree._objectLeftEdge = QuadTree._object.x;
|
|
||||||
QuadTree._objectTopEdge = QuadTree._object.y;
|
|
||||||
QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
|
|
||||||
QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
|
|
||||||
//console.log('object properties', QuadTree._objectLeftEdge, QuadTree._objectTopEdge, QuadTree._objectRightEdge, QuadTree._objectBottomEdge);
|
|
||||||
this.addObject();
|
this.addObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,23 +371,18 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
private addObject() {
|
private addObject() {
|
||||||
|
|
||||||
//console.log('addObject');
|
|
||||||
|
|
||||||
//If this quad (not its children) lies entirely inside this object, add it here
|
//If this quad (not its children) lies entirely inside this object, add it here
|
||||||
if (!this._canSubdivide || ((this._leftEdge >= QuadTree._objectLeftEdge) && (this._rightEdge <= QuadTree._objectRightEdge) && (this._topEdge >= QuadTree._objectTopEdge) && (this._bottomEdge <= QuadTree._objectBottomEdge)))
|
if (!this._canSubdivide || ((this._leftEdge >= QuadTree._object.collisionMask.x) && (this._rightEdge <= QuadTree._object.collisionMask.right) && (this._topEdge >= QuadTree._object.collisionMask.y) && (this._bottomEdge <= QuadTree._object.collisionMask.bottom)))
|
||||||
{
|
{
|
||||||
//console.log('add To List');
|
|
||||||
this.addToList();
|
this.addToList();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//See if the selected object fits completely inside any of the quadrants
|
//See if the selected object fits completely inside any of the quadrants
|
||||||
if ((QuadTree._objectLeftEdge > this._leftEdge) && (QuadTree._objectRightEdge < this._midpointX))
|
if ((QuadTree._object.collisionMask.x > this._leftEdge) && (QuadTree._object.collisionMask.right < this._midpointX))
|
||||||
{
|
{
|
||||||
if ((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY))
|
if ((QuadTree._object.collisionMask.y > this._topEdge) && (QuadTree._object.collisionMask.bottom < this._midpointY))
|
||||||
{
|
{
|
||||||
//console.log('Adding NW tree');
|
|
||||||
|
|
||||||
if (this._northWestTree == null)
|
if (this._northWestTree == null)
|
||||||
{
|
{
|
||||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||||
@@ -473,10 +392,8 @@ module Phaser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge))
|
if ((QuadTree._object.collisionMask.y > this._midpointY) && (QuadTree._object.collisionMask.bottom < this._bottomEdge))
|
||||||
{
|
{
|
||||||
//console.log('Adding SW tree');
|
|
||||||
|
|
||||||
if (this._southWestTree == null)
|
if (this._southWestTree == null)
|
||||||
{
|
{
|
||||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||||
@@ -487,12 +404,10 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QuadTree._objectLeftEdge > this._midpointX) && (QuadTree._objectRightEdge < this._rightEdge))
|
if ((QuadTree._object.collisionMask.x > this._midpointX) && (QuadTree._object.collisionMask.right < this._rightEdge))
|
||||||
{
|
{
|
||||||
if ((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY))
|
if ((QuadTree._object.collisionMask.y > this._topEdge) && (QuadTree._object.collisionMask.bottom < this._midpointY))
|
||||||
{
|
{
|
||||||
//console.log('Adding NE tree');
|
|
||||||
|
|
||||||
if (this._northEastTree == null)
|
if (this._northEastTree == null)
|
||||||
{
|
{
|
||||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||||
@@ -502,10 +417,8 @@ module Phaser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge))
|
if ((QuadTree._object.collisionMask.y > this._midpointY) && (QuadTree._object.collisionMask.bottom < this._bottomEdge))
|
||||||
{
|
{
|
||||||
//console.log('Adding SE tree');
|
|
||||||
|
|
||||||
if (this._southEastTree == null)
|
if (this._southEastTree == null)
|
||||||
{
|
{
|
||||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||||
@@ -517,47 +430,43 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//If it wasn't completely contained we have to check out the partial overlaps
|
//If it wasn't completely contained we have to check out the partial overlaps
|
||||||
if ((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY))
|
if ((QuadTree._object.collisionMask.right > this._leftEdge) && (QuadTree._object.collisionMask.x < this._midpointX) && (QuadTree._object.collisionMask.bottom > this._topEdge) && (QuadTree._object.collisionMask.y < this._midpointY))
|
||||||
{
|
{
|
||||||
if (this._northWestTree == null)
|
if (this._northWestTree == null)
|
||||||
{
|
{
|
||||||
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('added to north west partial tree');
|
|
||||||
this._northWestTree.addObject();
|
this._northWestTree.addObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY))
|
if ((QuadTree._object.collisionMask.right > this._midpointX) && (QuadTree._object.collisionMask.x < this._rightEdge) && (QuadTree._object.collisionMask.bottom > this._topEdge) && (QuadTree._object.collisionMask.y < this._midpointY))
|
||||||
{
|
{
|
||||||
if (this._northEastTree == null)
|
if (this._northEastTree == null)
|
||||||
{
|
{
|
||||||
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('added to north east partial tree');
|
|
||||||
this._northEastTree.addObject();
|
this._northEastTree.addObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge))
|
if ((QuadTree._object.collisionMask.right > this._midpointX) && (QuadTree._object.collisionMask.x < this._rightEdge) && (QuadTree._object.collisionMask.bottom > this._midpointY) && (QuadTree._object.collisionMask.y < this._bottomEdge))
|
||||||
{
|
{
|
||||||
if (this._southEastTree == null)
|
if (this._southEastTree == null)
|
||||||
{
|
{
|
||||||
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('added to south east partial tree');
|
|
||||||
this._southEastTree.addObject();
|
this._southEastTree.addObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge))
|
if ((QuadTree._object.collisionMask.right > this._leftEdge) && (QuadTree._object.collisionMask.x < this._midpointX) && (QuadTree._object.collisionMask.bottom > this._midpointY) && (QuadTree._object.collisionMask.y < this._bottomEdge))
|
||||||
{
|
{
|
||||||
if (this._southWestTree == null)
|
if (this._southWestTree == null)
|
||||||
{
|
{
|
||||||
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('added to south west partial tree');
|
|
||||||
this._southWestTree.addObject();
|
this._southWestTree.addObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,13 +477,10 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
private addToList() {
|
private addToList() {
|
||||||
|
|
||||||
//console.log('Adding to List');
|
|
||||||
|
|
||||||
var ot: LinkedList;
|
var ot: LinkedList;
|
||||||
|
|
||||||
if (QuadTree._list == QuadTree.A_LIST)
|
if (QuadTree._list == QuadTree.A_LIST)
|
||||||
{
|
{
|
||||||
//console.log('A LIST');
|
|
||||||
if (this._tailA.object != null)
|
if (this._tailA.object != null)
|
||||||
{
|
{
|
||||||
ot = this._tailA;
|
ot = this._tailA;
|
||||||
@@ -586,7 +492,6 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//console.log('B LIST');
|
|
||||||
if (this._tailB.object != null)
|
if (this._tailB.object != null)
|
||||||
{
|
{
|
||||||
ot = this._tailB;
|
ot = this._tailB;
|
||||||
@@ -628,20 +533,15 @@ module Phaser {
|
|||||||
* <code>QuadTree</code>'s other main function. Call this after adding objects
|
* <code>QuadTree</code>'s other main function. Call this after adding objects
|
||||||
* using <code>QuadTree.load()</code> to compare the objects that you loaded.
|
* using <code>QuadTree.load()</code> to compare the objects that you loaded.
|
||||||
*
|
*
|
||||||
* @return Whether or not any overlaps were found.
|
* @return {Boolean} Whether or not any overlaps were found.
|
||||||
*/
|
*/
|
||||||
public execute(): bool {
|
public execute(): bool {
|
||||||
|
|
||||||
//console.log('quadtree execute');
|
|
||||||
|
|
||||||
var overlapProcessed: bool = false;
|
var overlapProcessed: bool = false;
|
||||||
var iterator: LinkedList;
|
var iterator: LinkedList;
|
||||||
|
|
||||||
if (this._headA.object != null)
|
if (this._headA.object != null)
|
||||||
{
|
{
|
||||||
//console.log('---------------------------------------------------');
|
|
||||||
//console.log('headA iterator');
|
|
||||||
|
|
||||||
iterator = this._headA;
|
iterator = this._headA;
|
||||||
|
|
||||||
while (iterator != null)
|
while (iterator != null)
|
||||||
@@ -659,7 +559,6 @@ module Phaser {
|
|||||||
|
|
||||||
if (QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
|
if (QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
|
||||||
{
|
{
|
||||||
//console.log('headA iterator overlapped true');
|
|
||||||
overlapProcessed = true;
|
overlapProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,25 +570,21 @@ module Phaser {
|
|||||||
//Advance through the tree by calling overlap on each child
|
//Advance through the tree by calling overlap on each child
|
||||||
if ((this._northWestTree != null) && this._northWestTree.execute())
|
if ((this._northWestTree != null) && this._northWestTree.execute())
|
||||||
{
|
{
|
||||||
//console.log('NW quadtree execute');
|
|
||||||
overlapProcessed = true;
|
overlapProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this._northEastTree != null) && this._northEastTree.execute())
|
if ((this._northEastTree != null) && this._northEastTree.execute())
|
||||||
{
|
{
|
||||||
//console.log('NE quadtree execute');
|
|
||||||
overlapProcessed = true;
|
overlapProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this._southEastTree != null) && this._southEastTree.execute())
|
if ((this._southEastTree != null) && this._southEastTree.execute())
|
||||||
{
|
{
|
||||||
//console.log('SE quadtree execute');
|
|
||||||
overlapProcessed = true;
|
overlapProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((this._southWestTree != null) && this._southWestTree.execute())
|
if ((this._southWestTree != null) && this._southWestTree.execute())
|
||||||
{
|
{
|
||||||
//console.log('SW quadtree execute');
|
|
||||||
overlapProcessed = true;
|
overlapProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,9 +593,9 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An private for comparing an object against the contents of a node.
|
* A private for comparing an object against the contents of a node.
|
||||||
*
|
*
|
||||||
* @return Whether or not any overlaps were found.
|
* @return {Boolean} Whether or not any overlaps were found.
|
||||||
*/
|
*/
|
||||||
private overlapNode(): bool {
|
private overlapNode(): bool {
|
||||||
|
|
||||||
@@ -712,7 +607,6 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0))
|
if (!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0))
|
||||||
{
|
{
|
||||||
//console.log('break 1');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,32 +614,12 @@ module Phaser {
|
|||||||
|
|
||||||
if ((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0))
|
if ((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0))
|
||||||
{
|
{
|
||||||
//console.log('break 2');
|
|
||||||
QuadTree._iterator = QuadTree._iterator.next;
|
QuadTree._iterator = QuadTree._iterator.next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate bulk hull for QuadTree._object
|
if (QuadTree._object.collisionMask.checkHullIntersection(checkObject.collisionMask))
|
||||||
QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
|
|
||||||
QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
|
|
||||||
QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
|
|
||||||
QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
|
|
||||||
QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
|
|
||||||
QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
|
|
||||||
|
|
||||||
//calculate bulk hull for checkObject
|
|
||||||
QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
|
|
||||||
QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
|
|
||||||
QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
|
|
||||||
QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
|
|
||||||
QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
|
|
||||||
QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
|
|
||||||
|
|
||||||
//check for intersection of the two hulls
|
|
||||||
if ((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight))
|
|
||||||
{
|
{
|
||||||
//console.log('intersection!');
|
|
||||||
|
|
||||||
//Execute callback functions if they exist
|
//Execute callback functions if they exist
|
||||||
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject))
|
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject))
|
||||||
{
|
{
|
||||||
@@ -754,7 +628,14 @@ module Phaser {
|
|||||||
|
|
||||||
if (overlapProcessed && (QuadTree._notifyCallback != null))
|
if (overlapProcessed && (QuadTree._notifyCallback != null))
|
||||||
{
|
{
|
||||||
QuadTree._notifyCallback(QuadTree._object, checkObject);
|
if (QuadTree._callbackContext !== null)
|
||||||
|
{
|
||||||
|
QuadTree._notifyCallback.call(QuadTree._callbackContext, QuadTree._object, checkObject);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QuadTree._notifyCallback(QuadTree._object, checkObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ module Phaser {
|
|||||||
* @param {Any} callback
|
* @param {Any} callback
|
||||||
* @return {RequestAnimationFrame} This object.
|
* @return {RequestAnimationFrame} This object.
|
||||||
*/
|
*/
|
||||||
constructor(callback, callbackContext) {
|
constructor(game: Game, callback) {
|
||||||
|
|
||||||
this._callback = callback;
|
this._game = game;
|
||||||
this._callbackContext = callbackContext;
|
this.callback = callback;
|
||||||
|
|
||||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||||
|
|
||||||
@@ -33,24 +33,16 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Local private reference to game.
|
||||||
* @property _callback
|
*/
|
||||||
* @type Any
|
private _game: Game;
|
||||||
* @private
|
|
||||||
**/
|
|
||||||
private _callback;
|
|
||||||
private _callbackContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The function to be called each frame. Will be called in the context of _game
|
||||||
* @method callback
|
* @property callback
|
||||||
* @param {Any} callback
|
* @type Any
|
||||||
**/
|
**/
|
||||||
public setCallback(callback) {
|
public callback;
|
||||||
|
|
||||||
this._callback = callback;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -86,30 +78,10 @@ module Phaser {
|
|||||||
**/
|
**/
|
||||||
public isUsingRAF(): bool {
|
public isUsingRAF(): bool {
|
||||||
|
|
||||||
if (this._isSetTimeOut === true)
|
return this._isSetTimeOut === true;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property lastTime
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public lastTime: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property currentTime
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public currentTime: number = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @property isRunning
|
* @property isRunning
|
||||||
@@ -118,7 +90,7 @@ module Phaser {
|
|||||||
public isRunning: bool = false;
|
public isRunning: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
|
||||||
* @method start
|
* @method start
|
||||||
* @param {Any} [callback]
|
* @param {Any} [callback]
|
||||||
**/
|
**/
|
||||||
@@ -126,7 +98,7 @@ module Phaser {
|
|||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
{
|
{
|
||||||
this._callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!window.requestAnimationFrame)
|
if (!window.requestAnimationFrame)
|
||||||
@@ -137,7 +109,7 @@ module Phaser {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._isSetTimeOut = false;
|
this._isSetTimeOut = false;
|
||||||
window.requestAnimationFrame(() => this.RAFUpdate());
|
window.requestAnimationFrame(() => this.RAFUpdate(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
@@ -145,7 +117,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Stops the requestAnimationFrame from running
|
||||||
* @method stop
|
* @method stop
|
||||||
**/
|
**/
|
||||||
public stop() {
|
public stop() {
|
||||||
@@ -163,44 +135,38 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RAFUpdate() {
|
/**
|
||||||
|
* The update method for the requestAnimationFrame
|
||||||
|
* @method RAFUpdate
|
||||||
|
**/
|
||||||
|
public RAFUpdate(time: number) {
|
||||||
|
|
||||||
// Not in IE8 (but neither is RAF) also doesn't use a high performance timer (window.performance.now)
|
this._game.time.update(time);
|
||||||
this.currentTime = Date.now();
|
|
||||||
|
|
||||||
if (this._callback)
|
if (this.callback)
|
||||||
{
|
{
|
||||||
this._callback.call(this._callbackContext);
|
this.callback.call(this._game);
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeToCall: number = Math.max(0, 16 - (this.currentTime - this.lastTime));
|
window.requestAnimationFrame((time) => this.RAFUpdate(time));
|
||||||
|
|
||||||
window.requestAnimationFrame(() => this.RAFUpdate());
|
|
||||||
|
|
||||||
this.lastTime = this.currentTime + timeToCall;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The update method for the setTimeout
|
||||||
* @method SetTimeoutUpdate
|
* @method SetTimeoutUpdate
|
||||||
**/
|
**/
|
||||||
public SetTimeoutUpdate() {
|
public SetTimeoutUpdate() {
|
||||||
|
|
||||||
// Not in IE8
|
this._game.time.update(Date.now());
|
||||||
this.currentTime = Date.now();
|
|
||||||
|
|
||||||
if (this._callback)
|
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), 16.7);
|
||||||
|
|
||||||
|
if (this.callback)
|
||||||
{
|
{
|
||||||
this._callback.call(this._callbackContext);
|
this.callback.call(this._game);
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeToCall: number = Math.max(0, 16 - (this.currentTime - this.lastTime));
|
|
||||||
|
|
||||||
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), timeToCall);
|
|
||||||
|
|
||||||
this.lastTime = this.currentTime + timeToCall;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ module Phaser {
|
|||||||
|
|
||||||
export class Sound {
|
export class Sound {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sound constructor
|
||||||
|
* @param context {object} The AudioContext instance.
|
||||||
|
* @param gainNode {object} Gain node instance.
|
||||||
|
* @param data {object} Sound data.
|
||||||
|
* @param [volume] {number} volume of this sound when playing.
|
||||||
|
* @param [loop] {boolean} loop this sound when playing? (Default to false)
|
||||||
|
*/
|
||||||
constructor(context, gainNode, data, volume?: number = 1, loop?: bool = false) {
|
constructor(context, gainNode, data, volume?: number = 1, loop?: bool = false) {
|
||||||
|
|
||||||
this._context = context;
|
this._context = context;
|
||||||
@@ -38,11 +46,29 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to AudioContext.
|
||||||
|
*/
|
||||||
private _context;
|
private _context;
|
||||||
|
/**
|
||||||
|
* Reference to gain node of SoundManager.
|
||||||
|
*/
|
||||||
private _gainNode;
|
private _gainNode;
|
||||||
|
/**
|
||||||
|
* GainNode of this sound.
|
||||||
|
*/
|
||||||
private _localGainNode;
|
private _localGainNode;
|
||||||
|
/**
|
||||||
|
* Decoded data buffer.
|
||||||
|
*/
|
||||||
private _buffer;
|
private _buffer;
|
||||||
|
/**
|
||||||
|
* Volume of this sound.
|
||||||
|
*/
|
||||||
private _volume: number;
|
private _volume: number;
|
||||||
|
/**
|
||||||
|
* The real sound object (buffer source).
|
||||||
|
*/
|
||||||
private _sound;
|
private _sound;
|
||||||
|
|
||||||
loop: bool = false;
|
loop: bool = false;
|
||||||
@@ -58,6 +84,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play this sound.
|
||||||
|
*/
|
||||||
public play() {
|
public play() {
|
||||||
|
|
||||||
if (this._buffer === null || this.isDecoding === true)
|
if (this._buffer === null || this.isDecoding === true)
|
||||||
@@ -81,6 +110,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop playing this sound.
|
||||||
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
|
|
||||||
if (this.isPlaying === true)
|
if (this.isPlaying === true)
|
||||||
@@ -92,12 +124,18 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mute the sound.
|
||||||
|
*/
|
||||||
public mute() {
|
public mute() {
|
||||||
|
|
||||||
this._localGainNode.gain.value = 0;
|
this._localGainNode.gain.value = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the sound.
|
||||||
|
*/
|
||||||
public unmute() {
|
public unmute() {
|
||||||
|
|
||||||
this._localGainNode.gain.value = this._volume;
|
this._localGainNode.gain.value = this._volume;
|
||||||
|
|||||||
+216
-19
@@ -5,42 +5,186 @@
|
|||||||
*
|
*
|
||||||
* This class controls the scaling of your game. On mobile devices it will also remove the URL bar and allow
|
* This class controls the scaling of your game. On mobile devices it will also remove the URL bar and allow
|
||||||
* you to maintain proportion and aspect ratio.
|
* you to maintain proportion and aspect ratio.
|
||||||
* It is based on a technique taken from Viewporter v2.0 by Zynga Inc. http://github.com/zynga/viewporter
|
* The resizing method is based on a technique taken from Viewporter v2.0 by Zynga Inc. http://github.com/zynga/viewporter
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
|
|
||||||
export class StageScaleMode {
|
export class StageScaleMode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StageScaleMode constructor
|
||||||
|
*/
|
||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
|
|
||||||
this.orientation = window['orientation'];
|
this.enterLandscape = new Phaser.Signal();
|
||||||
|
this.enterPortrait = new Phaser.Signal();
|
||||||
|
|
||||||
|
if (window['orientation'])
|
||||||
|
{
|
||||||
|
this.orientation = window['orientation'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (window.outerWidth > window.outerHeight)
|
||||||
|
{
|
||||||
|
this.orientation = 90;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.orientation = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('orientationchange', (event) => this.checkOrientation(event), false);
|
window.addEventListener('orientationchange', (event) => this.checkOrientation(event), false);
|
||||||
|
window.addEventListener('resize', (event) => this.checkResize(event), false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stage height when start the game.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _startHeight: number = 0;
|
private _startHeight: number = 0;
|
||||||
private _iterations: number;
|
private _iterations: number;
|
||||||
private _check;
|
private _check;
|
||||||
|
|
||||||
// Specifies that the game be visible in the specified area without trying to preserve the original aspect ratio.
|
/**
|
||||||
|
* Specifies that the game be visible in the specified area without trying to preserve the original aspect ratio.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static EXACT_FIT: number = 0;
|
public static EXACT_FIT: number = 0;
|
||||||
|
|
||||||
// Specifies that the size of the game be fixed, so that it remains unchanged even if the size of the window changes.
|
/**
|
||||||
|
* Specifies that the size of the game be fixed, so that it remains unchanged even if the size of the window changes.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static NO_SCALE: number = 1;
|
public static NO_SCALE: number = 1;
|
||||||
|
|
||||||
// Specifies that the entire game be visible in the specified area without distortion while maintaining the original aspect ratio.
|
/**
|
||||||
|
* Specifies that the entire game be visible in the specified area without distortion while maintaining the original aspect ratio.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public static SHOW_ALL: number = 2;
|
public static SHOW_ALL: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum width the canvas should be scaled to (in pixels)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public minWidth: number = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum width the canvas should be scaled to (in pixels).
|
||||||
|
* If null it will scale to whatever width the browser can handle.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public maxWidth: number = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum height the canvas should be scaled to (in pixels)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public minHeight: number = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum height the canvas should be scaled to (in pixels).
|
||||||
|
* If null it will scale to whatever height the browser can handle.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public maxHeight: number = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of the stage after calculation.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public width: number = 0;
|
public width: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Height of the stage after calculation.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public height: number = 0;
|
public height: number = 0;
|
||||||
|
|
||||||
public orientation;
|
/**
|
||||||
|
* Window orientation angle (90 and -90 are landscape, 0 is portrait)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
public orientation: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Signal that is dispatched when the device enters landscape mode from portrait
|
||||||
|
* @type {Signal}
|
||||||
|
*/
|
||||||
|
public enterLandscape: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Signal that is dispatched when the device enters portrait mode from landscape
|
||||||
|
* @type {Signal}
|
||||||
|
*/
|
||||||
|
public enterPortrait: Phaser.Signal;
|
||||||
|
|
||||||
|
public get isFullScreen(): bool {
|
||||||
|
|
||||||
|
if (document['fullscreenElement'] === null|| document['mozFullScreenElement'] === null|| document['webkitFullscreenElement'] === null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public startFullScreen() {
|
||||||
|
|
||||||
|
if (this.isFullScreen)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = this._game.stage.canvas;
|
||||||
|
|
||||||
|
if (element['requestFullScreen'])
|
||||||
|
{
|
||||||
|
element['requestFullScreen']();
|
||||||
|
}
|
||||||
|
else if(element['mozRequestFullScreen'])
|
||||||
|
{
|
||||||
|
element['mozRequestFullScreen']();
|
||||||
|
}
|
||||||
|
else if (element['webkitRequestFullScreen'])
|
||||||
|
{
|
||||||
|
element['webkitRequestFullScreen']();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public stopFullScreen() {
|
||||||
|
|
||||||
|
if (document['cancelFullScreen'])
|
||||||
|
{
|
||||||
|
document['cancelFullScreen']();
|
||||||
|
}
|
||||||
|
else if (document['mozCancelFullScreen'])
|
||||||
|
{
|
||||||
|
document['mozCancelFullScreen']();
|
||||||
|
}
|
||||||
|
else if (document['webkitCancelFullScreen'])
|
||||||
|
{
|
||||||
|
document['webkitCancelFullScreen']();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The core update loop, called by Phaser.Stage
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
if (this._game.stage.scaleMode !== StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height))
|
if (this._game.stage.scaleMode !== StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height))
|
||||||
@@ -50,20 +194,70 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get isLandscape(): bool {
|
public get isPortrait(): bool {
|
||||||
return window['orientation'] === 90 || window['orientation'] === -90;
|
return this.orientation == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get isLandscape(): bool {
|
||||||
|
return this.orientation === 90 || this.orientation === -90;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle window.orientationchange events
|
||||||
|
*/
|
||||||
private checkOrientation(event) {
|
private checkOrientation(event) {
|
||||||
|
|
||||||
if (window['orientation'] !== this.orientation)
|
this.orientation = window['orientation'];
|
||||||
|
|
||||||
|
if (this.isLandscape)
|
||||||
|
{
|
||||||
|
this.enterLandscape.dispatch(this.orientation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.enterPortrait.dispatch(this.orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._game.stage.scaleMode !== StageScaleMode.NO_SCALE)
|
||||||
{
|
{
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.orientation = window['orientation'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle window.resize events
|
||||||
|
*/
|
||||||
|
private checkResize(event) {
|
||||||
|
|
||||||
|
if (window.outerWidth > window.outerHeight)
|
||||||
|
{
|
||||||
|
this.orientation = 90;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.orientation = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isLandscape)
|
||||||
|
{
|
||||||
|
this.enterLandscape.dispatch(this.orientation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.enterPortrait.dispatch(this.orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._game.stage.scaleMode !== StageScaleMode.NO_SCALE)
|
||||||
|
{
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-calculate scale mode and update screen size.
|
||||||
|
*/
|
||||||
private refresh() {
|
private refresh() {
|
||||||
|
|
||||||
// We can't do anything about the status bars in iPads, web apps or desktops
|
// We can't do anything about the status bars in iPads, web apps or desktops
|
||||||
@@ -91,6 +285,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set screen size automatically based on the scaleMode.
|
||||||
|
*/
|
||||||
private setScreenSize() {
|
private setScreenSize() {
|
||||||
|
|
||||||
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
|
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
|
||||||
@@ -114,18 +311,18 @@ module Phaser {
|
|||||||
|
|
||||||
if (this._game.stage.scaleMode == StageScaleMode.EXACT_FIT)
|
if (this._game.stage.scaleMode == StageScaleMode.EXACT_FIT)
|
||||||
{
|
{
|
||||||
if (this._game.stage.maxScaleX && window.innerWidth > this._game.stage.maxScaleX)
|
if (this.maxWidth && window.innerWidth > this.maxWidth)
|
||||||
{
|
{
|
||||||
this.width = this._game.stage.maxScaleX;
|
this.width = this.maxWidth;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.width = window.innerWidth;
|
this.width = window.innerWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._game.stage.maxScaleY && window.innerHeight > this._game.stage.maxScaleY)
|
if (this.maxHeight && window.innerHeight > this.maxHeight)
|
||||||
{
|
{
|
||||||
this.height = this._game.stage.maxScaleY;
|
this.height = this.maxHeight;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -133,20 +330,20 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (this._game.stage.scaleMode == StageScaleMode.SHOW_ALL)
|
else if (this._game.stage.scaleMode == StageScaleMode.SHOW_ALL)
|
||||||
{
|
{
|
||||||
var multiplier = Math.min((window.innerHeight / this._game.stage.height), (window.innerWidth / this._game.stage.width));
|
var multiplier = Math.min((window.innerHeight / this._game.stage.height), (window.innerWidth / this._game.stage.width));
|
||||||
|
|
||||||
this.width = Math.round(this._game.stage.width * multiplier);
|
this.width = Math.round(this._game.stage.width * multiplier);
|
||||||
this.height = Math.round(this._game.stage.height * multiplier);
|
this.height = Math.round(this._game.stage.height * multiplier);
|
||||||
|
|
||||||
if (this._game.stage.maxScaleX && this.width > this._game.stage.maxScaleX)
|
if (this.maxWidth && this.width > this.maxWidth)
|
||||||
{
|
{
|
||||||
this.width = this._game.stage.maxScaleX;
|
this.width = this.maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._game.stage.maxScaleY && this.height > this._game.stage.maxScaleY)
|
if (this.maxHeight && this.height > this.maxHeight)
|
||||||
{
|
{
|
||||||
this.height = this._game.stage.maxScaleY;
|
this.height = this.maxHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+68
-1
@@ -10,6 +10,15 @@ module Phaser {
|
|||||||
|
|
||||||
export class Tile {
|
export class Tile {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tile constructor
|
||||||
|
* Create a new <code>Tile</code>.
|
||||||
|
*
|
||||||
|
* @param tilemap {Tilemap} the tilemap this tile belongs to.
|
||||||
|
* @param index {number} The index of this tile type in the core map data.
|
||||||
|
* @param width {number} Width of the tile.
|
||||||
|
* @param height number} Height of the tile.
|
||||||
|
*/
|
||||||
constructor(game: Game, tilemap: Tilemap, index: number, width: number, height: number) {
|
constructor(game: Game, tilemap: Tilemap, index: number, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -22,27 +31,74 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
// You can give this Tile a friendly name to help with debugging. Never used internally.
|
/**
|
||||||
|
* You can give this Tile a friendly name to help with debugging. Never used internally.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The virtual mass of the tile.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public mass: number = 1.0;
|
public mass: number = 1.0;
|
||||||
|
/**
|
||||||
|
* Tile width.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public width: number;
|
public width: number;
|
||||||
|
/**
|
||||||
|
* Tile height.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public height: number;
|
public height: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public allowCollisions: number;
|
public allowCollisions: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicating collide with any object on the left.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public collideLeft: bool = false;
|
public collideLeft: bool = false;
|
||||||
|
/**
|
||||||
|
* Indicating collide with any object on the right.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public collideRight: bool = false;
|
public collideRight: bool = false;
|
||||||
|
/**
|
||||||
|
* Indicating collide with any object on the top.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public collideUp: bool = false;
|
public collideUp: bool = false;
|
||||||
|
/**
|
||||||
|
* Indicating collide with any object on the bottom.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public collideDown: bool = false;
|
public collideDown: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable separation at x-axis.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public separateX: bool = true;
|
public separateX: bool = true;
|
||||||
|
/**
|
||||||
|
* Enable separation at y-axis.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public separateY: bool = true;
|
public separateY: bool = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reference to the tilemap this tile object belongs to.
|
* A reference to the tilemap this tile object belongs to.
|
||||||
|
* @type {Tilemap}
|
||||||
*/
|
*/
|
||||||
public tilemap: Tilemap;
|
public tilemap: Tilemap;
|
||||||
|
|
||||||
@@ -50,6 +106,7 @@ module Phaser {
|
|||||||
* The index of this tile type in the core map data.
|
* The index of this tile type in the core map data.
|
||||||
* For example, if your map only has 16 kinds of tiles in it,
|
* For example, if your map only has 16 kinds of tiles in it,
|
||||||
* this number is usually between 0 and 15.
|
* this number is usually between 0 and 15.
|
||||||
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
public index: number;
|
public index: number;
|
||||||
|
|
||||||
@@ -62,6 +119,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set collision configs.
|
||||||
|
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||||
|
* @param resetCollisions {boolean} Reset collision flags before set.
|
||||||
|
* @param separateX {boolean} Enable seprate at x-axis.
|
||||||
|
* @param separateY {boolean} Enable seprate at y-axis.
|
||||||
|
*/
|
||||||
public setCollision(collision: number, resetCollisions: bool, separateX: bool, separateY: bool) {
|
public setCollision(collision: number, resetCollisions: bool, separateX: bool, separateY: bool) {
|
||||||
|
|
||||||
if (resetCollisions)
|
if (resetCollisions)
|
||||||
@@ -105,6 +169,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset collision status flags.
|
||||||
|
*/
|
||||||
public resetCollision() {
|
public resetCollision() {
|
||||||
|
|
||||||
this.allowCollisions = Collision.NONE;
|
this.allowCollisions = Collision.NONE;
|
||||||
|
|||||||
+222
-17
@@ -10,6 +10,18 @@ module Phaser {
|
|||||||
|
|
||||||
export class TilemapLayer {
|
export class TilemapLayer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TilemapLayer constructor
|
||||||
|
* Create a new <code>TilemapLayer</code>.
|
||||||
|
*
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
* @param parent {Tilemap} The tilemap that contains this layer.
|
||||||
|
* @param key {string} Asset key for this map.
|
||||||
|
* @param mapFormat {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||||
|
* @param name {string} Name of this layer, so you can get this layer by its name.
|
||||||
|
* @param tileWidth {number} Width of tiles in this map.
|
||||||
|
* @param tileHeight {number} Height of tiles in this map.
|
||||||
|
*/
|
||||||
constructor(game: Game, parent:Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number) {
|
constructor(game: Game, parent:Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -22,14 +34,29 @@ module Phaser {
|
|||||||
this.boundsInTiles = new Rectangle();
|
this.boundsInTiles = new Rectangle();
|
||||||
//this.scrollFactor = new MicroPoint(1, 1);
|
//this.scrollFactor = new MicroPoint(1, 1);
|
||||||
|
|
||||||
|
this.canvas = game.stage.canvas;
|
||||||
|
this.context = game.stage.context;
|
||||||
|
|
||||||
this.mapData = [];
|
this.mapData = [];
|
||||||
this._tempTileBlock = [];
|
this._tempTileBlock = [];
|
||||||
this._texture = this._game.cache.getImage(key);
|
this._texture = this._game.cache.getImage(key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tilemap that contains this layer.
|
||||||
|
* @type {Tilemap}
|
||||||
|
*/
|
||||||
private _parent: Tilemap;
|
private _parent: Tilemap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tileset of this layer.
|
||||||
|
*/
|
||||||
private _texture;
|
private _texture;
|
||||||
private _tileOffsets;
|
private _tileOffsets;
|
||||||
private _startX: number = 0;
|
private _startX: number = 0;
|
||||||
@@ -51,30 +78,126 @@ module Phaser {
|
|||||||
private _tempTileBlock;
|
private _tempTileBlock;
|
||||||
private _tempBlockResults;
|
private _tempBlockResults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of this layer, so you can get this layer by its name.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the Canvas this GameObject will render to
|
||||||
|
* @type {HTMLCanvasElement}
|
||||||
|
*/
|
||||||
|
public canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the Canvas Context2D this GameObject will render to
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
|
public context: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opacity of this layer.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public alpha: number = 1;
|
public alpha: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls whether update() and draw() are automatically called.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public exists: bool = true;
|
public exists: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls whether draw() are automatically called.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public visible: bool = true;
|
public visible: bool = true;
|
||||||
|
|
||||||
//public scrollFactor: MicroPoint;
|
//public scrollFactor: MicroPoint;
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public orientation: string;
|
public orientation: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties of this map layer. (normally set by map editors)
|
||||||
|
*/
|
||||||
public properties: {};
|
public properties: {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map data in a 2d array, its element is a index number for that tile.
|
||||||
|
* @type {number[][]}
|
||||||
|
*/
|
||||||
public mapData;
|
public mapData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||||
|
*/
|
||||||
public mapFormat: number;
|
public mapFormat: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It's width and height are in tiles instead of pixels.
|
||||||
|
* @type {Rectangle}
|
||||||
|
*/
|
||||||
public boundsInTiles: Rectangle;
|
public boundsInTiles: Rectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of each tile.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public tileWidth: number;
|
public tileWidth: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Height of a single tile.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public tileHeight: number;
|
public tileHeight: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many tiles in each row.
|
||||||
|
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public widthInTiles: number = 0;
|
public widthInTiles: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many tiles in each column.
|
||||||
|
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public heightInTiles: number = 0;
|
public heightInTiles: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public widthInPixels: number = 0;
|
public widthInPixels: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public heightInPixels: number = 0;
|
public heightInPixels: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance between REAL tiles to the tileset texture bound.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public tileMargin: number = 0;
|
public tileMargin: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distance between every 2 neighbor tile in the tileset texture.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public tileSpacing: number = 0;
|
public tileSpacing: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a specific tile with its x and y in tiles.
|
||||||
|
* @param x {number} X position of this tile.
|
||||||
|
* @param y {number} Y position of this tile.
|
||||||
|
* @param index {number} The index of this tile type in the core map data.
|
||||||
|
*/
|
||||||
public putTile(x: number, y: number, index: number) {
|
public putTile(x: number, y: number, index: number) {
|
||||||
|
|
||||||
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
||||||
@@ -90,6 +213,15 @@ 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.
|
||||||
|
*/
|
||||||
public swapTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
public swapTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
||||||
|
|
||||||
this.getTempBlock(x, y, width, height);
|
this.getTempBlock(x, y, width, height);
|
||||||
@@ -120,6 +252,14 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill a tile block with a specific tile index.
|
||||||
|
* @param index {number} Index of tiles you want to fill with.
|
||||||
|
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||||
|
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||||
|
* @param [width] {number} width of block.
|
||||||
|
* @param [height] {number} height of block.
|
||||||
|
*/
|
||||||
public fillTile(index: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
public fillTile(index: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
||||||
|
|
||||||
this.getTempBlock(x, y, width, height);
|
this.getTempBlock(x, y, width, height);
|
||||||
@@ -131,6 +271,14 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set random tiles to a specific tile block.
|
||||||
|
* @param tiles {number[]} Tiles with indexes in this array will be randomly set to the given block.
|
||||||
|
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||||
|
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||||
|
* @param [width] {number} width of block.
|
||||||
|
* @param [height] {number} height of block.
|
||||||
|
*/
|
||||||
public randomiseTiles(tiles: number[], x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
public randomiseTiles(tiles: number[], x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
||||||
|
|
||||||
this.getTempBlock(x, y, width, height);
|
this.getTempBlock(x, y, width, height);
|
||||||
@@ -142,6 +290,15 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace one kind of tiles to another kind.
|
||||||
|
* @param tileA {number} Index of tiles you want to replace.
|
||||||
|
* @param tileB {number} Index of tiles you want to set.
|
||||||
|
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||||
|
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||||
|
* @param [width] {number} width of block.
|
||||||
|
* @param [height] {number} height of block.
|
||||||
|
*/
|
||||||
public replaceTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
public replaceTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
|
||||||
|
|
||||||
this.getTempBlock(x, y, width, height);
|
this.getTempBlock(x, y, width, height);
|
||||||
@@ -156,6 +313,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a tile block with specific position and size.(both are in tiles)
|
||||||
|
* @param x {number} X position of block's left-top corner.
|
||||||
|
* @param y {number} Y position of block's left-top corner.
|
||||||
|
* @param width {number} Width of block.
|
||||||
|
* @param height {number} Height of block.
|
||||||
|
*/
|
||||||
public getTileBlock(x: number, y: number, width: number, height: number) {
|
public getTileBlock(x: number, y: number, width: number, height: number) {
|
||||||
|
|
||||||
var output = [];
|
var output = [];
|
||||||
@@ -171,6 +335,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a tile with specific position (in world coordinate). (thus you give a position of a point which is within the tile)
|
||||||
|
* @param x {number} X position of the point in target tile.
|
||||||
|
* @param x {number} Y position of the point in target tile.
|
||||||
|
*/
|
||||||
public getTileFromWorldXY(x: number, y: number): number {
|
public getTileFromWorldXY(x: number, y: number): number {
|
||||||
|
|
||||||
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
||||||
@@ -180,19 +349,24 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tiles overlaps the given object.
|
||||||
|
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||||
|
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||||
|
*/
|
||||||
public getTileOverlaps(object: GameObject) {
|
public getTileOverlaps(object: GameObject) {
|
||||||
|
|
||||||
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
|
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
|
||||||
if (object.bounds.x < 0 || object.bounds.x > this.widthInPixels || object.bounds.y < 0 || object.bounds.bottom > this.heightInPixels)
|
if (object.collisionMask.x < 0 || object.collisionMask.x > this.widthInPixels || object.collisionMask.y < 0 || object.collisionMask.bottom > this.heightInPixels)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// What tiles do we need to check against?
|
// What tiles do we need to check against?
|
||||||
this._tempTileX = this._game.math.snapToFloor(object.bounds.x, this.tileWidth) / this.tileWidth;
|
this._tempTileX = this._game.math.snapToFloor(object.collisionMask.x, this.tileWidth) / this.tileWidth;
|
||||||
this._tempTileY = this._game.math.snapToFloor(object.bounds.y, this.tileHeight) / this.tileHeight;
|
this._tempTileY = this._game.math.snapToFloor(object.collisionMask.y, this.tileHeight) / this.tileHeight;
|
||||||
this._tempTileW = (this._game.math.snapToCeil(object.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
|
this._tempTileW = (this._game.math.snapToCeil(object.collisionMask.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
|
||||||
this._tempTileH = (this._game.math.snapToCeil(object.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
|
this._tempTileH = (this._game.math.snapToCeil(object.collisionMask.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
|
||||||
|
|
||||||
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
|
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
|
||||||
|
|
||||||
@@ -213,6 +387,14 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a tile block with its position and size. (This method does not return, it'll set result to _tempTileBlock)
|
||||||
|
* @param x {number} X position of block's left-top corner.
|
||||||
|
* @param y {number} Y position of block's left-top corner.
|
||||||
|
* @param width {number} Width of block.
|
||||||
|
* @param height {number} Height of block.
|
||||||
|
* @param collisionOnly {boolean} Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE).
|
||||||
|
*/
|
||||||
private getTempBlock(x: number, y: number, width: number, height: number, collisionOnly?: bool = false) {
|
private getTempBlock(x: number, y: number, width: number, height: number, collisionOnly?: bool = false) {
|
||||||
|
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
@@ -261,6 +443,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile index of specific position (in tiles).
|
||||||
|
* @param x {number} X position of the tile.
|
||||||
|
* @param y {number} Y position of the tile.
|
||||||
|
* @return {number} Index of the tile at that position. Return null if there isn't a tile there.
|
||||||
|
*/
|
||||||
public getTileIndex(x: number, y: number): number {
|
public getTileIndex(x: number, y: number): number {
|
||||||
|
|
||||||
if (y >= 0 && y < this.mapData.length)
|
if (y >= 0 && y < this.mapData.length)
|
||||||
@@ -270,11 +458,15 @@ module Phaser {
|
|||||||
return this.mapData[y][x];
|
return this.mapData[y][x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a column of tiles into the layer.
|
||||||
|
* @param column {string[]/number[]} An array of tile indexes to be added.
|
||||||
|
*/
|
||||||
public addColumn(column) {
|
public addColumn(column) {
|
||||||
|
|
||||||
var data = [];
|
var data = [];
|
||||||
@@ -297,12 +489,19 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update boundsInTiles with widthInTiles and heightInTiles.
|
||||||
|
*/
|
||||||
public updateBounds() {
|
public updateBounds() {
|
||||||
|
|
||||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse tile offsets from map data.
|
||||||
|
* @return {number} length of _tileOffsets array.
|
||||||
|
*/
|
||||||
public parseTileOffsets():number {
|
public parseTileOffsets():number {
|
||||||
|
|
||||||
this._tileOffsets = [];
|
this._tileOffsets = [];
|
||||||
@@ -331,14 +530,21 @@ module Phaser {
|
|||||||
|
|
||||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||||
|
|
||||||
this._game.stage.context.fillStyle = color;
|
this.context.fillStyle = color;
|
||||||
this._game.stage.context.fillText('TilemapLayer: ' + this.name, x, y);
|
this.context.fillText('TilemapLayer: ' + this.name, x, y);
|
||||||
this._game.stage.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
||||||
this._game.stage.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
||||||
this._game.stage.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render this layer to a specific camera with offset to camera.
|
||||||
|
* @param camera {Camera} The camera the layer is going to be rendered.
|
||||||
|
* @param dx {number} X offset to the camera.
|
||||||
|
* @param dy {number} Y offset to the camera.
|
||||||
|
* @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
|
||||||
|
*/
|
||||||
public render(camera: Camera, dx, dy): bool {
|
public render(camera: Camera, dx, dy): bool {
|
||||||
|
|
||||||
if (this.visible === false || this.alpha < 0.1)
|
if (this.visible === false || this.alpha < 0.1)
|
||||||
@@ -407,8 +613,8 @@ module Phaser {
|
|||||||
// Alpha
|
// Alpha
|
||||||
if (this.alpha !== 1)
|
if (this.alpha !== 1)
|
||||||
{
|
{
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
var globalAlpha = this.context.globalAlpha;
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
this.context.globalAlpha = this.alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var row = this._startY; row < this._startY + this._maxY; row++)
|
for (var row = this._startY; row < this._startY + this._maxY; row++)
|
||||||
@@ -419,7 +625,7 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (this._tileOffsets[this._columnData[tile]])
|
if (this._tileOffsets[this._columnData[tile]])
|
||||||
{
|
{
|
||||||
this._game.stage.context.drawImage(
|
this.context.drawImage(
|
||||||
this._texture, // Source Image
|
this._texture, // Source Image
|
||||||
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
|
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
|
||||||
this._tileOffsets[this._columnData[tile]].y, // Source Y
|
this._tileOffsets[this._columnData[tile]].y, // Source Y
|
||||||
@@ -430,7 +636,7 @@ module Phaser {
|
|||||||
this.tileWidth, // Destination Width (always same as Source Width unless scaled)
|
this.tileWidth, // Destination Width (always same as Source Width unless scaled)
|
||||||
this.tileHeight // Destination Height (always same as Source Height unless scaled)
|
this.tileHeight // Destination Height (always same as Source Height unless scaled)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._tx += this.tileWidth;
|
this._tx += this.tileWidth;
|
||||||
@@ -444,13 +650,12 @@ module Phaser {
|
|||||||
|
|
||||||
if (globalAlpha > -1)
|
if (globalAlpha > -1)
|
||||||
{
|
{
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
this.context.globalAlpha = globalAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+92
-1
@@ -21,6 +21,13 @@ module Phaser {
|
|||||||
|
|
||||||
export class Tween {
|
export class Tween {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tween constructor
|
||||||
|
* Create a new <code>Tween</code>.
|
||||||
|
*
|
||||||
|
* @param object {object} Target object will be affected by this tween.
|
||||||
|
* @param game {Phaser.Game} Current game instance.
|
||||||
|
*/
|
||||||
constructor(object, game:Phaser.Game) {
|
constructor(object, game:Phaser.Game) {
|
||||||
|
|
||||||
this._object = object;
|
this._object = object;
|
||||||
@@ -37,25 +44,85 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Phaser.Game;
|
private _game: Phaser.Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manager of this tween.
|
||||||
|
* @type {Phaser.TweenManager}
|
||||||
|
*/
|
||||||
private _manager: Phaser.TweenManager;
|
private _manager: Phaser.TweenManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the target object.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _object = null;
|
private _object = null;
|
||||||
private _pausedTime: number = 0;
|
private _pausedTime: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start values container.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _valuesStart = {};
|
private _valuesStart = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End values container.
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
private _valuesEnd = {};
|
private _valuesEnd = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long this tween will perform.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _duration = 1000;
|
private _duration = 1000;
|
||||||
private _delayTime = 0;
|
private _delayTime = 0;
|
||||||
private _startTime = null;
|
private _startTime = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Easing function which actually updating this tween.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
private _easingFunction;
|
private _easingFunction;
|
||||||
private _interpolationFunction;
|
private _interpolationFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains chained tweens.
|
||||||
|
* @type {Tweens[]}
|
||||||
|
*/
|
||||||
private _chainedTweens = [];
|
private _chainedTweens = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal to be dispatched when this tween start.
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
public onStart: Phaser.Signal;
|
public onStart: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal to be dispatched when this tween updating.
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
public onUpdate: Phaser.Signal;
|
public onUpdate: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal to be dispatched when this tween completed.
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
public onComplete: Phaser.Signal;
|
public onComplete: Phaser.Signal;
|
||||||
|
|
||||||
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false) {
|
/**
|
||||||
|
* Configure the Tween
|
||||||
|
* @param properties {object} Propertis you want to tween.
|
||||||
|
* @param [duration] {number} duration of this tween.
|
||||||
|
* @param [ease] {any} Easing function.
|
||||||
|
* @param [autoStart] {boolean} Whether this tween will start automatically or not.
|
||||||
|
* @param [delay] {number} delay before this tween will start, defaults to 0 (no delay)
|
||||||
|
* @return {Tween} Itself.
|
||||||
|
*/
|
||||||
|
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false, delay?:number = 0) {
|
||||||
|
|
||||||
this._duration = duration;
|
this._duration = duration;
|
||||||
|
|
||||||
@@ -67,6 +134,11 @@ module Phaser {
|
|||||||
this._easingFunction = ease;
|
this._easingFunction = ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (delay > 0)
|
||||||
|
{
|
||||||
|
this._delayTime = delay;
|
||||||
|
}
|
||||||
|
|
||||||
if (autoStart === true)
|
if (autoStart === true)
|
||||||
{
|
{
|
||||||
return this.start();
|
return this.start();
|
||||||
@@ -78,6 +150,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start to tween.
|
||||||
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
|
|
||||||
if (this._game === null || this._object === null)
|
if (this._game === null || this._object === null)
|
||||||
@@ -120,6 +195,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop tweening.
|
||||||
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
|
|
||||||
if (this._manager !== null)
|
if (this._manager !== null)
|
||||||
@@ -164,6 +242,11 @@ module Phaser {
|
|||||||
return this._interpolationFunction;
|
return this._interpolationFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add another chained tween, which will start automatically when the one before it completes.
|
||||||
|
* @param tween {Phaser.Tween} Tween object you want to chain with this.
|
||||||
|
* @return {Phaser.Tween} Itselfe.
|
||||||
|
*/
|
||||||
public chain(tween:Phaser.Tween) {
|
public chain(tween:Phaser.Tween) {
|
||||||
|
|
||||||
this._chainedTweens.push(tween);
|
this._chainedTweens.push(tween);
|
||||||
@@ -172,8 +255,16 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug value?
|
||||||
|
*/
|
||||||
public debugValue;
|
public debugValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update tweening.
|
||||||
|
* @param time {number} Current time from game clock.
|
||||||
|
* @return {boolean} Return false if this completed and no need to update, otherwise return true.
|
||||||
|
*/
|
||||||
public update(time) {
|
public update(time) {
|
||||||
|
|
||||||
if (this._game.paused == true)
|
if (this._game.paused == true)
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ module Phaser {
|
|||||||
|
|
||||||
export class Animation {
|
export class Animation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Animation constructor
|
||||||
|
* Create a new <code>Animation</code>.
|
||||||
|
*
|
||||||
|
* @param parent {Sprite} Owner sprite of this animation.
|
||||||
|
* @param frameData {FrameData} The FrameData object contains animation data.
|
||||||
|
* @param name {string} Unique name of this animation.
|
||||||
|
* @param frames {number[]/string[]} An array of numbers or strings indicating what frames to play in what order.
|
||||||
|
* @param delay {number} Time between frames in ms.
|
||||||
|
* @param looped {boolean} Whether or not the animation is looped or just plays once.
|
||||||
|
*/
|
||||||
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool) {
|
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -29,21 +40,81 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to its owner sprite.
|
||||||
|
* @type {Sprite}
|
||||||
|
*/
|
||||||
private _parent: Sprite;
|
private _parent: Sprite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Animation frame container.
|
||||||
|
* @type {number[]}
|
||||||
|
*/
|
||||||
private _frames: number[];
|
private _frames: number[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frame data of this animation.(parsed from sprite sheet)
|
||||||
|
* @type {FrameData}
|
||||||
|
*/
|
||||||
private _frameData: FrameData;
|
private _frameData: FrameData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index of current frame.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
private _frameIndex: number;
|
private _frameIndex: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time when switched to last frame (in ms).
|
||||||
|
* @type number
|
||||||
|
*/
|
||||||
private _timeLastFrame: number;
|
private _timeLastFrame: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time when this will switch to next frame (in ms).
|
||||||
|
* @type number
|
||||||
|
*/
|
||||||
private _timeNextFrame: number;
|
private _timeNextFrame: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of this animation.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently played frame instance.
|
||||||
|
* @type {Frame}
|
||||||
|
*/
|
||||||
public currentFrame: Frame;
|
public currentFrame: Frame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this animation finished playing.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public isFinished: bool;
|
public isFinished: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whethor or not this animation is currently playing.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public isPlaying: bool;
|
public isPlaying: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the animation is looped.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public looped: bool;
|
public looped: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time between frames in ms.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public delay: number;
|
public delay: number;
|
||||||
|
|
||||||
public get frameTotal(): number {
|
public get frameTotal(): number {
|
||||||
@@ -51,7 +122,16 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get frame(): number {
|
public get frame(): number {
|
||||||
return this._frameIndex;
|
|
||||||
|
if (this.currentFrame !== null)
|
||||||
|
{
|
||||||
|
return this.currentFrame.index;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this._frameIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public set frame(value: number) {
|
public set frame(value: number) {
|
||||||
@@ -60,13 +140,18 @@ module Phaser {
|
|||||||
|
|
||||||
if (this.currentFrame !== null)
|
if (this.currentFrame !== null)
|
||||||
{
|
{
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
this._parent.frameBounds.width = this.currentFrame.width;
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
this._parent.frameBounds.height = this.currentFrame.height;
|
||||||
this._frameIndex = value;
|
this._frameIndex = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play this animation.
|
||||||
|
* @param frameRate {number} FrameRate you want to specify instead of using default.
|
||||||
|
* @param loop {boolean} Whether or not the animation is looped or just plays once.
|
||||||
|
*/
|
||||||
public play(frameRate?: number = null, loop?: bool) {
|
public play(frameRate?: number = null, loop?: bool) {
|
||||||
|
|
||||||
if (frameRate !== null)
|
if (frameRate !== null)
|
||||||
@@ -90,6 +175,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play this animation from the first frame.
|
||||||
|
*/
|
||||||
public restart() {
|
public restart() {
|
||||||
|
|
||||||
this.isPlaying = true;
|
this.isPlaying = true;
|
||||||
@@ -103,6 +191,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop playing animation and set it finished.
|
||||||
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
|
|
||||||
this.isPlaying = false;
|
this.isPlaying = false;
|
||||||
@@ -110,6 +201,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update animation frames.
|
||||||
|
*/
|
||||||
public update(): bool {
|
public update(): bool {
|
||||||
|
|
||||||
if (this.isPlaying == true && this._game.time.now >= this._timeNextFrame)
|
if (this.isPlaying == true && this._game.time.now >= this._timeNextFrame)
|
||||||
@@ -143,6 +237,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up animation memory.
|
||||||
|
*/
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
|
||||||
this._game = null;
|
this._game = null;
|
||||||
@@ -154,11 +251,14 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Animation complete callback method.
|
||||||
|
*/
|
||||||
private onComplete() {
|
private onComplete() {
|
||||||
|
|
||||||
this.isPlaying = false;
|
this.isPlaying = false;
|
||||||
this.isFinished = true;
|
this.isFinished = true;
|
||||||
// callback
|
// callback goes here
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ module Phaser {
|
|||||||
|
|
||||||
export class AnimationLoader {
|
export class AnimationLoader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a sprite sheet from asset data.
|
||||||
|
* @param key {string} Asset key for the sprite sheet data.
|
||||||
|
* @param frameWidth {number} Width of animation frame.
|
||||||
|
* @param frameHeight {number} Height of animation frame.
|
||||||
|
* @param frameMax {number} Number of animation frames.
|
||||||
|
* @return {FrameData} Generated FrameData object.
|
||||||
|
*/
|
||||||
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData {
|
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData {
|
||||||
|
|
||||||
// How big is our image?
|
// How big is our image?
|
||||||
@@ -63,8 +71,19 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse frame datas from json.
|
||||||
|
* @param json {object} Json data you want to parse.
|
||||||
|
* @return {FrameData} Generated FrameData object.
|
||||||
|
*/
|
||||||
public static parseJSONData(game: Game, json): FrameData {
|
public static parseJSONData(game: Game, json): FrameData {
|
||||||
|
|
||||||
|
// Malformed?
|
||||||
|
if (!json['frames'])
|
||||||
|
{
|
||||||
|
throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
|
||||||
|
}
|
||||||
|
|
||||||
// Let's create some frames then
|
// Let's create some frames then
|
||||||
var data: FrameData = new FrameData();
|
var data: FrameData = new FrameData();
|
||||||
|
|
||||||
@@ -83,6 +102,38 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static parseXMLData(game: Game, xml, format: number): FrameData {
|
||||||
|
|
||||||
|
// Malformed?
|
||||||
|
if (!xml.getElementsByTagName('TextureAtlas'))
|
||||||
|
{
|
||||||
|
throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing <TextureAtlas> tag");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's create some frames then
|
||||||
|
var data: FrameData = new FrameData();
|
||||||
|
|
||||||
|
var frames = xml.getElementsByTagName('SubTexture');
|
||||||
|
|
||||||
|
var newFrame: Frame;
|
||||||
|
|
||||||
|
for (var i = 0; i < frames.length; i++)
|
||||||
|
{
|
||||||
|
var frame = frames[i].attributes;
|
||||||
|
|
||||||
|
newFrame = data.addFrame(new Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
|
||||||
|
|
||||||
|
// Trimmed?
|
||||||
|
if (frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0')
|
||||||
|
{
|
||||||
|
newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,16 @@ module Phaser {
|
|||||||
|
|
||||||
export class Frame {
|
export class Frame {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frame constructor
|
||||||
|
* Create a new <code>Frame</code> with specific position, size and name.
|
||||||
|
*
|
||||||
|
* @param x {number} X position within the image to cut from.
|
||||||
|
* @param y {number} Y position within the image to cut from.
|
||||||
|
* @param width {number} Width of the frame.
|
||||||
|
* @param height {number} Height of the frame.
|
||||||
|
* @param name {string} Name of this frame.
|
||||||
|
*/
|
||||||
constructor(x: number, y: number, width: number, height: number, name: string) {
|
constructor(x: number, y: number, width: number, height: number, name: string) {
|
||||||
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@@ -23,40 +33,113 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position within the image to cut from
|
/**
|
||||||
|
* X position within the image to cut from.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public x: number;
|
public x: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Y position within the image to cut from.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public y: number;
|
public y: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of the frame.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public width: number;
|
public width: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Height of the frame.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public height: number;
|
public height: number;
|
||||||
|
|
||||||
// Useful for Sprite Sheets
|
/**
|
||||||
|
* Useful for Sprite Sheets.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public index: number;
|
public index: number;
|
||||||
|
|
||||||
// Useful for Texture Atlas files (is set to the filename value)
|
/**
|
||||||
|
* Useful for Texture Atlas files. (is set to the filename value)
|
||||||
|
*/
|
||||||
public name: string = '';
|
public name: string = '';
|
||||||
|
|
||||||
// Rotated? (not yet implemented)
|
/**
|
||||||
|
* Rotated? (not yet implemented)
|
||||||
|
*/
|
||||||
public rotated: bool = false;
|
public rotated: bool = false;
|
||||||
|
|
||||||
// Either cw or ccw, rotation is always 90 degrees
|
/**
|
||||||
|
* Either cw or ccw, rotation is always 90 degrees.
|
||||||
|
*/
|
||||||
public rotationDirection: string = 'cw';
|
public rotationDirection: string = 'cw';
|
||||||
|
|
||||||
// Was it trimmed when packed?
|
/**
|
||||||
|
* Was it trimmed when packed?
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
public trimmed: bool;
|
public trimmed: bool;
|
||||||
|
|
||||||
// The coordinates of the trimmed sprite inside the original sprite
|
// The coordinates of the trimmed sprite inside the original sprite
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of the original sprite.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public sourceSizeW: number;
|
public sourceSizeW: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Height of the original sprite.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public sourceSizeH: number;
|
public sourceSizeH: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* X position of the trimmed sprite inside original sprite.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public spriteSourceSizeX: number;
|
public spriteSourceSizeX: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Y position of the trimmed sprite inside original sprite.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public spriteSourceSizeY: number;
|
public spriteSourceSizeY: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Width of the trimmed sprite.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public spriteSourceSizeW: number;
|
public spriteSourceSizeW: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Height of the trimmed sprite.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
public spriteSourceSizeH: number;
|
public spriteSourceSizeH: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set rotation of this frame. (Not yet supported!)
|
||||||
|
*/
|
||||||
public setRotation(rotated: bool, rotationDirection: string) {
|
public setRotation(rotated: bool, rotationDirection: string) {
|
||||||
// Not yet supported
|
// Not yet supported
|
||||||
}
|
}
|
||||||
|
|
||||||
public setTrim(trimmed: bool, actualWidth, actualHeight, destX, destY, destWidth, destHeight, ) {
|
/**
|
||||||
|
* Set trim of the frame.
|
||||||
|
* @param trimmed {boolean} Whether this frame trimmed or not.
|
||||||
|
* @param actualWidth {number} Actual width of this frame.
|
||||||
|
* @param actualHeight {number} Actual height of this frame.
|
||||||
|
* @param destX {number} Destiny x position.
|
||||||
|
* @param destY {number} Destiny y position.
|
||||||
|
* @param destWidth {number} Destiny draw width.
|
||||||
|
* @param destHeight {number} Destiny draw height.
|
||||||
|
*/
|
||||||
|
public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number) {
|
||||||
|
|
||||||
this.trimmed = trimmed;
|
this.trimmed = trimmed;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ module Phaser {
|
|||||||
|
|
||||||
export class FrameData {
|
export class FrameData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FrameData constructor
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
this._frames = [];
|
this._frames = [];
|
||||||
@@ -17,13 +20,24 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local frame container.
|
||||||
|
*/
|
||||||
private _frames: Frame[];
|
private _frames: Frame[];
|
||||||
|
/**
|
||||||
|
* Local frameName<->index container.
|
||||||
|
*/
|
||||||
private _frameNames;
|
private _frameNames;
|
||||||
|
|
||||||
public get total(): number {
|
public get total(): number {
|
||||||
return this._frames.length;
|
return this._frames.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new frame.
|
||||||
|
* @param frame {Frame} The frame you want to add.
|
||||||
|
* @return {Frame} The frame you just added.
|
||||||
|
*/
|
||||||
public addFrame(frame: Frame): Frame {
|
public addFrame(frame: Frame): Frame {
|
||||||
|
|
||||||
frame.index = this._frames.length;
|
frame.index = this._frames.length;
|
||||||
@@ -39,6 +53,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a frame by its index.
|
||||||
|
* @param index {number} Index of the frame you want to get.
|
||||||
|
* @return {Frame} The frame you want.
|
||||||
|
*/
|
||||||
public getFrame(index: number): Frame {
|
public getFrame(index: number): Frame {
|
||||||
|
|
||||||
if (this._frames[index])
|
if (this._frames[index])
|
||||||
@@ -50,6 +69,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a frame by its name.
|
||||||
|
* @param name {string} Name of the frame you want to get.
|
||||||
|
* @return {Frame} The frame you want.
|
||||||
|
*/
|
||||||
public getFrameByName(name: string): Frame {
|
public getFrameByName(name: string): Frame {
|
||||||
|
|
||||||
if (this._frameNames[name] >= 0)
|
if (this._frameNames[name] >= 0)
|
||||||
@@ -61,6 +85,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether there's a frame with given name.
|
||||||
|
* @param name {string} Name of the frame you want to check.
|
||||||
|
* @return {boolean} True if frame with given name found, otherwise return false.
|
||||||
|
*/
|
||||||
public checkFrameName(name: string): bool {
|
public checkFrameName(name: string): bool {
|
||||||
|
|
||||||
if (this._frameNames[name] >= 0)
|
if (this._frameNames[name] >= 0)
|
||||||
@@ -72,6 +101,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get ranges of frames in an array.
|
||||||
|
* @param start {number} Start index of frames you want.
|
||||||
|
* @param end {number} End index of frames you want.
|
||||||
|
* @param [output] {Frame[]} result will be added into this array.
|
||||||
|
* @return {Frame[]} Ranges of specific frames in an array.
|
||||||
|
*/
|
||||||
public getFrameRange(start: number, end: number, output?: Frame[] = []): Frame[] {
|
public getFrameRange(start: number, end: number, output?: Frame[] = []): Frame[] {
|
||||||
|
|
||||||
for (var i = start; i <= end; i++)
|
for (var i = start; i <= end; i++)
|
||||||
@@ -83,6 +119,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all indexes of frames by giving their name.
|
||||||
|
* @param [output] {number[]} result will be added into this array.
|
||||||
|
* @return {number[]} Indexes of specific frames in an array.
|
||||||
|
*/
|
||||||
public getFrameIndexes(output?: number[] = []): number[] {
|
public getFrameIndexes(output?: number[] = []): number[] {
|
||||||
|
|
||||||
output.length = 0;
|
output.length = 0;
|
||||||
@@ -96,6 +137,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all names of frames by giving their indexes.
|
||||||
|
* @param [output] {number[]} result will be added into this array.
|
||||||
|
* @return {number[]} Names of specific frames in an array.
|
||||||
|
*/
|
||||||
public getFrameIndexesByName(input: string[]): number[] {
|
public getFrameIndexesByName(input: string[]): number[] {
|
||||||
|
|
||||||
var output: number[] = [];
|
var output: number[] = [];
|
||||||
@@ -112,10 +158,19 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all frames in this frame data.
|
||||||
|
* @return {Frame[]} All the frames in an array.
|
||||||
|
*/
|
||||||
public getAllFrames(): Frame[] {
|
public getAllFrames(): Frame[] {
|
||||||
return this._frames;
|
return this._frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All frames with specific ranges.
|
||||||
|
* @param range {number[]} Ranges in an array.
|
||||||
|
* @return {Frame[]} All frames in an array.
|
||||||
|
*/
|
||||||
public getFrames(range: number[]) {
|
public getFrames(range: number[]) {
|
||||||
|
|
||||||
var output: Frame[] = [];
|
var output: Frame[] = [];
|
||||||
|
|||||||
@@ -1,319 +0,0 @@
|
|||||||
/// <reference path="../../Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Finger
|
|
||||||
*
|
|
||||||
* A Finger object is used by the Touch manager and represents a single finger on the touch screen.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Finger {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @param {Phaser.Game} game.
|
|
||||||
* @return {Phaser.Finger} This object.
|
|
||||||
*/
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
this.active = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property _game
|
|
||||||
* @type Phaser.Game
|
|
||||||
* @private
|
|
||||||
**/
|
|
||||||
private _game: Game;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An identification number for each touch point. When a touch point becomes active, it must be assigned an identifier that is distinct from any other active touch point. While the touch point remains active, all events that refer to it must assign it the same identifier.
|
|
||||||
* @property identifier
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public identifier: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property active
|
|
||||||
* @type Boolean
|
|
||||||
*/
|
|
||||||
public active: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property point
|
|
||||||
* @type Point
|
|
||||||
**/
|
|
||||||
public point: Point = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property circle
|
|
||||||
* @type Circle
|
|
||||||
**/
|
|
||||||
public circle: Circle = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property withinGame
|
|
||||||
* @type Boolean
|
|
||||||
*/
|
|
||||||
public withinGame: bool = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
|
||||||
* @property clientX
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public clientX: number = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
/**
|
|
||||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
|
||||||
* @property clientY
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public clientY: number = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
/**
|
|
||||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
|
||||||
* @property pageX
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public pageX: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
|
||||||
* @property pageY
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public pageY: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The horizontal coordinate of point relative to the screen in pixels
|
|
||||||
* @property screenX
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public screenX: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The vertical coordinate of point relative to the screen in pixels
|
|
||||||
* @property screenY
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public screenY: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The horizontal coordinate of point relative to the game element
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public x: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The vertical coordinate of point relative to the game element
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public y: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Element on which the touch point started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element.
|
|
||||||
* @property target
|
|
||||||
* @type Any
|
|
||||||
*/
|
|
||||||
public target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property isDown
|
|
||||||
* @type Boolean
|
|
||||||
**/
|
|
||||||
public isDown: bool = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property isUp
|
|
||||||
* @type Boolean
|
|
||||||
**/
|
|
||||||
public isUp: bool = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property timeDown
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public timeDown: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property duration
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public duration: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property timeUp
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public timeUp: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property justPressedRate
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public justPressedRate: number = 200;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property justReleasedRate
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public justReleasedRate: number = 200;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method start
|
|
||||||
* @param {Any} event
|
|
||||||
*/
|
|
||||||
public start(event) {
|
|
||||||
|
|
||||||
this.identifier = event.identifier;
|
|
||||||
this.target = event.target;
|
|
||||||
|
|
||||||
// populate geom objects
|
|
||||||
if (this.point === null)
|
|
||||||
{
|
|
||||||
this.point = new Point();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.circle === null)
|
|
||||||
{
|
|
||||||
this.circle = new Circle(0, 0, 44);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.move(event);
|
|
||||||
|
|
||||||
this.active = true;
|
|
||||||
this.withinGame = true;
|
|
||||||
this.isDown = true;
|
|
||||||
this.isUp = false;
|
|
||||||
this.timeDown = this._game.time.now;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method move
|
|
||||||
* @param {Any} event
|
|
||||||
*/
|
|
||||||
public move(event) {
|
|
||||||
|
|
||||||
this.clientX = event.clientX;
|
|
||||||
this.clientY = event.clientY;
|
|
||||||
this.pageX = event.pageX;
|
|
||||||
this.pageY = event.pageY;
|
|
||||||
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.point.setTo(this.x, this.y);
|
|
||||||
this.circle.setTo(this.x, this.y, 44);
|
|
||||||
|
|
||||||
// Droppings history (used for gestures and motion tracking)
|
|
||||||
|
|
||||||
this.duration = this._game.time.now - this.timeDown;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method leave
|
|
||||||
* @param {Any} event
|
|
||||||
*/
|
|
||||||
public leave(event) {
|
|
||||||
|
|
||||||
this.withinGame = false;
|
|
||||||
this.move(event);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method stop
|
|
||||||
* @param {Any} event
|
|
||||||
*/
|
|
||||||
public stop(event) {
|
|
||||||
|
|
||||||
this.active = false;
|
|
||||||
this.withinGame = false;
|
|
||||||
|
|
||||||
this.isDown = false;
|
|
||||||
this.isUp = true;
|
|
||||||
this.timeUp = this._game.time.now;
|
|
||||||
this.duration = this.timeUp - this.timeDown;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method justPressed
|
|
||||||
* @param {Number} [duration].
|
|
||||||
* @return {Boolean}
|
|
||||||
*/
|
|
||||||
public justPressed(duration?: number = this.justPressedRate): bool {
|
|
||||||
|
|
||||||
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method justReleased
|
|
||||||
* @param {Number} [duration].
|
|
||||||
* @return {Boolean}
|
|
||||||
*/
|
|
||||||
public justReleased(duration?: number = this.justReleasedRate): bool {
|
|
||||||
|
|
||||||
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this object.
|
|
||||||
* @method toString
|
|
||||||
* @return {string} a string representation of the instance.
|
|
||||||
**/
|
|
||||||
public toString(): string {
|
|
||||||
|
|
||||||
return "[{Finger (identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/// <reference path="../../Game.ts" />
|
||||||
|
/// <reference path="Pointer.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Gestures
|
||||||
|
*
|
||||||
|
* The Gesture class monitors for gestures and dispatches the resulting signals when they occur.
|
||||||
|
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class Gestures {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param {Game} game.
|
||||||
|
* @return {Touch} This object.
|
||||||
|
*/
|
||||||
|
constructor(game: Game) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
* @property _game
|
||||||
|
* @type {Game}
|
||||||
|
* @private
|
||||||
|
**/
|
||||||
|
private _game: Game;
|
||||||
|
|
||||||
|
private _p1: Pointer;
|
||||||
|
private _p2: Pointer;
|
||||||
|
private _p3: Pointer;
|
||||||
|
private _p4: Pointer;
|
||||||
|
private _p5: Pointer;
|
||||||
|
private _p6: Pointer;
|
||||||
|
private _p7: Pointer;
|
||||||
|
private _p8: Pointer;
|
||||||
|
private _p9: Pointer;
|
||||||
|
private _p10: Pointer;
|
||||||
|
|
||||||
|
public start() {
|
||||||
|
|
||||||
|
// Local references to the Phaser.Input.pointer objects
|
||||||
|
this._p1 = this._game.input.pointer1;
|
||||||
|
this._p2 = this._game.input.pointer2;
|
||||||
|
this._p3 = this._game.input.pointer3;
|
||||||
|
this._p4 = this._game.input.pointer4;
|
||||||
|
this._p5 = this._game.input.pointer5;
|
||||||
|
this._p6 = this._game.input.pointer6;
|
||||||
|
this._p7 = this._game.input.pointer7;
|
||||||
|
this._p8 = this._game.input.pointer8;
|
||||||
|
this._p9 = this._game.input.pointer9;
|
||||||
|
this._p10 = this._game.input.pointer10;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+798
-16
@@ -1,10 +1,14 @@
|
|||||||
/// <reference path="../../Game.ts" />
|
/// <reference path="../../Game.ts" />
|
||||||
/// <reference path="../../Signal.ts" />
|
/// <reference path="../../Signal.ts" />
|
||||||
|
/// <reference path="Pointer.ts" />
|
||||||
|
/// <reference path="MSPointer.ts" />
|
||||||
|
/// <reference path="Gestures.ts" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phaser - Input
|
* Phaser - Input
|
||||||
*
|
*
|
||||||
* A game specific Input manager that looks after the mouse, keyboard and touch objects. This is updated by the core game loop.
|
* A game specific Input manager that looks after the mouse, keyboard and touch objects.
|
||||||
|
* This is updated by the core game loop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
@@ -15,77 +19,855 @@ module Phaser {
|
|||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
|
|
||||||
|
this.mousePointer = new Pointer(this._game, 0);
|
||||||
|
this.pointer1 = new Pointer(this._game, 1);
|
||||||
|
this.pointer2 = new Pointer(this._game, 2);
|
||||||
|
this.pointer3 = new Pointer(this._game, 3);
|
||||||
|
this.pointer4 = new Pointer(this._game, 4);
|
||||||
|
this.pointer5 = new Pointer(this._game, 5);
|
||||||
|
|
||||||
this.mouse = new Mouse(this._game);
|
this.mouse = new Mouse(this._game);
|
||||||
this.keyboard = new Keyboard(this._game);
|
this.keyboard = new Keyboard(this._game);
|
||||||
this.touch = new Touch(this._game);
|
this.touch = new Touch(this._game);
|
||||||
|
this.mspointer = new MSPointer(this._game);
|
||||||
|
this.gestures = new Gestures(this._game);
|
||||||
|
|
||||||
this.onDown = new Phaser.Signal();
|
this.onDown = new Phaser.Signal();
|
||||||
this.onUp = new Phaser.Signal();
|
this.onUp = new Phaser.Signal();
|
||||||
|
this.onTap = new Phaser.Signal();
|
||||||
|
this.onHold = new Phaser.Signal();
|
||||||
|
|
||||||
|
this.position = new Vector2;
|
||||||
|
this.circle = new Circle(0, 0, 44);
|
||||||
|
|
||||||
|
this.currentPointers = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
public disabled: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
|
||||||
|
*/
|
||||||
|
public multiInputOverride: number = Input.MOUSE_TOUCH_COMBINE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static defining the behaviour expected on a multi-input device system.
|
||||||
|
* With this setting when the mouse is used it updates the Input.x/y globals regardless if another pointer is active or not
|
||||||
|
*/
|
||||||
|
public static MOUSE_OVERRIDES_TOUCH: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static defining the behaviour expected on a multi-input device system.
|
||||||
|
* With this setting when the mouse is used it only updates the Input.x/y globals if no other pointer is active
|
||||||
|
*/
|
||||||
|
public static TOUCH_OVERRIDES_MOUSE: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static defining the behaviour expected on a multi-input device system.
|
||||||
|
* With this setting when the mouse is used it updates the Input.x/y globals at the same time as any active Pointer objects might
|
||||||
|
*/
|
||||||
|
public static MOUSE_TOUCH_COMBINE: number = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser.Mouse handler
|
||||||
|
* @type {Mouse}
|
||||||
|
*/
|
||||||
public mouse: Mouse;
|
public mouse: Mouse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser.Keyboard handler
|
||||||
|
* @type {Keyboard}
|
||||||
|
*/
|
||||||
public keyboard: Keyboard;
|
public keyboard: Keyboard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser.Touch handler
|
||||||
|
* @type {Touch}
|
||||||
|
*/
|
||||||
public touch: Touch;
|
public touch: Touch;
|
||||||
|
|
||||||
public x: number = 0;
|
/**
|
||||||
public y: number = 0;
|
* Phaser.MSPointer handler
|
||||||
|
* @type {MSPointer}
|
||||||
|
*/
|
||||||
|
public mspointer: MSPointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser.Gestures handler
|
||||||
|
* @type {Gestures}
|
||||||
|
*/
|
||||||
|
public gestures: Gestures;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A vector object representing the current position of the Pointer.
|
||||||
|
* @property vector
|
||||||
|
* @type {Vector2}
|
||||||
|
**/
|
||||||
|
public position: Vector2 = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Circle object centered on the x/y screen coordinates of the Input.
|
||||||
|
* Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything
|
||||||
|
* @property circle
|
||||||
|
* @type {Circle}
|
||||||
|
**/
|
||||||
|
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}
|
||||||
|
*/
|
||||||
public scaleX: number = 1;
|
public scaleX: number = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
public scaleY: number = 1;
|
public scaleY: number = 1;
|
||||||
|
|
||||||
public worldX: number = 0;
|
/**
|
||||||
public worldY: number = 0;
|
* The maximum number of Pointers allowed to be active at any one time.
|
||||||
|
* For lots of games it's useful to set this to 1
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public maxPointers: number = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current number of active Pointers.
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public currentPointers: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Signal dispatched when a mouse/Pointer object is pressed
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
public onDown: Phaser.Signal;
|
public onDown: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Signal dispatched when a mouse/Pointer object is released
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
public onUp: Phaser.Signal;
|
public onUp: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Signal dispatched when a Pointer object (including the mouse) is tapped: pressed and released quickly.
|
||||||
|
* The signal sends 2 parameters. The Pointer that caused it and a boolean depending if the tap was a single tap or a double tap.
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
|
public onTap: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Signal dispatched when a Pointer object (including the mouse) is held down
|
||||||
|
* @type {Phaser.Signal}
|
||||||
|
*/
|
||||||
|
public onHold: Phaser.Signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click
|
||||||
|
* @property tapRate
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public tapRate: number = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
|
||||||
|
* @property doubleTapRate
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public doubleTapRate: number = 300;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
|
||||||
|
* @property holdRate
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public holdRate: number = 2000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds below which the Pointer is considered justPressed
|
||||||
|
* @property justPressedRate
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public justPressedRate: number = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds below which the Pointer is considered justReleased
|
||||||
|
* @property justReleasedRate
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public justReleasedRate: number = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if the Pointer objects should record a history of x/y coordinates they have passed through.
|
||||||
|
* The history is cleared each time the Pointer is pressed down.
|
||||||
|
* The history is updated at the rate specified in Input.pollRate
|
||||||
|
* @property recordPointerHistory
|
||||||
|
* @type {Boolean}
|
||||||
|
**/
|
||||||
|
public recordPointerHistory: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rate in milliseconds at which the Pointer objects should update their tracking history
|
||||||
|
* @property recordRate
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public recordRate: number = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The total number of entries that can be recorded into the Pointer objects tracking history.
|
||||||
|
* The the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
|
||||||
|
* @property recordLimit
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public recordLimit: number = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object specifically used by the Mouse
|
||||||
|
* @property mousePointer
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public mousePointer: Pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer1
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer1: Pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer2
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer2: Pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer3
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer3: Pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer4
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer4: Pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer5
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer5: Pointer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer6
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer6: Pointer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer7
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer7: Pointer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer8
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer8: Pointer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer9
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer9: Pointer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Pointer object
|
||||||
|
* @property pointer10
|
||||||
|
* @type {Pointer}
|
||||||
|
**/
|
||||||
|
public pointer10: Pointer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The screen X coordinate
|
||||||
|
* @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
|
||||||
|
* @property y
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public get y(): number {
|
||||||
|
|
||||||
|
return this._y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public set y(value: number) {
|
||||||
|
|
||||||
|
this._y = Math.round(value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more
|
||||||
|
* use this to create a new one, up to a maximum of 10.
|
||||||
|
* @method addPointer
|
||||||
|
* @return {Pointer} A reference to the new Pointer object
|
||||||
|
**/
|
||||||
|
public addPointer(): Pointer {
|
||||||
|
|
||||||
|
var next: number = 0;
|
||||||
|
|
||||||
|
if (this.pointer10 === null)
|
||||||
|
{
|
||||||
|
next = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pointer9 === null)
|
||||||
|
{
|
||||||
|
next = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pointer8 === null)
|
||||||
|
{
|
||||||
|
next = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pointer7 === null)
|
||||||
|
{
|
||||||
|
next = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pointer6 === null)
|
||||||
|
{
|
||||||
|
next = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next == 0)
|
||||||
|
{
|
||||||
|
throw new Error("You can only have 10 Pointer objects");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this['pointer' + next] = new Pointer(this._game, next);
|
||||||
|
return this['pointer' + next];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Input Manager running
|
||||||
|
* @method start
|
||||||
|
**/
|
||||||
|
public start() {
|
||||||
|
|
||||||
|
this.mouse.start();
|
||||||
|
this.keyboard.start();
|
||||||
|
this.touch.start();
|
||||||
|
this.mspointer.start();
|
||||||
|
this.gestures.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the Input Manager. Called by the core Game loop.
|
||||||
|
* @method update
|
||||||
|
**/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
this.x = Math.round(this.x);
|
this.mousePointer.update();
|
||||||
this.y = Math.round(this.y);
|
this.pointer1.update();
|
||||||
|
this.pointer2.update();
|
||||||
|
this.pointer3.update();
|
||||||
|
this.pointer4.update();
|
||||||
|
this.pointer5.update();
|
||||||
|
|
||||||
this.worldX = this._game.camera.worldView.x + this.x;
|
if (this.pointer6) { this.pointer6.update(); }
|
||||||
this.worldY = this._game.camera.worldView.y + this.y;
|
if (this.pointer7) { this.pointer7.update(); }
|
||||||
|
if (this.pointer8) { this.pointer8.update(); }
|
||||||
this.mouse.update();
|
if (this.pointer9) { this.pointer9.update(); }
|
||||||
this.touch.update();
|
if (this.pointer10) { this.pointer10.update(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset() {
|
/**
|
||||||
|
* Reset all of the Pointers and Input states
|
||||||
|
* @method reset
|
||||||
|
* @param hard {Boolean} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
|
||||||
|
**/
|
||||||
|
public reset(hard?: bool = false) {
|
||||||
|
|
||||||
this.mouse.reset();
|
|
||||||
this.keyboard.reset();
|
this.keyboard.reset();
|
||||||
this.touch.reset();
|
|
||||||
|
this.pointer1.reset();
|
||||||
|
this.pointer2.reset();
|
||||||
|
this.pointer3.reset();
|
||||||
|
this.pointer4.reset();
|
||||||
|
this.pointer5.reset();
|
||||||
|
|
||||||
|
if (this.pointer6) { this.pointer6.reset(); }
|
||||||
|
if (this.pointer7) { this.pointer7.reset(); }
|
||||||
|
if (this.pointer8) { this.pointer8.reset(); }
|
||||||
|
if (this.pointer9) { this.pointer9.reset(); }
|
||||||
|
if (this.pointer10) { this.pointer10.reset(); }
|
||||||
|
|
||||||
|
this.currentPointers = 0;
|
||||||
|
|
||||||
|
if (hard == true)
|
||||||
|
{
|
||||||
|
this.onDown = new Phaser.Signal();
|
||||||
|
this.onUp = new Phaser.Signal();
|
||||||
|
this.onTap = new Phaser.Signal();
|
||||||
|
this.onHold = new Phaser.Signal();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the total number of inactive Pointers
|
||||||
|
* @method totalInactivePointers
|
||||||
|
* @return {Number} The number of Pointers currently inactive
|
||||||
|
**/
|
||||||
|
public get totalInactivePointers(): number {
|
||||||
|
|
||||||
|
return 10 - this.currentPointers;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculates the total number of active Pointers
|
||||||
|
* @method totalActivePointers
|
||||||
|
* @return {Number} The number of Pointers currently active
|
||||||
|
**/
|
||||||
|
public get totalActivePointers(): number {
|
||||||
|
|
||||||
|
this.currentPointers = 0;
|
||||||
|
|
||||||
|
if (this.pointer1.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer2.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer3.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer4.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer5.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer6 && this.pointer6.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer7 && this.pointer7.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer8 && this.pointer8.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer9 && this.pointer9.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
else if (this.pointer10 && this.pointer10.active == true)
|
||||||
|
{
|
||||||
|
this.currentPointers++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.currentPointers;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the first free Pointer object and start it, passing in the event data.
|
||||||
|
* @method startPointer
|
||||||
|
* @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 {
|
||||||
|
|
||||||
|
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unrolled for speed
|
||||||
|
if (this.pointer1.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer1.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer2.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer2.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer3.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer3.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer4.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer4.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer5.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer5.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer6 && this.pointer6.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer6.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer7 && this.pointer7.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer7.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer8 && this.pointer8.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer8.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer9 && this.pointer9.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer9.start(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer10 && this.pointer10.active == false)
|
||||||
|
{
|
||||||
|
return this.pointer10.start(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the matching Pointer object, passing in the event data.
|
||||||
|
* @method updatePointer
|
||||||
|
* @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 {
|
||||||
|
|
||||||
|
// Unrolled for speed
|
||||||
|
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer1.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer2.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer3.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer4.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer5.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer6.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer7.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer8.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer9.move(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer10.move(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the matching Pointer object, passing in the event data.
|
||||||
|
* @method stopPointer
|
||||||
|
* @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 {
|
||||||
|
|
||||||
|
// Unrolled for speed
|
||||||
|
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer1.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer2.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer3.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer4.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer5.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer6.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer7.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer8.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer9.stop(event);
|
||||||
|
}
|
||||||
|
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||||
|
{
|
||||||
|
return this.pointer10.stop(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next Pointer object whos active property matches the given state
|
||||||
|
* @method getPointer
|
||||||
|
* @param {Boolean} state The state the Pointer should be in (false for inactive, true for active)
|
||||||
|
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested state.
|
||||||
|
**/
|
||||||
|
public getPointer(state: bool = false): Pointer {
|
||||||
|
|
||||||
|
// Unrolled for speed
|
||||||
|
if (this.pointer1.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer1;
|
||||||
|
}
|
||||||
|
else if (this.pointer2.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer2;
|
||||||
|
}
|
||||||
|
else if (this.pointer3.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer3;
|
||||||
|
}
|
||||||
|
else if (this.pointer4.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer4;
|
||||||
|
}
|
||||||
|
else if (this.pointer5.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer5;
|
||||||
|
}
|
||||||
|
else if (this.pointer6 && this.pointer6.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer6;
|
||||||
|
}
|
||||||
|
else if (this.pointer7 && this.pointer7.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer7;
|
||||||
|
}
|
||||||
|
else if (this.pointer8 && this.pointer8.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer8;
|
||||||
|
}
|
||||||
|
else if (this.pointer9 && this.pointer9.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer9;
|
||||||
|
}
|
||||||
|
else if (this.pointer10 && this.pointer10.active == state)
|
||||||
|
{
|
||||||
|
return this.pointer10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Pointer object whos identified property matches the given identifier value
|
||||||
|
* @method getPointerFromIdentifier
|
||||||
|
* @param {Number} identifier The Pointer.identifier value to search for
|
||||||
|
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
|
||||||
|
**/
|
||||||
|
public getPointerFromIdentifier(identifier: number): Pointer {
|
||||||
|
|
||||||
|
// Unrolled for speed
|
||||||
|
if (this.pointer1.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer1;
|
||||||
|
}
|
||||||
|
else if (this.pointer2.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer2;
|
||||||
|
}
|
||||||
|
else if (this.pointer3.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer3;
|
||||||
|
}
|
||||||
|
else if (this.pointer4.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer4;
|
||||||
|
}
|
||||||
|
else if (this.pointer5.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer5;
|
||||||
|
}
|
||||||
|
else if (this.pointer6 && this.pointer6.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer6;
|
||||||
|
}
|
||||||
|
else if (this.pointer7 && this.pointer7.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer7;
|
||||||
|
}
|
||||||
|
else if (this.pointer8 && this.pointer8.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer8;
|
||||||
|
}
|
||||||
|
else if (this.pointer9 && this.pointer9.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer9;
|
||||||
|
}
|
||||||
|
else if (this.pointer10 && this.pointer10.identifier == identifier)
|
||||||
|
{
|
||||||
|
return this.pointer10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Camera} [camera]
|
||||||
|
*/
|
||||||
public getWorldX(camera?: Camera = this._game.camera) {
|
public getWorldX(camera?: Camera = this._game.camera) {
|
||||||
|
|
||||||
return camera.worldView.x + this.x;
|
return camera.worldView.x + this.x;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Camera} [camera]
|
||||||
|
*/
|
||||||
public getWorldY(camera?: Camera = this._game.camera) {
|
public getWorldY(camera?: Camera = this._game.camera) {
|
||||||
|
|
||||||
return camera.worldView.y + this.y;
|
return camera.worldView.y + this.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} x
|
||||||
|
* @param {Number} y
|
||||||
|
* @param {String} [color]
|
||||||
|
*/
|
||||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||||
|
|
||||||
this._game.stage.context.font = '14px Courier';
|
this._game.stage.context.font = '14px Courier';
|
||||||
this._game.stage.context.fillStyle = color;
|
this._game.stage.context.fillStyle = color;
|
||||||
this._game.stage.context.fillText('Input', x, y);
|
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('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
|
||||||
this._game.stage.context.fillText('World X: ' + this.worldX + ' World Y: ' + this.worldY, x, y + 28);
|
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.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the distance between two Pointer objects
|
||||||
|
* @method getDistance
|
||||||
|
* @param {Pointer} pointer1
|
||||||
|
* @param {Pointer} pointer2
|
||||||
|
**/
|
||||||
|
public getDistance(pointer1: Pointer, pointer2: Pointer): number {
|
||||||
|
return pointer1.position.distance(pointer2.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the angle between two Pointer objects
|
||||||
|
* @method getAngle
|
||||||
|
* @param {Pointer} pointer1
|
||||||
|
* @param {Pointer} pointer2
|
||||||
|
**/
|
||||||
|
public getAngle(pointer1: Pointer, pointer2: Pointer): number {
|
||||||
|
return pointer1.position.angle(pointer2.position);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,6 @@ module Phaser {
|
|||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
this.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +22,12 @@ module Phaser {
|
|||||||
private _keys = {};
|
private _keys = {};
|
||||||
private _capture = {};
|
private _capture = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
public disabled: bool = false;
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
|
|
||||||
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
|
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
|
||||||
@@ -30,6 +35,13 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default when a key is pressed Phaser will not stop the event from propagating up to the browser.
|
||||||
|
* There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll.
|
||||||
|
* You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser.
|
||||||
|
* Pass in either a single keycode or an array of keycodes.
|
||||||
|
* @param {Any} keycode
|
||||||
|
*/
|
||||||
public addKeyCapture(keycode) {
|
public addKeyCapture(keycode) {
|
||||||
|
|
||||||
if (typeof keycode === 'object')
|
if (typeof keycode === 'object')
|
||||||
@@ -46,6 +58,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} keycode
|
||||||
|
*/
|
||||||
public removeKeyCapture(keycode: number) {
|
public removeKeyCapture(keycode: number) {
|
||||||
|
|
||||||
delete this._capture[keycode];
|
delete this._capture[keycode];
|
||||||
@@ -58,8 +73,16 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {KeyboardEvent} event
|
||||||
|
*/
|
||||||
public onKeyDown(event: KeyboardEvent) {
|
public onKeyDown(event: KeyboardEvent) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._capture[event.keyCode])
|
if (this._capture[event.keyCode])
|
||||||
{
|
{
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -77,8 +100,16 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {KeyboardEvent} event
|
||||||
|
*/
|
||||||
public onKeyUp(event: KeyboardEvent) {
|
public onKeyUp(event: KeyboardEvent) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this._capture[event.keyCode])
|
if (this._capture[event.keyCode])
|
||||||
{
|
{
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -105,6 +136,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} keycode
|
||||||
|
* @param {Number} [duration]
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
public justPressed(keycode: number, duration?: number = 250): bool {
|
public justPressed(keycode: number, duration?: number = 250): bool {
|
||||||
|
|
||||||
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this._game.time.now - this._keys[keycode].timeDown < duration))
|
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this._game.time.now - this._keys[keycode].timeDown < duration))
|
||||||
@@ -118,6 +154,11 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} keycode
|
||||||
|
* @param {Number} [duration]
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
public justReleased(keycode: number, duration?: number = 250): bool {
|
public justReleased(keycode: number, duration?: number = 250): bool {
|
||||||
|
|
||||||
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this._game.time.now - this._keys[keycode].timeUp < duration))
|
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this._game.time.now - this._keys[keycode].timeUp < duration))
|
||||||
@@ -131,6 +172,10 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Number} keycode
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
public isDown(keycode: number): bool {
|
public isDown(keycode: number): bool {
|
||||||
|
|
||||||
if (this._keys[keycode])
|
if (this._keys[keycode])
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
/// <reference path="../../Game.ts" />
|
||||||
|
/// <reference path="Pointer.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - MSPointer
|
||||||
|
*
|
||||||
|
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
|
||||||
|
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
|
||||||
|
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class MSPointer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param {Game} game.
|
||||||
|
* @return {MSPointer} This object.
|
||||||
|
*/
|
||||||
|
constructor(game: Game) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
* @property _game
|
||||||
|
* @type Game
|
||||||
|
* @private
|
||||||
|
**/
|
||||||
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
public disabled: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the event listeners running
|
||||||
|
* @method start
|
||||||
|
*/
|
||||||
|
public start() {
|
||||||
|
|
||||||
|
if (this._game.device.mspointer == true)
|
||||||
|
{
|
||||||
|
this._game.stage.canvas.addEventListener('MSPointerDown', (event) => this.onPointerDown(event), false);
|
||||||
|
this._game.stage.canvas.addEventListener('MSPointerMove', (event) => this.onPointerMove(event), false);
|
||||||
|
this._game.stage.canvas.addEventListener('MSPointerUp', (event) => this.onPointerUp(event), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @method onPointerDown
|
||||||
|
* @param {Any} event
|
||||||
|
**/
|
||||||
|
private onPointerDown(event) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.identifier = event.pointerId;
|
||||||
|
|
||||||
|
this._game.input.startPointer(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @method onPointerMove
|
||||||
|
* @param {Any} event
|
||||||
|
**/
|
||||||
|
private onPointerMove(event) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.identifier = event.pointerId;
|
||||||
|
|
||||||
|
this._game.input.updatePointer(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @method onPointerUp
|
||||||
|
* @param {Any} event
|
||||||
|
**/
|
||||||
|
private onPointerUp(event) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.identifier = event.pointerId;
|
||||||
|
|
||||||
|
this._game.input.stopPointer(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the event listeners
|
||||||
|
* @method stop
|
||||||
|
*/
|
||||||
|
public stop() {
|
||||||
|
|
||||||
|
if (this._game.device.mspointer == true)
|
||||||
|
{
|
||||||
|
//this._game.stage.canvas.addEventListener('MSPointerDown', (event) => this.onPointerDown(event), false);
|
||||||
|
//this._game.stage.canvas.addEventListener('MSPointerMove', (event) => this.onPointerMove(event), false);
|
||||||
|
//this._game.stage.canvas.addEventListener('MSPointerUp', (event) => this.onPointerUp(event), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,27 +13,32 @@ module Phaser {
|
|||||||
constructor(game: Game) {
|
constructor(game: Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
this.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
* @property _game
|
||||||
|
* @type {Phaser.Game}
|
||||||
|
* @private
|
||||||
|
**/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
private _x: number = 0;
|
|
||||||
private _y: number = 0;
|
|
||||||
|
|
||||||
public button: number;
|
|
||||||
|
|
||||||
public static LEFT_BUTTON: number = 0;
|
public static LEFT_BUTTON: number = 0;
|
||||||
public static MIDDLE_BUTTON: number = 1;
|
public static MIDDLE_BUTTON: number = 1;
|
||||||
public static RIGHT_BUTTON: number = 2;
|
public static RIGHT_BUTTON: number = 2;
|
||||||
|
|
||||||
public isDown: bool = false;
|
/**
|
||||||
public isUp: bool = true;
|
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||||
public timeDown: number = 0;
|
* @type {Boolean}
|
||||||
public duration: number = 0;
|
*/
|
||||||
public timeUp: number = 0;
|
public disabled: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the event listeners running
|
||||||
|
* @method start
|
||||||
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
|
|
||||||
this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
|
this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
|
||||||
@@ -42,70 +47,63 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset() {
|
/**
|
||||||
|
* @param {MouseEvent} event
|
||||||
this.isDown = false;
|
*/
|
||||||
this.isUp = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public onMouseDown(event: MouseEvent) {
|
public onMouseDown(event: MouseEvent) {
|
||||||
|
|
||||||
this.button = event.button;
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
|
||||||
this._x = event.clientX - this._game.stage.x;
|
|
||||||
this._y = event.clientY - this._game.stage.y;
|
|
||||||
|
|
||||||
this._game.input.x = this._x * this._game.input.scaleX;
|
|
||||||
this._game.input.y = this._y * this._game.input.scaleY;
|
|
||||||
|
|
||||||
this.isDown = true;
|
|
||||||
this.isUp = false;
|
|
||||||
this.timeDown = this._game.time.now;
|
|
||||||
|
|
||||||
this._game.input.onDown.dispatch(this._game.input.x, this._game.input.y, this.timeDown);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
//this._game.input.x = this._x * this._game.input.scaleX;
|
|
||||||
//this._game.input.y = this._y * this._game.input.scaleY;
|
|
||||||
|
|
||||||
if (this.isDown)
|
|
||||||
{
|
{
|
||||||
this.duration = this._game.time.now - this.timeDown;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event['identifier'] = 0;
|
||||||
|
|
||||||
|
this._game.input.mousePointer.start(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {MouseEvent} event
|
||||||
|
*/
|
||||||
public onMouseMove(event: MouseEvent) {
|
public onMouseMove(event: MouseEvent) {
|
||||||
|
|
||||||
this.button = event.button;
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._x = event.clientX - this._game.stage.x;
|
event['identifier'] = 0;
|
||||||
this._y = event.clientY - this._game.stage.y;
|
|
||||||
|
|
||||||
this._game.input.x = this._x * this._game.input.scaleX;
|
this._game.input.mousePointer.move(event);
|
||||||
this._game.input.y = this._y * this._game.input.scaleY;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {MouseEvent} event
|
||||||
|
*/
|
||||||
public onMouseUp(event: MouseEvent) {
|
public onMouseUp(event: MouseEvent) {
|
||||||
|
|
||||||
this.button = event.button;
|
if (this._game.input.disabled || this.disabled)
|
||||||
this.isDown = false;
|
{
|
||||||
this.isUp = true;
|
return;
|
||||||
this.timeUp = this._game.time.now;
|
}
|
||||||
this.duration = this.timeUp - this.timeDown;
|
|
||||||
|
|
||||||
this._x = event.clientX - this._game.stage.x;
|
event['identifier'] = 0;
|
||||||
this._y = event.clientY - this._game.stage.y;
|
|
||||||
|
|
||||||
this._game.input.x = this._x * this._game.input.scaleX;
|
this._game.input.mousePointer.stop(event);
|
||||||
this._game.input.y = this._y * this._game.input.scaleY;
|
|
||||||
|
|
||||||
this._game.input.onUp.dispatch(this._game.input.x, this._game.input.y, this.timeDown);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the event listeners
|
||||||
|
* @method stop
|
||||||
|
*/
|
||||||
|
public stop() {
|
||||||
|
|
||||||
|
//this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
|
||||||
|
//this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
|
||||||
|
//this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,568 @@
|
|||||||
|
/// <reference path="../../Game.ts" />
|
||||||
|
/// <reference path="../../geom/Vector2.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Pointer
|
||||||
|
*
|
||||||
|
* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class Pointer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param {Phaser.Game} game.
|
||||||
|
* @return {Phaser.Pointer} This object.
|
||||||
|
*/
|
||||||
|
constructor(game: Game, id: number) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
this.active = false;
|
||||||
|
this.position = new Vector2;
|
||||||
|
this.positionDown = new Vector2;
|
||||||
|
this.circle = new Circle(0, 0, 44);
|
||||||
|
|
||||||
|
if (id == 0)
|
||||||
|
{
|
||||||
|
this.isMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
* @property _game
|
||||||
|
* @type {Phaser.Game}
|
||||||
|
* @private
|
||||||
|
**/
|
||||||
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private variable to store the status of dispatching a hold event
|
||||||
|
* @property _holdSent
|
||||||
|
* @type {Boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private _holdSent: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private variable storing the short-term history of pointer movements
|
||||||
|
* @property _history
|
||||||
|
* @type {Array}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private _history = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private variable storing the time at which the next history drop should occur
|
||||||
|
* @property _lastDrop
|
||||||
|
* @type {Number}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private _nextDrop: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Pointer ID (a number between 1 and 10, 0 is reserved for the mouse pointer specifically)
|
||||||
|
* @property id
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public id: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An identification number for each touch point.
|
||||||
|
* When a touch point becomes active, it is assigned an identifier that is distinct from any other active touch point.
|
||||||
|
* While the touch point remains active, all events that refer to it are assigned the same identifier.
|
||||||
|
* @property identifier
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public identifier: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this Pointer active or not? An active Pointer is one that is in contact with the touch screen.
|
||||||
|
* @property active
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
public active: bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Vector object containing the initial position when the Pointer was engaged with the screen.
|
||||||
|
* @property positionDown
|
||||||
|
* @type {Vector2}
|
||||||
|
**/
|
||||||
|
public positionDown: Vector2 = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Vector object containing the current position of the Pointer on the screen.
|
||||||
|
* @property position
|
||||||
|
* @type {Vector2}
|
||||||
|
**/
|
||||||
|
public position: Vector2 = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Circle object centered on the x/y screen coordinates of the Pointer.
|
||||||
|
* Default size of 44px (Apple's recommended "finger tip" size)
|
||||||
|
* @property circle
|
||||||
|
* @type {Circle}
|
||||||
|
**/
|
||||||
|
public circle: Circle = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @property withinGame
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
public withinGame: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this Pointer is a mouse the button property holds the value of which mouse button was pressed down
|
||||||
|
* @property button
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public button: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||||
|
* @property clientX
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public clientX: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||||
|
* @property clientY
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public clientY: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||||
|
* @property pageX
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public pageX: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||||
|
* @property pageY
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public pageY: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The horizontal coordinate of point relative to the screen in pixels
|
||||||
|
* @property screenX
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public screenX: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The vertical coordinate of point relative to the screen in pixels
|
||||||
|
* @property screenY
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public screenY: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The horizontal coordinate of point relative to the game element
|
||||||
|
* @property x
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public x: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The vertical coordinate of point relative to the game element
|
||||||
|
* @property y
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public y: number = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Element on which the touch point started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element.
|
||||||
|
* @property target
|
||||||
|
* @type {Any}
|
||||||
|
*/
|
||||||
|
public target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the Pointer is a mouse this is true, otherwise false
|
||||||
|
* @property isMouse
|
||||||
|
* @type {Boolean}
|
||||||
|
**/
|
||||||
|
public isMouse: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||||
|
* @property isDown
|
||||||
|
* @type {Boolean}
|
||||||
|
**/
|
||||||
|
public isDown: bool = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||||
|
* @property isUp
|
||||||
|
* @type {Boolean}
|
||||||
|
**/
|
||||||
|
public isUp: bool = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||||
|
* @property timeDown
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public timeDown: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timestamp representing when the Pointer left the touchscreen.
|
||||||
|
* @property timeUp
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public timeUp: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timestamp representing when the Pointer was last tapped or clicked
|
||||||
|
* @property previousTapTime
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public previousTapTime: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The total number of times this Pointer has been touched to the touchscreen
|
||||||
|
* @property totalTouches
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public totalTouches: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
|
||||||
|
* @property duration
|
||||||
|
* @type {Number}
|
||||||
|
**/
|
||||||
|
public get duration(): number {
|
||||||
|
|
||||||
|
if (this.isUp)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._game.time.now - this.timeDown;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the X value of this Pointer in world coordinate space
|
||||||
|
* @param {Camera} [camera]
|
||||||
|
*/
|
||||||
|
public getWorldX(camera?: Camera = this._game.camera) {
|
||||||
|
|
||||||
|
return camera.worldView.x + this.x;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Y value of this Pointer in world coordinate space
|
||||||
|
* @param {Camera} [camera]
|
||||||
|
*/
|
||||||
|
public getWorldY(camera?: Camera = this._game.camera) {
|
||||||
|
|
||||||
|
return camera.worldView.y + this.y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the Pointer is pressed onto the touchscreen
|
||||||
|
* @method start
|
||||||
|
* @param {Any} event
|
||||||
|
*/
|
||||||
|
public start(event): Pointer {
|
||||||
|
|
||||||
|
this.identifier = event.identifier;
|
||||||
|
this.target = event.target;
|
||||||
|
|
||||||
|
if (event.button)
|
||||||
|
{
|
||||||
|
this.button = event.button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix to stop rogue browser plugins from blocking the visibility state event
|
||||||
|
if (this._game.paused == true)
|
||||||
|
{
|
||||||
|
this._game.stage.resumeGame();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._history.length = 0;
|
||||||
|
|
||||||
|
this.move(event);
|
||||||
|
|
||||||
|
this.positionDown.setTo(this.x, this.y);
|
||||||
|
|
||||||
|
this.active = true;
|
||||||
|
this.withinGame = true;
|
||||||
|
this.isDown = true;
|
||||||
|
this.isUp = false;
|
||||||
|
this.timeDown = this._game.time.now;
|
||||||
|
this._holdSent = false;
|
||||||
|
|
||||||
|
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.onDown.dispatch(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.totalTouches++;
|
||||||
|
|
||||||
|
if (this.isMouse == false)
|
||||||
|
{
|
||||||
|
this._game.input.currentPointers++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
|
||||||
|
if (this.active)
|
||||||
|
{
|
||||||
|
if (this._holdSent == false && this.duration >= this._game.input.holdRate)
|
||||||
|
{
|
||||||
|
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.onHold.dispatch(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._holdSent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the droppings history
|
||||||
|
if (this._game.input.recordPointerHistory && this._game.time.now >= this._nextDrop)
|
||||||
|
{
|
||||||
|
this._nextDrop = this._game.time.now + this._game.input.recordRate;
|
||||||
|
this._history.push({ x: this.position.x, y: this.position.y });
|
||||||
|
|
||||||
|
if (this._history.length > this._game.input.recordLimit)
|
||||||
|
{
|
||||||
|
this._history.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the Pointer is moved on the touchscreen
|
||||||
|
* @method move
|
||||||
|
* @param {Any} event
|
||||||
|
*/
|
||||||
|
public move(event): Pointer {
|
||||||
|
|
||||||
|
if (event.button)
|
||||||
|
{
|
||||||
|
this.button = event.button;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clientX = event.clientX;
|
||||||
|
this.clientY = event.clientY;
|
||||||
|
this.pageX = event.pageX;
|
||||||
|
this.pageY = event.pageY;
|
||||||
|
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.position.setTo(this.x, this.y);
|
||||||
|
this.circle.x = this.x;
|
||||||
|
this.circle.y = 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.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the Pointer leaves the target area
|
||||||
|
* @method leave
|
||||||
|
* @param {Any} event
|
||||||
|
*/
|
||||||
|
public leave(event) {
|
||||||
|
|
||||||
|
this.withinGame = false;
|
||||||
|
this.move(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the Pointer leaves the touchscreen
|
||||||
|
* @method stop
|
||||||
|
* @param {Any} event
|
||||||
|
*/
|
||||||
|
public stop(event): Pointer {
|
||||||
|
|
||||||
|
this.timeUp = this._game.time.now;
|
||||||
|
|
||||||
|
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.onUp.dispatch(this);
|
||||||
|
|
||||||
|
// Was it a tap?
|
||||||
|
if (this.duration >= 0 && this.duration <= this._game.input.tapRate)
|
||||||
|
{
|
||||||
|
// Was it a double-tap?
|
||||||
|
if (this.timeUp - this.previousTapTime < this._game.input.doubleTapRate)
|
||||||
|
{
|
||||||
|
// Yes, let's dispatch the signal then with the 2nd parameter set to true
|
||||||
|
this._game.input.onTap.dispatch(this, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Wasn't a double-tap, so dispatch a single tap signal
|
||||||
|
this._game.input.onTap.dispatch(this, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.previousTapTime = this.timeUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.active = false;
|
||||||
|
this.withinGame = false;
|
||||||
|
this.isDown = false;
|
||||||
|
this.isUp = true;
|
||||||
|
|
||||||
|
if (this.isMouse == false)
|
||||||
|
{
|
||||||
|
this._game.input.currentPointers--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate
|
||||||
|
* @method justPressed
|
||||||
|
* @param {Number} [duration].
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
public justPressed(duration?: number = this._game.input.justPressedRate): bool {
|
||||||
|
|
||||||
|
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate
|
||||||
|
* @method justReleased
|
||||||
|
* @param {Number} [duration].
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
public justReleased(duration?: number = this._game.input.justReleasedRate): bool {
|
||||||
|
|
||||||
|
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the Pointer properties. Called by Input.reset when you perform a State change.
|
||||||
|
* @method reset
|
||||||
|
*/
|
||||||
|
public reset() {
|
||||||
|
|
||||||
|
this.active = false;
|
||||||
|
this.identifier = null;
|
||||||
|
this.isDown = false;
|
||||||
|
this.isUp = true;
|
||||||
|
this.totalTouches = 0;
|
||||||
|
this._holdSent = false;
|
||||||
|
this._history.length = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Pointer.circle object onto the stage in green if down or red if up.
|
||||||
|
* @method renderDebug
|
||||||
|
*/
|
||||||
|
public renderDebug(hideIfUp: bool = false) {
|
||||||
|
|
||||||
|
if (hideIfUp == true && this.isUp == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._game.stage.context.beginPath();
|
||||||
|
this._game.stage.context.arc(this.x, this.y, this.circle.radius, 0, Math.PI * 2);
|
||||||
|
|
||||||
|
if (this.active)
|
||||||
|
{
|
||||||
|
this._game.stage.context.fillStyle = 'rgba(0,255,0,0.5)';
|
||||||
|
this._game.stage.context.strokeStyle = 'rgb(0,255,0)';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||||
|
this._game.stage.context.strokeStyle = 'rgb(100,0,0)';
|
||||||
|
}
|
||||||
|
|
||||||
|
this._game.stage.context.fill();
|
||||||
|
this._game.stage.context.closePath();
|
||||||
|
|
||||||
|
// Render the points
|
||||||
|
this._game.stage.context.beginPath();
|
||||||
|
this._game.stage.context.moveTo(this.positionDown.x, this.positionDown.y);
|
||||||
|
this._game.stage.context.lineTo(this.position.x, this.position.y);
|
||||||
|
this._game.stage.context.lineWidth = 2;
|
||||||
|
this._game.stage.context.stroke();
|
||||||
|
this._game.stage.context.closePath();
|
||||||
|
|
||||||
|
// Render the text
|
||||||
|
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||||
|
this._game.stage.context.font = 'Arial 16px';
|
||||||
|
this._game.stage.context.fillText('ID: ' + this.id + " Active: " + this.active, this.x, this.y - 100);
|
||||||
|
this._game.stage.context.fillText('Screen X: ' + this.x + " Screen Y: " + this.y, this.x, this.y - 80);
|
||||||
|
this._game.stage.context.fillText('Duration: ' + this.duration + " ms", this.x, this.y - 60);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of this object.
|
||||||
|
* @method toString
|
||||||
|
* @return {String} a string representation of the instance.
|
||||||
|
**/
|
||||||
|
public toString(): string {
|
||||||
|
|
||||||
|
return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+71
-305
@@ -1,27 +1,21 @@
|
|||||||
/// <reference path="../../Game.ts" />
|
/// <reference path="../../Game.ts" />
|
||||||
/// <reference path="Finger.ts" />
|
/// <reference path="Pointer.ts" />
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phaser - Touch
|
* Phaser - Touch
|
||||||
*
|
*
|
||||||
* The Touch class handles touch interactions with the game and the resulting Finger objects.
|
* The Touch class handles touch interactions with the game and the resulting Pointer objects.
|
||||||
* http://www.w3.org/TR/touch-events/
|
* http://www.w3.org/TR/touch-events/
|
||||||
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||||
* http://www.html5rocks.com/en/mobile/touchandmouse/
|
* http://www.html5rocks.com/en/mobile/touchandmouse/
|
||||||
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||||
*
|
|
||||||
* @todo Try and resolve update lag in Chrome/Android
|
|
||||||
* Gestures (pinch, zoom, swipe)
|
|
||||||
* GameObject Touch
|
|
||||||
* Touch point within GameObject
|
|
||||||
* Input Zones (mouse and touch) - lock entities within them + axis aligned drags
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module Phaser {
|
module Phaser {
|
||||||
|
|
||||||
export class Touch {
|
export class Touch {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param {Game} game.
|
* @param {Game} game.
|
||||||
* @return {Touch} This object.
|
* @return {Touch} This object.
|
||||||
@@ -30,168 +24,43 @@ module Phaser {
|
|||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
|
|
||||||
this.finger1 = new Finger(this._game);
|
|
||||||
this.finger2 = new Finger(this._game);
|
|
||||||
this.finger3 = new Finger(this._game);
|
|
||||||
this.finger4 = new Finger(this._game);
|
|
||||||
this.finger5 = new Finger(this._game);
|
|
||||||
this.finger6 = new Finger(this._game);
|
|
||||||
this.finger7 = new Finger(this._game);
|
|
||||||
this.finger8 = new Finger(this._game);
|
|
||||||
this.finger9 = new Finger(this._game);
|
|
||||||
this.finger10 = new Finger(this._game);
|
|
||||||
|
|
||||||
this._fingers = [this.finger1, this.finger2, this.finger3, this.finger4, this.finger5, this.finger6, this.finger7, this.finger8, this.finger9, this.finger10];
|
|
||||||
|
|
||||||
this.touchDown = new Signal();
|
|
||||||
this.touchUp = new Signal();
|
|
||||||
|
|
||||||
this.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Local private reference to game.
|
||||||
* @property _game
|
* @property _game
|
||||||
* @type Game
|
* @type {Phaser.Game}
|
||||||
* @private
|
* @private
|
||||||
**/
|
**/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||||
* @property x
|
* @type {Boolean}
|
||||||
* @type Number
|
*/
|
||||||
**/
|
public disabled: bool = false;
|
||||||
public x: number = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Starts the event listeners running
|
||||||
* @property y
|
* @method start
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public y: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property _fingers
|
|
||||||
* @type Array
|
|
||||||
* @private
|
|
||||||
**/
|
|
||||||
private _fingers: Finger[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger1
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger1: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger2
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger2: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger3
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger3: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger4
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger4: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger5
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger5: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger6
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger6: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger7
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger7: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger8
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger8: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger9
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger9: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property finger10
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public finger10: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property latestFinger
|
|
||||||
* @type Finger
|
|
||||||
**/
|
|
||||||
public latestFinger: Finger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property isDown
|
|
||||||
* @type Boolean
|
|
||||||
**/
|
|
||||||
public isDown: bool = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property isUp
|
|
||||||
* @type Boolean
|
|
||||||
**/
|
|
||||||
public isUp: bool = true;
|
|
||||||
|
|
||||||
public touchDown: Signal;
|
|
||||||
public touchUp: Signal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method start
|
|
||||||
*/
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
|
|
||||||
this._game.stage.canvas.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
if (this._game.device.touch)
|
||||||
this._game.stage.canvas.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
{
|
||||||
this._game.stage.canvas.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
this._game.stage.canvas.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
||||||
this._game.stage.canvas.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
this._game.stage.canvas.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
||||||
this._game.stage.canvas.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
this._game.stage.canvas.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
||||||
this._game.stage.canvas.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
this._game.stage.canvas.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
||||||
|
this._game.stage.canvas.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
||||||
|
this._game.stage.canvas.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
||||||
|
|
||||||
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
|
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevent iOS bounce-back (doesn't work?)
|
* Prevent iOS bounce-back (doesn't work?)
|
||||||
* @method consumeTouchMove
|
* @method consumeTouchMove
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
@@ -202,98 +71,78 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method onTouchStart
|
* @method onTouchStart
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
**/
|
**/
|
||||||
private onTouchStart(event) {
|
private onTouchStart(event) {
|
||||||
|
|
||||||
event.preventDefault();
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// A list of all the touch points that BECAME active with the current event
|
event.preventDefault();
|
||||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
|
||||||
|
|
||||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
||||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
||||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||||
for (var i = 0; i < event.changedTouches.length; i++)
|
for (var i = 0; i < event.changedTouches.length; i++)
|
||||||
{
|
{
|
||||||
for (var f = 0; f < this._fingers.length; f++)
|
this._game.input.startPointer(event.changedTouches[i]);
|
||||||
{
|
|
||||||
if (this._fingers[f].active === false)
|
|
||||||
{
|
|
||||||
this._fingers[f].start(event.changedTouches[i]);
|
|
||||||
this.x = this._fingers[f].x;
|
|
||||||
this.y = this._fingers[f].y;
|
|
||||||
this._game.input.x = this.x * this._game.input.scaleX;
|
|
||||||
this._game.input.y = this.y * this._game.input.scaleY;
|
|
||||||
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
|
||||||
this._game.input.onDown.dispatch(this._game.input.x, this._game.input.y, this._fingers[f].timeDown);
|
|
||||||
this.isDown = true;
|
|
||||||
this.isUp = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Doesn't appear to be supported by most browsers yet
|
* Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||||
|
* Occurs for example on iOS when you put down 4 fingers and the app selector UI appears
|
||||||
* @method onTouchCancel
|
* @method onTouchCancel
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
**/
|
**/
|
||||||
private onTouchCancel(event) {
|
private onTouchCancel(event) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||||
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
|
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
|
||||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
|
||||||
for (var i = 0; i < event.changedTouches.length; i++)
|
for (var i = 0; i < event.changedTouches.length; i++)
|
||||||
{
|
{
|
||||||
for (var f = 0; f < this._fingers.length; f++)
|
this._game.input.stopPointer(event.changedTouches[i]);
|
||||||
{
|
|
||||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
|
||||||
{
|
|
||||||
this._fingers[f].stop(event.changedTouches[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* For touch enter and leave its a list of the touch points that have entered or left the target
|
||||||
* Doesn't appear to be supported by most browsers yet
|
* Doesn't appear to be supported by most browsers yet
|
||||||
* @method onTouchEnter
|
* @method onTouchEnter
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
**/
|
**/
|
||||||
private onTouchEnter(event) {
|
private onTouchEnter(event) {
|
||||||
|
|
||||||
|
if (this._game.input.disabled || this.disabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
|
||||||
|
|
||||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
|
||||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
|
||||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
|
||||||
for (var i = 0; i < event.changedTouches.length; i++)
|
for (var i = 0; i < event.changedTouches.length; i++)
|
||||||
{
|
{
|
||||||
for (var f = 0; f < this._fingers.length; f++)
|
console.log('touch enter');
|
||||||
{
|
|
||||||
if (this._fingers[f].active === false)
|
|
||||||
{
|
|
||||||
this._fingers[f].start(event.changedTouches[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* For touch enter and leave its a list of the touch points that have entered or left the target
|
||||||
* Doesn't appear to be supported by most browsers yet
|
* Doesn't appear to be supported by most browsers yet
|
||||||
* @method onTouchLeave
|
* @method onTouchLeave
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
@@ -302,25 +151,15 @@ module Phaser {
|
|||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
|
||||||
|
|
||||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
|
||||||
for (var i = 0; i < event.changedTouches.length; i++)
|
for (var i = 0; i < event.changedTouches.length; i++)
|
||||||
{
|
{
|
||||||
for (var f = 0; f < this._fingers.length; f++)
|
console.log('touch leave');
|
||||||
{
|
|
||||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
|
||||||
{
|
|
||||||
this._fingers[f].leave(event.changedTouches[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method onTouchMove
|
* @method onTouchMove
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
**/
|
**/
|
||||||
@@ -328,29 +167,15 @@ module Phaser {
|
|||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
|
||||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
|
||||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
|
||||||
for (var i = 0; i < event.changedTouches.length; i++)
|
for (var i = 0; i < event.changedTouches.length; i++)
|
||||||
{
|
{
|
||||||
for (var f = 0; f < this._fingers.length; f++)
|
this._game.input.updatePointer(event.changedTouches[i]);
|
||||||
{
|
|
||||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
|
||||||
{
|
|
||||||
this._fingers[f].move(event.changedTouches[i]);
|
|
||||||
this.x = this._fingers[f].x;
|
|
||||||
this.y = this._fingers[f].y;
|
|
||||||
this._game.input.x = this.x * this._game.input.scaleX;
|
|
||||||
this._game.input.y = this.y * this._game.input.scaleY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @method onTouchEnd
|
* @method onTouchEnd
|
||||||
* @param {Any} event
|
* @param {Any} event
|
||||||
**/
|
**/
|
||||||
@@ -364,85 +189,26 @@ module Phaser {
|
|||||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||||
for (var i = 0; i < event.changedTouches.length; i++)
|
for (var i = 0; i < event.changedTouches.length; i++)
|
||||||
{
|
{
|
||||||
for (var f = 0; f < this._fingers.length; f++)
|
this._game.input.stopPointer(event.changedTouches[i]);
|
||||||
{
|
|
||||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
|
||||||
{
|
|
||||||
this._fingers[f].stop(event.changedTouches[i]);
|
|
||||||
this.x = this._fingers[f].x;
|
|
||||||
this.y = this._fingers[f].y;
|
|
||||||
this._game.input.x = this.x * this._game.input.scaleX;
|
|
||||||
this._game.input.y = this.y * this._game.input.scaleY;
|
|
||||||
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
|
||||||
this._game.input.onUp.dispatch(this._game.input.x, this._game.input.y, this._fingers[f].timeUp);
|
|
||||||
this.isDown = false;
|
|
||||||
this.isUp = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Stop the event listeners
|
||||||
* @method calculateDistance
|
* @method stop
|
||||||
* @param {Finger} finger1
|
|
||||||
* @param {Finger} finger2
|
|
||||||
**/
|
|
||||||
public calculateDistance(finger1: Finger, finger2: Finger) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method calculateAngle
|
|
||||||
* @param {Finger} finger1
|
|
||||||
* @param {Finger} finger2
|
|
||||||
**/
|
|
||||||
public calculateAngle(finger1: Finger, finger2: Finger) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method checkOverlap
|
|
||||||
* @param {Finger} finger1
|
|
||||||
* @param {Finger} finger2
|
|
||||||
**/
|
|
||||||
public checkOverlap(finger1: Finger, finger2: Finger) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method update
|
|
||||||
*/
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method stop
|
|
||||||
*/
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
|
|
||||||
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
if (this._game.device.touch)
|
||||||
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
{
|
||||||
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
||||||
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
||||||
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
||||||
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
||||||
|
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
||||||
}
|
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
||||||
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method reset
|
|
||||||
**/
|
|
||||||
public reset() {
|
|
||||||
|
|
||||||
this.isDown = false;
|
|
||||||
this.isUp = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ module Phaser {
|
|||||||
|
|
||||||
export class BootScreen {
|
export class BootScreen {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BootScreen constructor
|
||||||
|
* Create a new <code>BootScreen</code> with specific width and height.
|
||||||
|
*
|
||||||
|
* @param width {number} Screen canvas width.
|
||||||
|
* @param height {number} Screen canvas height.
|
||||||
|
*/
|
||||||
constructor(game:Game) {
|
constructor(game:Game) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -19,13 +26,35 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
/**
|
||||||
|
* Engine logo.
|
||||||
|
*/
|
||||||
private _logo;
|
private _logo;
|
||||||
|
/**
|
||||||
|
* Engine logo image data.
|
||||||
|
*/
|
||||||
private _logoData: string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
|
private _logoData: string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
|
||||||
|
/**
|
||||||
|
* Background gradient effect color 1.
|
||||||
|
*/
|
||||||
private _color1 = { r: 20, g: 20, b: 20 };
|
private _color1 = { r: 20, g: 20, b: 20 };
|
||||||
|
/**
|
||||||
|
* Background gradient effect color 2.
|
||||||
|
*/
|
||||||
private _color2 = { r: 200, g: 200, b: 200 };
|
private _color2 = { r: 200, g: 200, b: 200 };
|
||||||
|
/**
|
||||||
|
* Fade effect tween.
|
||||||
|
* @type {Phaser.Tween}
|
||||||
|
*/
|
||||||
private _fade: Phaser.Tween = null;
|
private _fade: Phaser.Tween = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update color and fade.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
if (this._fade == null)
|
if (this._fade == null)
|
||||||
@@ -42,6 +71,9 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render BootScreen.
|
||||||
|
*/
|
||||||
public render() {
|
public render() {
|
||||||
|
|
||||||
var grd = this._game.stage.context.createLinearGradient(0, 0, 0, this._game.stage.height);
|
var grd = this._game.stage.context.createLinearGradient(0, 0, 0, this._game.stage.height);
|
||||||
@@ -75,9 +107,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start color fading cycle.
|
||||||
|
*/
|
||||||
private colorCycle() {
|
private colorCycle() {
|
||||||
|
|
||||||
this._fade = this._game.createTween(this._color2);
|
this._fade = this._game.add.tween(this._color2);
|
||||||
|
|
||||||
this._fade.to({ r: Math.random() * 250, g: Math.random() * 250, b: Math.random() * 250 }, 3000, Phaser.Easing.Linear.None);
|
this._fade.to({ r: Math.random() * 250, g: Math.random() * 250, b: Math.random() * 250 }, 3000, Phaser.Easing.Linear.None);
|
||||||
this._fade.onComplete.add(this.colorCycle, this);
|
this._fade.onComplete.add(this.colorCycle, this);
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ module Phaser {
|
|||||||
|
|
||||||
export class PauseScreen {
|
export class PauseScreen {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PauseScreen constructor
|
||||||
|
* Create a new <code>PauseScreen</code> with specific width and height.
|
||||||
|
*
|
||||||
|
* @param width {number} Screen canvas width.
|
||||||
|
* @param height {number} Screen canvas height.
|
||||||
|
*/
|
||||||
constructor(game: Game, width: number, height: number) {
|
constructor(game: Game, width: number, height: number) {
|
||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
@@ -20,14 +27,37 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local private reference to game.
|
||||||
|
*/
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canvas element used by engine.
|
||||||
|
* @type {HTMLCanvasElement}
|
||||||
|
*/
|
||||||
private _canvas: HTMLCanvasElement;
|
private _canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render context of stage's canvas.
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
private _context: CanvasRenderingContext2D;
|
private _context: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background color.
|
||||||
|
*/
|
||||||
private _color;
|
private _color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fade effect tween.
|
||||||
|
* @type {Phaser.Tween}
|
||||||
|
*/
|
||||||
private _fade: Phaser.Tween;
|
private _fade: Phaser.Tween;
|
||||||
|
|
||||||
// Called when the game enters pause mode
|
/**
|
||||||
|
* Called when the game enters pause mode.
|
||||||
|
*/
|
||||||
public onPaused() {
|
public onPaused() {
|
||||||
|
|
||||||
// Take a grab of the current canvas to our temporary one
|
// Take a grab of the current canvas to our temporary one
|
||||||
@@ -38,17 +68,26 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the game resume from pause mode.
|
||||||
|
*/
|
||||||
public onResume() {
|
public onResume() {
|
||||||
this._fade.stop();
|
this._fade.stop();
|
||||||
this._game.tweens.remove(this._fade);
|
this._game.tweens.remove(this._fade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update background color.
|
||||||
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
this._color.r = Math.round(this._color.r);
|
this._color.r = Math.round(this._color.r);
|
||||||
this._color.g = Math.round(this._color.g);
|
this._color.g = Math.round(this._color.g);
|
||||||
this._color.b = Math.round(this._color.b);
|
this._color.b = Math.round(this._color.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render PauseScreen.
|
||||||
|
*/
|
||||||
public render() {
|
public render() {
|
||||||
|
|
||||||
this._game.stage.context.drawImage(this._canvas, 0, 0);
|
this._game.stage.context.drawImage(this._canvas, 0, 0);
|
||||||
@@ -73,9 +112,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start fadeOut effect.
|
||||||
|
*/
|
||||||
private fadeOut() {
|
private fadeOut() {
|
||||||
|
|
||||||
this._fade = this._game.createTween(this._color);
|
this._fade = this._game.add.tween(this._color);
|
||||||
|
|
||||||
this._fade.to({ r: 50, g: 50, b: 50 }, 1000, Phaser.Easing.Linear.None);
|
this._fade.to({ r: 50, g: 50, b: 50 }, 1000, Phaser.Easing.Linear.None);
|
||||||
this._fade.onComplete.add(this.fadeIn, this);
|
this._fade.onComplete.add(this.fadeIn, this);
|
||||||
@@ -83,9 +125,12 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start fadeIn effect.
|
||||||
|
*/
|
||||||
private fadeIn() {
|
private fadeIn() {
|
||||||
|
|
||||||
this._fade = this._game.createTween(this._color);
|
this._fade = this._game.add.tween(this._color);
|
||||||
|
|
||||||
this._fade.to({ r: 255, g: 255, b: 255 }, 1000, Phaser.Easing.Linear.None);
|
this._fade.to({ r: 255, g: 255, b: 255 }, 1000, Phaser.Easing.Linear.None);
|
||||||
this._fade.onComplete.add(this.fadeOut, this);
|
this._fade.onComplete.add(this.fadeOut, this);
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="Particle.ts" />
|
||||||
|
/// <reference path="../geom/Vector2.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - AngleConstraint
|
||||||
|
*
|
||||||
|
* constrains 3 particles to an angle
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser.Verlet {
|
||||||
|
|
||||||
|
export class AngleConstraint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new AngleConstraint object.
|
||||||
|
* @class AngleConstraint
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x coordinate of vector2
|
||||||
|
* @param {Number} y The y coordinate of vector2
|
||||||
|
* @return {AngleConstraint} This object
|
||||||
|
**/
|
||||||
|
constructor(a: Phaser.Verlet.Particle, b: Phaser.Verlet.Particle, c: Phaser.Verlet.Particle, stiffness: number) {
|
||||||
|
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
this.c = c;
|
||||||
|
this.angle = this.b.pos.angle2(this.a.pos, this.c.pos);
|
||||||
|
this.stiffness = stiffness;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public a: Phaser.Verlet.Particle;
|
||||||
|
public b: Phaser.Verlet.Particle;
|
||||||
|
public c: Phaser.Verlet.Particle;
|
||||||
|
public angle: number;
|
||||||
|
public stiffness: number;
|
||||||
|
|
||||||
|
public relax(stepCoef: number) {
|
||||||
|
|
||||||
|
var angle = this.b.pos.angle2(this.a.pos, this.c.pos);
|
||||||
|
var diff = angle - this.angle;
|
||||||
|
|
||||||
|
if (diff <= -Math.PI)
|
||||||
|
diff += 2 * Math.PI;
|
||||||
|
else if (diff >= Math.PI)
|
||||||
|
diff -= 2 * Math.PI;
|
||||||
|
|
||||||
|
diff *= stepCoef * this.stiffness;
|
||||||
|
|
||||||
|
this.a.pos = this.a.pos.rotate(this.b.pos, diff);
|
||||||
|
this.c.pos = this.c.pos.rotate(this.b.pos, -diff);
|
||||||
|
this.b.pos = this.b.pos.rotate(this.a.pos, diff);
|
||||||
|
this.b.pos = this.b.pos.rotate(this.c.pos, -diff);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(ctx) {
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(this.a.pos.x, this.a.pos.y);
|
||||||
|
ctx.lineTo(this.b.pos.x, this.b.pos.y);
|
||||||
|
ctx.lineTo(this.c.pos.x, this.c.pos.y);
|
||||||
|
var tmp = ctx.lineWidth;
|
||||||
|
ctx.lineWidth = 5;
|
||||||
|
ctx.strokeStyle = "rgba(255,255,0,0.2)";
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.lineWidth = tmp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="../geom/Vector2.ts" />
|
||||||
|
/// <reference path="Particle.ts" />
|
||||||
|
/// <reference path="PinConstraint.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Verlet - Composite
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser.Verlet {
|
||||||
|
|
||||||
|
export class Composite {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Composite object.
|
||||||
|
* @class Composite
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x coordinate of vector2
|
||||||
|
* @param {Number} y The y coordinate of vector2
|
||||||
|
* @return {Composite} This object
|
||||||
|
**/
|
||||||
|
constructor(game: Game) {
|
||||||
|
|
||||||
|
this._game = game;
|
||||||
|
|
||||||
|
this.sprites = [];
|
||||||
|
this.particles = [];
|
||||||
|
this.constraints = [];
|
||||||
|
|
||||||
|
this.frameBounds = new Phaser.Quad();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private _game: Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture of the particles to be rendered.
|
||||||
|
*/
|
||||||
|
private _texture = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rendering bounds for the texture
|
||||||
|
* @type {Quad}
|
||||||
|
*/
|
||||||
|
private frameBounds: Quad;
|
||||||
|
|
||||||
|
// local rendering related temp vars to help avoid gc spikes
|
||||||
|
private _sx: number = 0;
|
||||||
|
private _sy: number = 0;
|
||||||
|
private _sw: number = 0;
|
||||||
|
private _sh: number = 0;
|
||||||
|
private _dx: number = 0;
|
||||||
|
private _dy: number = 0;
|
||||||
|
private _dw: number = 0;
|
||||||
|
private _dh: number = 0;
|
||||||
|
private _hw: number = 0;
|
||||||
|
private _hh: number = 0;
|
||||||
|
|
||||||
|
public sprites: Phaser.Sprite[];
|
||||||
|
public particles: Phaser.Verlet.Particle[];
|
||||||
|
public constraints;
|
||||||
|
|
||||||
|
public drawParticles = null;
|
||||||
|
public drawConstraints = null;
|
||||||
|
|
||||||
|
// Create Constraints
|
||||||
|
|
||||||
|
public createDistanceConstraint(a: Phaser.Verlet.Particle, b: Phaser.Verlet.Particle, stiffness: number, distance?: number = null): Phaser.Verlet.DistanceConstraint {
|
||||||
|
|
||||||
|
this.constraints.push(new Phaser.Verlet.DistanceConstraint(a, b, stiffness, distance));
|
||||||
|
return this.constraints[this.constraints.length - 1];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public createAngleConstraint(a: Phaser.Verlet.Particle, b: Phaser.Verlet.Particle, c: Phaser.Verlet.Particle, stiffness: number): Phaser.Verlet.AngleConstraint {
|
||||||
|
|
||||||
|
this.constraints.push(new Phaser.Verlet.AngleConstraint(a, b, c, stiffness));
|
||||||
|
return this.constraints[this.constraints.length - 1];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public createPinConstraint(a: Phaser.Verlet.Particle, pos: Vector2): Phaser.Verlet.PinConstraint {
|
||||||
|
|
||||||
|
this.constraints.push(new Phaser.Verlet.PinConstraint(a, pos));
|
||||||
|
return this.constraints[this.constraints.length - 1];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a graphic for this Composite. The graphic cannot be a SpriteSheet yet.
|
||||||
|
* @param key {string} Key of the graphic you want to load for this sprite.
|
||||||
|
* @return {Composite} This object
|
||||||
|
*/
|
||||||
|
public loadGraphic(key: string): Composite {
|
||||||
|
|
||||||
|
if (this._game.cache.getImage(key) !== null)
|
||||||
|
{
|
||||||
|
if (this._game.cache.isSpriteSheet(key) == false)
|
||||||
|
{
|
||||||
|
this._texture = this._game.cache.getImage(key);
|
||||||
|
this.frameBounds.width = this._texture.width;
|
||||||
|
this.frameBounds.height = this._texture.height;
|
||||||
|
this._hw = Math.floor(this.frameBounds.width / 2);
|
||||||
|
this._hh = Math.floor(this.frameBounds.width / 2);
|
||||||
|
this.drawParticles = this.render;
|
||||||
|
this.drawConstraints = this.renderConstraints;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public hideConstraints: bool = true;
|
||||||
|
public constraintLineColor: string = 'rgba(200,200,200,1)';
|
||||||
|
|
||||||
|
private renderConstraints(context) {
|
||||||
|
|
||||||
|
if (this.hideConstraints == true || this.constraints.length == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var i;
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
|
||||||
|
for (i in this.constraints)
|
||||||
|
{
|
||||||
|
if (this.constraints[i].b)
|
||||||
|
{
|
||||||
|
context.moveTo(this.constraints[i].a.pos.x, this.constraints[i].a.pos.y);
|
||||||
|
context.lineTo(this.constraints[i].b.pos.x, this.constraints[i].b.pos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.strokeStyle = this.constraintLineColor;
|
||||||
|
context.stroke();
|
||||||
|
context.closePath();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private render(context) {
|
||||||
|
|
||||||
|
this._sx = 0;
|
||||||
|
this._sy = 0;
|
||||||
|
this._sw = this.frameBounds.width;
|
||||||
|
this._sh = this.frameBounds.height;
|
||||||
|
this._dw = this.frameBounds.width;
|
||||||
|
this._dh = this.frameBounds.height;
|
||||||
|
|
||||||
|
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._dw = Math.round(this._dw);
|
||||||
|
this._dh = Math.round(this._dh);
|
||||||
|
|
||||||
|
var i;
|
||||||
|
|
||||||
|
for (i in this.particles)
|
||||||
|
{
|
||||||
|
//this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x);
|
||||||
|
//this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y);
|
||||||
|
this._dx = this.particles[i].pos.x - this._hw;
|
||||||
|
this._dy = this.particles[i].pos.y - this._hh;
|
||||||
|
this._dx = Math.round(this._dx);
|
||||||
|
this._dy = Math.round(this._dy);
|
||||||
|
|
||||||
|
context.drawImage(
|
||||||
|
this._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)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public pin(index, pos?=null) {
|
||||||
|
|
||||||
|
if (pos == null)
|
||||||
|
{
|
||||||
|
pos = this.particles[index].pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pc = new Phaser.Verlet.PinConstraint(this.particles[index], pos);
|
||||||
|
this.constraints.push(pc);
|
||||||
|
return pc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="Particle.ts" />
|
||||||
|
/// <reference path="../geom/Vector2.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - DistanceConstraint
|
||||||
|
*
|
||||||
|
* Constrains to initial distance
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser.Verlet {
|
||||||
|
|
||||||
|
export class DistanceConstraint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new DistanceConstraint object.
|
||||||
|
* @class DistanceConstraint
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x coordinate of vector2
|
||||||
|
* @param {Number} y The y coordinate of vector2
|
||||||
|
* @return {DistanceConstraint} This object
|
||||||
|
**/
|
||||||
|
constructor(a: Phaser.Verlet.Particle, b: Phaser.Verlet.Particle, stiffness: number, distance?:number = null) {
|
||||||
|
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
|
||||||
|
if (distance === null)
|
||||||
|
{
|
||||||
|
this.distance = a.pos.sub(b.pos).length();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.distance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.stiffness = stiffness;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public a: Phaser.Verlet.Particle;
|
||||||
|
public b: Phaser.Verlet.Particle;
|
||||||
|
public distance: number;
|
||||||
|
public stiffness: number;
|
||||||
|
|
||||||
|
public relax(stepCoef: number) {
|
||||||
|
|
||||||
|
var normal = this.a.pos.sub(this.b.pos);
|
||||||
|
|
||||||
|
var m = normal.length2();
|
||||||
|
|
||||||
|
normal.mutableScale(((this.distance * this.distance - m) / m) * this.stiffness * stepCoef);
|
||||||
|
|
||||||
|
this.a.pos.mutableAdd(normal);
|
||||||
|
this.b.pos.mutableSub(normal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(ctx) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(this.a.pos.x, this.a.pos.y);
|
||||||
|
ctx.lineTo(this.b.pos.x, this.b.pos.y);
|
||||||
|
ctx.strokeStyle = "#d8dde2";
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.closePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="../geom/Vector2.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - Verlet - Particle
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser.Verlet {
|
||||||
|
|
||||||
|
export class Particle {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Particle object.
|
||||||
|
* @class Particle
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x coordinate of vector2
|
||||||
|
* @param {Number} y The y coordinate of vector2
|
||||||
|
* @return {Particle} This object
|
||||||
|
**/
|
||||||
|
constructor(pos: Vector2) {
|
||||||
|
|
||||||
|
this.pos = (new Vector2()).mutableSet(pos);
|
||||||
|
this.lastPos = (new Vector2()).mutableSet(pos);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public pos: Vector2;
|
||||||
|
public lastPos: Vector2;
|
||||||
|
|
||||||
|
public render(ctx) {
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(this.pos.x, this.pos.y, 2, 0, 2*Math.PI);
|
||||||
|
ctx.fillStyle = "#2dad8f";
|
||||||
|
ctx.fill();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/// <reference path="../Game.ts" />
|
||||||
|
/// <reference path="Particle.ts" />
|
||||||
|
/// <reference path="../geom/Vector2.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phaser - PinConstraint
|
||||||
|
*
|
||||||
|
* Constrains to static / fixed point
|
||||||
|
*/
|
||||||
|
|
||||||
|
module Phaser.Verlet {
|
||||||
|
|
||||||
|
export class PinConstraint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PinConstraint object.
|
||||||
|
* @class PinConstraint
|
||||||
|
* @constructor
|
||||||
|
* @param {Number} x The x coordinate of vector2
|
||||||
|
* @param {Number} y The y coordinate of vector2
|
||||||
|
* @return {PinConstraint} This object
|
||||||
|
**/
|
||||||
|
constructor(a: Phaser.Verlet.Particle, pos: Vector2) {
|
||||||
|
|
||||||
|
this.a = a;
|
||||||
|
this.pos = (new Vector2()).mutableSet(pos);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public a: Phaser.Verlet.Particle;
|
||||||
|
public pos: Vector2;
|
||||||
|
|
||||||
|
public relax() {
|
||||||
|
this.a.pos.mutableSet(this.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(ctx) {
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(this.pos.x, this.pos.y, 6, 0, 2*Math.PI);
|
||||||
|
ctx.fillStyle = "rgba(0,153,255,0.1)";
|
||||||
|
ctx.fill();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,12 +15,109 @@ Try out the [Phaser Test Suite](http://gametest.mobi/phaser/)
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
"Being negative is not how we make progress" - Larry Page, Google
|
||||||
|
|
||||||
Latest Update
|
Latest Update
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
V0.9.6
|
V0.9.6
|
||||||
|
|
||||||
*
|
* Virtually every class now has documentation - if you spot a typo or something missing please shout (thanks pixelpicosean).
|
||||||
|
* Grunt file updated to produce the new Special FX JS file (thanks HackManiac).
|
||||||
|
* Fixed issue stopping Phaser working on iOS 5 (iPad 1).
|
||||||
|
* Created new mobile test folder, updated index.php to use mobile CSS and made some mobile specific tests.
|
||||||
|
* Fixed a few speed issues on Android 2.x stock browser.
|
||||||
|
* Moved Camera context save/restore back inside parameter checks (sped-up Samsung S3 stock browser).
|
||||||
|
* Fixed bug with StageScaleMode.checkOrientation not respecting the NO_SCALE value.
|
||||||
|
* Added MSPointer support (thanks Diego Bezerra).
|
||||||
|
* Added Camera.clear to perform a clearRect instead of a fillRect if needed (default is false).
|
||||||
|
* Swapped Camera.opaque default from true to false re: performance.
|
||||||
|
* Updated Stage.visibilityChange to avoid pause screen locking in certain situations.
|
||||||
|
* Added StageScaleMode.enterLandscape and enterPortrait signals for easier device orientation change checks.
|
||||||
|
* Added StageScaleMode.isPortrait.
|
||||||
|
* Updated StageScaleMode to check both window.orientationchange and window.resize events.
|
||||||
|
* Updated RequestAnimationFrame to use performance.now for sub-millisecond precision and to drive the Game.time.update loop.
|
||||||
|
* Updated RequestAnimationFrame setTimeout to use fixed timestep and re-ordered callback sequence. Android 2/iOS5 performance much better now.
|
||||||
|
* Removed Stage.ORIENTATION_LANDSCAPE statics because the values should be taken from Stage.scale.isPortrait / isLandscape.
|
||||||
|
* Removed Stage.maxScaleX/Y and moved them into StageScaleMode.minWidth, minHeight, maxWidth and maxHeight.
|
||||||
|
* Fixed Stage.scale so that it resizes without needing an orientation change first.
|
||||||
|
* Added StageScaleMode.startFullscreen(), stopFullScreen() and isFullScreen for making use of the FullScreen API on desktop browsers.
|
||||||
|
* Swapped Stage.offset from Point to MicroPoint.
|
||||||
|
* Swapped Stage.bounds from Rectangle to Quad.
|
||||||
|
* Added State.destroy support. A states destroy function is called when you switch to a new state (thanks JesseFreeman).
|
||||||
|
* Added Sprite.fillColor, used in the Sprite render if no image is loaded (set via the property or Sprite.makeGraphic) (thanks JesseFreeman).
|
||||||
|
* Renamed Phaser.Finger to Phaser.Pointer.
|
||||||
|
* Updated all of the Input classes so they now use Input.pointers 1 through 10.
|
||||||
|
* Updated Touch and MSPointer to allow multi-touch support (when the hardware supports it) and created new tests to show this.
|
||||||
|
* Added Input.getPointer, Input.getPointerFromIdentifier, Input.totalActivePointers and Input.totalInactivePointers.
|
||||||
|
* Added Input.startPointer, Input.updatePointer and Input.stopPointer.
|
||||||
|
* Phaser Input now confirmed working on Windows Phone 8 (Nokia Lumia 920).
|
||||||
|
* Added Input.maxPointers to allow you to limit the number of fingers your game will listen for on multi-touch systems.
|
||||||
|
* Added Input.addPointer. By default Input will create 5 pointers (+1 for the mouse). Use addPointer() to add up to a maximum of 10.
|
||||||
|
* Added Input.position - a Vector2 object containing the most recent position of the most recently active Pointer.
|
||||||
|
* Added Input.getDistance. Find the distance between the two given Pointer objects.
|
||||||
|
* Added Input.getAngle. Find the angle between the two given Pointer objects.
|
||||||
|
* Pointer.totalTouches value keeps a running total of the number of times the Pointer has been pressed.
|
||||||
|
* Added Pointer.position and positionDown. positionDown is placed on touch and position is update on move, useful for tracking distance/direction/gestures.
|
||||||
|
* Added Game.state - now contains a reference to the current state object (if any was given).
|
||||||
|
* Moved the Input start events from the constructors to a single Input.start method.
|
||||||
|
* Added Input.disabled boolean to globally turn off all input event processing.
|
||||||
|
* Added Input.Mouse.disabled, Input.Touch.disabled, Input.MSPointer.disabled and Input.Keyboard.disabled.
|
||||||
|
* Added Device.mspointer boolean. true if MSPointer is available on the device.
|
||||||
|
* Added Input.onDown, onUp, onTap, onDoubleTap and onHold signals - all fired by the mouse or touch.
|
||||||
|
* Added Input.recordPointerHistory to record the x/y coordinates a Pointer tracks through. Also Input.recordRate and Input.recordLimit for fine control.
|
||||||
|
* Added Input.multiInputOverride which can be MOUSE_OVERRIDES_TOUCH, TOUCH_OVERRIDES_MOUSE or MOUSE_TOUCH_COMBINE.
|
||||||
|
* Added GameObject.setBoundsFromWorld to quickly set the bounds of a game object to match those of the current game world.
|
||||||
|
* Added GameObject.canvas and GameObject.context. By default they reference Stage.canvas but can be changed to anything, i.e. a DynamicTexture
|
||||||
|
* The new canvas and context references are applied to Sprite, GeomSprite and TilemapLayer
|
||||||
|
* Added DynamicTexture.assignCanvasToGameObjects() to allow you to redirect GameObject rendering en-mass to a DynamicTexture
|
||||||
|
* Added DynamicTexture.render(x,y) to render the texture to the Stage canvas
|
||||||
|
* Added Basic.ignoreGlobalUpdate - stops the object being updated as part of the main game loop, you'll need to call update on it yourself
|
||||||
|
* Added Basic.ignoreGlobalRender - stops the object being rendered as part of the main game loop, you'll need to call render on it yourself
|
||||||
|
* Added forceUpdate and forceRender parameters to Group.update and Group.render respectively. Combined with ignoreGlobal you can create custom rendering set-ups
|
||||||
|
* Fixed Loader.progress calculation so it now accurately passes a value between 0 and 100 to your loader callback
|
||||||
|
* Added a 'hard reset' parameter to Input.reset. A hard reset clears Input signals (such as on a state swap), a soft (such as on game pause) doesn't
|
||||||
|
* Added Device.isConsoleOpen() to check if the browser console is open. Tested on Firefox with Firebug and Chrome with DevTools
|
||||||
|
* Added delay parameter to Tween.to()
|
||||||
|
* Fixed bug where GeomSprite.renderOutline was being ignored for Circle objects
|
||||||
|
* Fixed bug with GeomSprite circles rendering at twice the size they should have been and offset from actual x/y values
|
||||||
|
* Added Sprite.cacheKey which stores the key of the item from the cache that was used for its texture (if any)
|
||||||
|
* Added GameMath.shuffleArray
|
||||||
|
* Updated Animation.frame to return the index of the currentFrame if set
|
||||||
|
* Added Quad.copyTo and Quad.copyFrom
|
||||||
|
* Removed the bakedRotations parameter from Emiter.makeParticles - update your code accordingly!
|
||||||
|
* Updated various classes to remove the Flixel left-over CamelCase parameters
|
||||||
|
* Updated QuadTree to use the new CollisionMask values and significantly optimised and reduced overall class size
|
||||||
|
* Updated Collision.seperate to use the new CollisionMask
|
||||||
|
* Added a callback context parameter to Game.collide, Collision.overlap and the QuadTree class
|
||||||
|
* Stage.canvas now calls preventDefault() when the context menu is activated (oncontextmenu)
|
||||||
|
* 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 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)
|
||||||
|
* Added Quad.intersectsRaw(left, right, top, bottom, tolerance)
|
||||||
|
* Updated Sprite.inCamera to correctly apply the scrollFactor to the camera bounds check
|
||||||
|
* Added Loader.crossOrigin property which is applied to loaded Images
|
||||||
|
* Added AnimationManager.destroy() to clear out all local references and objects
|
||||||
|
* Added the clearAnimations parameter to Sprite.loadGraphic(). Allows you to change animation textures but retain the frame data.
|
||||||
|
* Added the GameObjectFactory to Game. You now make Sprites like this: game.add.sprite(). Much better separation of game object creation methods now. But you'll have to update ALL code, sorry! (blame JesseFreeman for breaking your code and coming up with the idea :)
|
||||||
|
* Added GameObjectFactory methods to add existing objects to the game world, such as existingSprite(), existingTween(), etc.
|
||||||
|
* Added the GameObjectFactory to Phaser.State
|
||||||
|
* Added new format parameter to Loader.addTextureAtlas defining the format. Currently supported: JSON Array and Starling/Sparrow XML.
|
||||||
|
|
||||||
|
* TODO: Check that tween pausing works with the new performance.now
|
||||||
|
* TODO: Game.Time should monitor pause duration
|
||||||
|
* TODO: Investigate bug re: tilemap collision and animation frames
|
||||||
|
* TODO: Update tests that use arrow keys and include touch/mouse support (FlxControlHandler style)
|
||||||
|
* TODO: GameObject.clipRect - won't work with rotation :( have to use context.clip which is crazy expensive, damnit
|
||||||
|
* TODO: Polygon geom primitive
|
||||||
|
* TODO: Move GameObject transforms to a single matrix
|
||||||
|
* TODO: this.target.view.style.cursor = "pointer"; ("default")
|
||||||
|
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
|
||||||
|
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
@@ -29,7 +126,7 @@ Games created with Phaser require a modern web browser that supports the canvas
|
|||||||
|
|
||||||
For developing with Phaser you can use either a plain-vanilla JavaScript approach or [TypeScript](https://typescript.codeplex.com/). We made no assumptions about how you like to code your games, and were careful not to impose any form of class/inheritance/structure upon you.
|
For developing with Phaser you can use either a plain-vanilla JavaScript approach or [TypeScript](https://typescript.codeplex.com/). We made no assumptions about how you like to code your games, and were careful not to impose any form of class/inheritance/structure upon you.
|
||||||
|
|
||||||
If you are compiling via TypeScript from the command-line please use `--target ES5` and `--nolib`
|
If you are compiling via TypeScript from the command-line please use `--target ES5`
|
||||||
|
|
||||||
If you need it the included Grunt file will generate a RequireJS/CommonJS version of Phaser on build.
|
If you need it the included Grunt file will generate a RequireJS/CommonJS version of Phaser on build.
|
||||||
|
|
||||||
@@ -118,9 +215,9 @@ Work in Progress
|
|||||||
We've a number of features that we know Phaser is lacking, here is our current priority list:
|
We've a number of features that we know Phaser is lacking, here is our current priority list:
|
||||||
|
|
||||||
* Better sound controls
|
* Better sound controls
|
||||||
* MSPointer support
|
|
||||||
* Text Rendering
|
* Text Rendering
|
||||||
* Buttons
|
* Buttons
|
||||||
|
* Google Play Game Services
|
||||||
|
|
||||||
Beyond this there are lots of other things we plan to add such as WebGL support, Spine animation format support, sloped collision tiles, path finding and support for custom plugins. But the list above are priority items, and by no means exhaustive either! However we do feel that the core structure of Phaser is now tightly locked down, so safe to use for small scale production games.
|
Beyond this there are lots of other things we plan to add such as WebGL support, Spine animation format support, sloped collision tiles, path finding and support for custom plugins. But the list above are priority items, and by no means exhaustive either! However we do feel that the core structure of Phaser is now tightly locked down, so safe to use for small scale production games.
|
||||||
|
|
||||||
|
|||||||
+93
-3
@@ -87,9 +87,7 @@
|
|||||||
<TypeScriptCompile Include="sprites\velocity.ts" />
|
<TypeScriptCompile Include="sprites\velocity.ts" />
|
||||||
<TypeScriptCompile Include="tilemap\basic tilemap.ts" />
|
<TypeScriptCompile Include="tilemap\basic tilemap.ts" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="mobile\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<TypeScriptCompile Include="sprites\dynamic texture 1.ts" />
|
<TypeScriptCompile Include="sprites\dynamic texture 1.ts" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -117,9 +115,97 @@
|
|||||||
<Content Include="camera fx\shake.js">
|
<Content Include="camera fx\shake.js">
|
||||||
<DependentUpon>shake.ts</DependentUpon>
|
<DependentUpon>shake.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="input\multitouch.ts" />
|
||||||
|
<TypeScriptCompile Include="groups\display order.ts" />
|
||||||
|
<TypeScriptCompile Include="collision\mask test 1.ts" />
|
||||||
|
<TypeScriptCompile Include="collision\mask animation 1.ts" />
|
||||||
|
<Content Include="collision\mask animation 1.js">
|
||||||
|
<DependentUpon>mask animation 1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="collision\mask test 1.js">
|
||||||
|
<DependentUpon>mask test 1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="collision\mask test 2.ts" />
|
||||||
|
<Content Include="collision\mask test 2.js">
|
||||||
|
<DependentUpon>mask test 2.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geometry\multi rotate.ts" />
|
||||||
|
<Content Include="geometry\multi rotate.js">
|
||||||
|
<DependentUpon>multi rotate.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geometry\rotate point 2.ts" />
|
||||||
|
<TypeScriptCompile Include="geometry\rotate point 1.ts" />
|
||||||
|
<TypeScriptCompile Include="geometry\rope bridge.ts" />
|
||||||
|
<Content Include="geometry\rope bridge.js">
|
||||||
|
<DependentUpon>rope bridge.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="geometry\rotate point 1.js">
|
||||||
|
<DependentUpon>rotate point 1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="geometry\rotate point 2.js">
|
||||||
|
<DependentUpon>rotate point 2.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geometry\rotate point 3.ts" />
|
||||||
|
<Content Include="geometry\rotate point 3.js">
|
||||||
|
<DependentUpon>rotate point 3.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geometry\verlet 1.ts" />
|
||||||
|
<TypeScriptCompile Include="geometry\rotate point 4.ts" />
|
||||||
|
<Content Include="geometry\rotate point 4.js">
|
||||||
|
<DependentUpon>rotate point 4.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="geometry\verlet 1.js">
|
||||||
|
<DependentUpon>verlet 1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="geometry\verlet sprites.ts" />
|
||||||
|
<Content Include="geometry\verlet sprites.js">
|
||||||
|
<DependentUpon>verlet sprites.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="groups\display order.js">
|
||||||
|
<DependentUpon>display order.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="input\multitouch.js">
|
||||||
|
<DependentUpon>multitouch.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="input\single touch.ts" />
|
||||||
|
<TypeScriptCompile Include="input\single tap.ts" />
|
||||||
|
<Content Include="input\single tap.js">
|
||||||
|
<DependentUpon>single tap.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="input\single touch.js">
|
||||||
|
<DependentUpon>single touch.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="misc\bootscreen.js">
|
<Content Include="misc\bootscreen.js">
|
||||||
<DependentUpon>bootscreen.ts</DependentUpon>
|
<DependentUpon>bootscreen.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
<TypeScriptCompile Include="mobile\sprite test 1.ts" />
|
||||||
|
<TypeScriptCompile Include="mobile\bunny mobile.ts" />
|
||||||
|
<TypeScriptCompile Include="misc\time.ts" />
|
||||||
|
<TypeScriptCompile Include="misc\starfield.ts" />
|
||||||
|
<Content Include="misc\starfield.js">
|
||||||
|
<DependentUpon>starfield.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="misc\time.js">
|
||||||
|
<DependentUpon>time.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="mobile\bunny mobile.js">
|
||||||
|
<DependentUpon>bunny mobile.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<Content Include="mobile\sprite test 1.js">
|
||||||
|
<DependentUpon>sprite test 1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="particles\mousetrail.ts" />
|
||||||
|
<Content Include="particles\mousetrail.js">
|
||||||
|
<DependentUpon>mousetrail.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="physics\temp1.ts" />
|
||||||
|
<Content Include="physics\temp1.js">
|
||||||
|
<DependentUpon>temp1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="physics\temp2.ts" />
|
||||||
|
<Content Include="physics\temp2.js">
|
||||||
|
<DependentUpon>temp2.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="scrollzones\ballscroller.js">
|
<Content Include="scrollzones\ballscroller.js">
|
||||||
<DependentUpon>ballscroller.ts</DependentUpon>
|
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -153,6 +239,10 @@
|
|||||||
<TypeScriptCompile Include="tilemap\get tile.ts" />
|
<TypeScriptCompile Include="tilemap\get tile.ts" />
|
||||||
<TypeScriptCompile Include="tilemap\collision.ts" />
|
<TypeScriptCompile Include="tilemap\collision.ts" />
|
||||||
<TypeScriptCompile Include="tilemap\collide with tile.ts" />
|
<TypeScriptCompile Include="tilemap\collide with tile.ts" />
|
||||||
|
<TypeScriptCompile Include="sprites\starling texture atlas 1.ts" />
|
||||||
|
<Content Include="sprites\starling texture atlas 1.js">
|
||||||
|
<DependentUpon>starling texture atlas 1.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
<Content Include="tilemap\collide with tile.js">
|
<Content Include="tilemap\collide with tile.js">
|
||||||
<DependentUpon>collide with tile.ts</DependentUpon>
|
<DependentUpon>collide with tile.ts</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<TextureAtlas imagePath="sprites.png">
|
||||||
|
<!--
|
||||||
|
Created with ShoeBox
|
||||||
|
http://renderhjs.net/shoebox/
|
||||||
|
-->
|
||||||
|
<SubTexture name="running bot_0000.png" x="0" y="286" width="279" height="293" frameX="-1" frameY="-14" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0001.png" x="0" y="580" width="277" height="287" frameX="-2" frameY="-17" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0002.png" x="280" y="286" width="277" height="289" frameX="-2" frameY="-16" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0003.png" x="820" y="621" width="165" height="317" frameX="-58" frameY="-2" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0004.png" x="556" y="576" width="263" height="315" frameX="-9" frameY="-3" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0005.png" x="0" y="868" width="271" height="287" frameX="-5" frameY="-17" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0006.png" x="558" y="0" width="261" height="311" frameX="-10" frameY="-5" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0007.png" x="278" y="580" width="277" height="289" frameX="-2" frameY="-16" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0008.png" x="820" y="0" width="247" height="299" frameX="-17" frameY="-11" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0009.png" x="820" y="300" width="169" height="320" frameX="-56" frameY="-0" frameWidth="280" frameHeight="320"/>
|
||||||
|
<SubTexture name="running bot_0010.png" x="0" y="0" width="280" height="285" frameX="-0" frameY="-18" frameWidth="280" frameHeight="320"/>
|
||||||
|
</TextureAtlas>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<TextureAtlas imagePath="sprites.png">
|
||||||
|
<!--
|
||||||
|
Created with ShoeBox
|
||||||
|
http://renderhjs.net/shoebox/
|
||||||
|
-->
|
||||||
|
<SubTexture name="bunny.png" x="0" y="0" width="248" height="340" frameX="-0" frameY="-0" frameWidth="248" frameHeight="340"/>
|
||||||
|
<SubTexture name="ilkke.png" x="0" y="406" width="53" height="71" frameX="-0" frameY="-0" frameWidth="53" frameHeight="71"/>
|
||||||
|
<SubTexture name="mushroom2.png" x="0" y="341" width="64" height="64" frameX="-0" frameY="-0" frameWidth="64" frameHeight="64"/>
|
||||||
|
<SubTexture name="oz_pov_melting_disk.png" x="65" y="341" width="62" height="116" frameX="-0" frameY="-0" frameWidth="62" frameHeight="116"/>
|
||||||
|
</TextureAtlas>
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
var car;
|
var car;
|
||||||
var fade;
|
var fade;
|
||||||
function create() {
|
function create() {
|
||||||
myGame.createSprite(0, 0, 'background');
|
myGame.add.sprite(0, 0, 'background');
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
// Add our effect to the camera
|
// Add our effect to the camera
|
||||||
fade = myGame.camera.fx.add(Phaser.FX.Camera.Fade);
|
fade = myGame.camera.fx.add(Phaser.FX.Camera.Fade);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'background');
|
myGame.add.sprite(0, 0, 'background');
|
||||||
|
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
|
|
||||||
// Add our effect to the camera
|
// Add our effect to the camera
|
||||||
fade = <Phaser.FX.Camera.Fade> myGame.camera.fx.add(Phaser.FX.Camera.Fade);
|
fade = <Phaser.FX.Camera.Fade> myGame.camera.fx.add(Phaser.FX.Camera.Fade);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
var car;
|
var car;
|
||||||
var flash;
|
var flash;
|
||||||
function create() {
|
function create() {
|
||||||
myGame.createSprite(0, 0, 'background');
|
myGame.add.sprite(0, 0, 'background');
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
// Add our effect to the camera
|
// Add our effect to the camera
|
||||||
flash = myGame.camera.fx.add(Phaser.FX.Camera.Flash);
|
flash = myGame.camera.fx.add(Phaser.FX.Camera.Flash);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'background');
|
myGame.add.sprite(0, 0, 'background');
|
||||||
|
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
|
|
||||||
// Add our effect to the camera
|
// Add our effect to the camera
|
||||||
flash = <Phaser.FX.Camera.Flash> myGame.camera.fx.add(Phaser.FX.Camera.Flash);
|
flash = <Phaser.FX.Camera.Flash> myGame.camera.fx.add(Phaser.FX.Camera.Flash);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
// Experiment with variations on these to see the different mirror effects that can be achieved.
|
// Experiment with variations on these to see the different mirror effects that can be achieved.
|
||||||
//mirror.flipX = true;
|
//mirror.flipX = true;
|
||||||
//mirror.flipY = true;
|
//mirror.flipY = true;
|
||||||
myGame.createSprite(0, 0, 'backdrop');
|
myGame.add.sprite(0, 0, 'backdrop');
|
||||||
}
|
}
|
||||||
function update() {
|
function update() {
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
//mirror.flipX = true;
|
//mirror.flipX = true;
|
||||||
//mirror.flipY = true;
|
//mirror.flipY = true;
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'backdrop');
|
myGame.add.sprite(0, 0, 'backdrop');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
scanlines.spacing = 2;
|
scanlines.spacing = 2;
|
||||||
// This is the color the lines will be drawn in
|
// This is the color the lines will be drawn in
|
||||||
scanlines.color = 'rgba(0, 0, 0, 0.8)';
|
scanlines.color = 'rgba(0, 0, 0, 0.8)';
|
||||||
myGame.createSprite(0, 0, 'backdrop');
|
myGame.add.sprite(0, 0, 'backdrop');
|
||||||
}
|
}
|
||||||
function update() {
|
function update() {
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
// This is the color the lines will be drawn in
|
// This is the color the lines will be drawn in
|
||||||
scanlines.color = 'rgba(0, 0, 0, 0.8)';
|
scanlines.color = 'rgba(0, 0, 0, 0.8)';
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'backdrop');
|
myGame.add.sprite(0, 0, 'backdrop');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
var car;
|
var car;
|
||||||
var shake;
|
var shake;
|
||||||
function create() {
|
function create() {
|
||||||
myGame.createSprite(0, 0, 'background');
|
myGame.add.sprite(0, 0, 'background');
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
// Add our effect to the camera
|
// Add our effect to the camera
|
||||||
shake = myGame.camera.fx.add(Phaser.FX.Camera.Shake);
|
shake = myGame.camera.fx.add(Phaser.FX.Camera.Shake);
|
||||||
myGame.onRenderCallback = render;
|
myGame.onRenderCallback = render;
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'background');
|
myGame.add.sprite(0, 0, 'background');
|
||||||
|
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
|
|
||||||
// Add our effect to the camera
|
// Add our effect to the camera
|
||||||
shake = <Phaser.FX.Camera.Shake> myGame.camera.fx.add(Phaser.FX.Camera.Shake);
|
shake = <Phaser.FX.Camera.Shake> myGame.camera.fx.add(Phaser.FX.Camera.Shake);
|
||||||
|
|||||||
@@ -10,11 +10,11 @@
|
|||||||
var car;
|
var car;
|
||||||
var miniCam;
|
var miniCam;
|
||||||
function create() {
|
function create() {
|
||||||
myGame.createSprite(0, 0, 'grid');
|
myGame.add.sprite(0, 0, 'grid');
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
||||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||||
miniCam = myGame.createCamera(0, 0, 300, 300);
|
miniCam = myGame.add.camera(0, 0, 300, 300);
|
||||||
miniCam.follow(car, Phaser.Camera.STYLE_TOPDOWN_TIGHT);
|
miniCam.follow(car, Phaser.Camera.STYLE_TOPDOWN_TIGHT);
|
||||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||||
miniCam.showBorder = true;
|
miniCam.showBorder = true;
|
||||||
|
|||||||
@@ -20,14 +20,14 @@
|
|||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'grid');
|
myGame.add.sprite(0, 0, 'grid');
|
||||||
|
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.add.sprite(400, 300, 'car');
|
||||||
|
|
||||||
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
||||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||||
|
|
||||||
miniCam = myGame.createCamera(0, 0, 300, 300);
|
miniCam = myGame.add.camera(0, 0, 300, 300);
|
||||||
miniCam.follow(car, Phaser.Camera.STYLE_TOPDOWN_TIGHT);
|
miniCam.follow(car, Phaser.Camera.STYLE_TOPDOWN_TIGHT);
|
||||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||||
miniCam.showBorder = true;
|
miniCam.showBorder = true;
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
myGame.loader.load();
|
myGame.loader.load();
|
||||||
}
|
}
|
||||||
function create() {
|
function create() {
|
||||||
myGame.createSprite(0, 0, 'backdrop');
|
myGame.add.sprite(0, 0, 'backdrop');
|
||||||
for(var i = 0; i < 100; i++) {
|
for(var i = 0; i < 100; i++) {
|
||||||
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
myGame.add.sprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
||||||
}
|
}
|
||||||
myGame.onRenderCallback = render;
|
myGame.onRenderCallback = render;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
|
||||||
myGame.createSprite(0, 0, 'backdrop');
|
myGame.add.sprite(0, 0, 'backdrop');
|
||||||
|
|
||||||
for (var i = 0; i < 100; i++)
|
for (var i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
myGame.add.sprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
||||||
}
|
}
|
||||||
|
|
||||||
myGame.onRenderCallback = render;
|
myGame.onRenderCallback = render;
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
var cam2;
|
var cam2;
|
||||||
function create() {
|
function create() {
|
||||||
for(var i = 0; i < 1000; i++) {
|
for(var i = 0; i < 1000; i++) {
|
||||||
myGame.createSprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
myGame.add.sprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
||||||
}
|
}
|
||||||
myGame.camera.setPosition(16, 80);
|
myGame.camera.setPosition(16, 80);
|
||||||
myGame.camera.setSize(320, 320);
|
myGame.camera.setSize(320, 320);
|
||||||
myGame.camera.showBorder = true;
|
myGame.camera.showBorder = true;
|
||||||
myGame.camera.borderColor = 'rgb(255,0,0)';
|
myGame.camera.borderColor = 'rgb(255,0,0)';
|
||||||
cam2 = myGame.createCamera(380, 100, 400, 400);
|
cam2 = myGame.add.camera(380, 100, 400, 400);
|
||||||
cam2.showBorder = true;
|
cam2.showBorder = true;
|
||||||
cam2.borderColor = 'rgb(255,255,0)';
|
cam2.borderColor = 'rgb(255,255,0)';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
for (var i = 0; i < 1000; i++)
|
for (var i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
myGame.createSprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
myGame.add.sprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
||||||
}
|
}
|
||||||
|
|
||||||
myGame.camera.setPosition(16, 80);
|
myGame.camera.setPosition(16, 80);
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
myGame.camera.showBorder = true;
|
myGame.camera.showBorder = true;
|
||||||
myGame.camera.borderColor = 'rgb(255,0,0)';
|
myGame.camera.borderColor = 'rgb(255,0,0)';
|
||||||
|
|
||||||
cam2 = myGame.createCamera(380, 100, 400, 400);
|
cam2 = myGame.add.camera(380, 100, 400, 400);
|
||||||
cam2.showBorder = true;
|
cam2.showBorder = true;
|
||||||
cam2.borderColor = 'rgb(255,255,0)';
|
cam2.borderColor = 'rgb(255,255,0)';
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
function create() {
|
function create() {
|
||||||
for(var i = 0; i < 1000; i++) {
|
for(var i = 0; i < 1000; i++) {
|
||||||
if(Math.random() > 0.5) {
|
if(Math.random() > 0.5) {
|
||||||
myGame.createSprite(Math.random() * 3000, Math.random() * 3000, 'car');
|
myGame.add.sprite(Math.random() * 3000, Math.random() * 3000, 'car');
|
||||||
} else {
|
} else {
|
||||||
myGame.createSprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
myGame.add.sprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
myGame.camera.setPosition(100, 100);
|
myGame.camera.setPosition(100, 100);
|
||||||
|
|||||||
@@ -21,11 +21,11 @@
|
|||||||
{
|
{
|
||||||
if (Math.random() > 0.5)
|
if (Math.random() > 0.5)
|
||||||
{
|
{
|
||||||
myGame.createSprite(Math.random() * 3000, Math.random() * 3000, 'car');
|
myGame.add.sprite(Math.random() * 3000, Math.random() * 3000, 'car');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myGame.createSprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
myGame.add.sprite(Math.random() * 3000, Math.random() * 3000, 'melon');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user