mirror of
https://github.com/wassname/phaser.git
synced 2026-07-11 00:40:20 +08:00
Updated Loader component and fixed a few Pointer issues.
This commit is contained in:
+8
-8
@@ -101,7 +101,7 @@ module Phaser {
|
||||
private _step: number = 0;
|
||||
|
||||
/**
|
||||
* Whether loader complete loading or not.
|
||||
* Whether load complete loading or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
private _loadComplete: bool = false;
|
||||
@@ -187,7 +187,7 @@ module Phaser {
|
||||
* Reference to the assets loader.
|
||||
* @type {Loader}
|
||||
*/
|
||||
public loader: Loader;
|
||||
public load: Loader;
|
||||
|
||||
/**
|
||||
* Reference to the math helper.
|
||||
@@ -288,7 +288,7 @@ module Phaser {
|
||||
this.add = new GameObjectFactory(this);
|
||||
this.sound = new SoundManager(this);
|
||||
this.cache = new Cache(this);
|
||||
this.loader = new Loader(this, this.loadComplete);
|
||||
this.load = new Loader(this, this.loadComplete);
|
||||
this.time = new Time(this);
|
||||
this.tweens = new TweenManager(this);
|
||||
this.input = new Input(this);
|
||||
@@ -353,7 +353,7 @@ module Phaser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the loader has finished after init was run.
|
||||
* Called when the load has finished after init was run.
|
||||
*/
|
||||
private loadComplete() {
|
||||
|
||||
@@ -432,12 +432,12 @@ module Phaser {
|
||||
|
||||
if (this.onInitCallback !== null)
|
||||
{
|
||||
this.loader.reset();
|
||||
this.load.reset();
|
||||
|
||||
this.onInitCallback.call(this.callbackContext);
|
||||
|
||||
// Is the loader empty?
|
||||
if (this.loader.queueSize == 0)
|
||||
// Is the load empty?
|
||||
if (this.load.queueSize == 0)
|
||||
{
|
||||
if (this.onCreateCallback !== null)
|
||||
{
|
||||
@@ -584,7 +584,7 @@ module Phaser {
|
||||
this.onDestroyCallback = null;
|
||||
this.cache = null;
|
||||
this.input = null;
|
||||
this.loader = null;
|
||||
this.load = null;
|
||||
this.sound = null;
|
||||
this.stage = null;
|
||||
this.time = null;
|
||||
|
||||
+2
-2
@@ -255,7 +255,7 @@ module Phaser {
|
||||
|
||||
public pauseGame() {
|
||||
|
||||
if (this.disablePauseScreen == false)
|
||||
if (this.disablePauseScreen == false && this.pauseScreen)
|
||||
{
|
||||
this.pauseScreen.onPaused();
|
||||
}
|
||||
@@ -267,7 +267,7 @@ module Phaser {
|
||||
|
||||
public resumeGame() {
|
||||
|
||||
if (this.disablePauseScreen == false)
|
||||
if (this.disablePauseScreen == false && this.pauseScreen)
|
||||
{
|
||||
this.pauseScreen.onResume();
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ module Phaser {
|
||||
this.camera = game.camera;
|
||||
this.cache = game.cache;
|
||||
this.input = game.input;
|
||||
this.loader = game.loader;
|
||||
this.load = game.load;
|
||||
this.math = game.math;
|
||||
this.motion = game.motion;
|
||||
this.sound = game.sound;
|
||||
@@ -66,7 +66,7 @@ module Phaser {
|
||||
* Reference to the assets loader.
|
||||
* @type {Loader}
|
||||
*/
|
||||
public loader: Loader;
|
||||
public load: Loader;
|
||||
|
||||
/**
|
||||
* Reference to the math helper.
|
||||
|
||||
@@ -287,7 +287,7 @@ module Phaser.Components {
|
||||
}
|
||||
else
|
||||
{
|
||||
this._pointOutHandler(pointer);
|
||||
this._pointerOutHandler(pointer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -316,7 +316,7 @@ module Phaser.Components {
|
||||
|
||||
}
|
||||
|
||||
public _pointOutHandler(pointer: Pointer) {
|
||||
public _pointerOutHandler(pointer: Pointer) {
|
||||
|
||||
this._pointerData[pointer.id].isOver = false;
|
||||
this._pointerData[pointer.id].isOut = true;
|
||||
@@ -335,11 +335,8 @@ module Phaser.Components {
|
||||
|
||||
public _touchedHandler(pointer: Pointer): bool {
|
||||
|
||||
console.log('touched handler', this._pointerData[pointer.id]);
|
||||
|
||||
if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true)
|
||||
{
|
||||
//console.log('touchDown on', this._sprite.texture.cacheKey,this._sprite.frameName, this._sprite.frameBounds.width,this._sprite.frameBounds.height);
|
||||
this._pointerData[pointer.id].isDown = true;
|
||||
this._pointerData[pointer.id].isUp = false;
|
||||
this._pointerData[pointer.id].timeDown = this.game.time.now;
|
||||
@@ -362,8 +359,6 @@ module Phaser.Components {
|
||||
|
||||
public _releasedHandler(pointer: Pointer) {
|
||||
|
||||
console.log('release handler');
|
||||
|
||||
// If was previously touched by this Pointer, check if still is
|
||||
if (this._pointerData[pointer.id].isDown && pointer.isUp)
|
||||
{
|
||||
@@ -562,7 +557,7 @@ module Phaser.Components {
|
||||
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
|
||||
}
|
||||
|
||||
//pointer.draggedObject = this._sprite;
|
||||
this.updateDrag(pointer);
|
||||
|
||||
}
|
||||
|
||||
@@ -678,13 +673,13 @@ module Phaser.Components {
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._sprite.texture.context.font = '16px Courier';
|
||||
this._sprite.texture.context.font = '14px Courier';
|
||||
this._sprite.texture.context.fillStyle = color;
|
||||
this._sprite.texture.context.fillText('Sprite Input: (' + this._sprite.frameBounds.width + ' x ' + this._sprite.frameBounds.height + ')', x, y);
|
||||
this._sprite.texture.context.fillText('x: ' + this.pointerX(1).toFixed(1) + ' y: ' + this.pointerY(1).toFixed(1), x, y + 14);
|
||||
this._sprite.texture.context.fillText('over: ' + this.pointerOver(1) + ' duration: ' + this.overDuration(1).toFixed(0), x, y + 28);
|
||||
this._sprite.texture.context.fillText('down: ' + this.pointerDown(1) + ' duration: ' + this.downDuration(1).toFixed(0), x, y + 42);
|
||||
this._sprite.texture.context.fillText('just over: ' + this.justOver(1) + ' just out: ' + this.justOut(1), x, y + 56);
|
||||
this._sprite.texture.context.fillText('x: ' + this.pointerX().toFixed(1) + ' y: ' + this.pointerY().toFixed(1), x, y + 14);
|
||||
this._sprite.texture.context.fillText('over: ' + this.pointerOver() + ' duration: ' + this.overDuration().toFixed(0), x, y + 28);
|
||||
this._sprite.texture.context.fillText('down: ' + this.pointerDown() + ' duration: ' + this.downDuration().toFixed(0), x, y + 42);
|
||||
this._sprite.texture.context.fillText('just over: ' + this.justOver() + ' just out: ' + this.justOut(), x, y + 56);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -904,7 +904,7 @@ module Phaser {
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.font = '24px Courier';
|
||||
this._game.stage.context.font = '14px Courier';
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Input', x, y);
|
||||
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
|
||||
|
||||
+2
-68
@@ -348,29 +348,6 @@ module Phaser {
|
||||
this.game.input.currentPointers++;
|
||||
}
|
||||
|
||||
// Build our temporary click stack
|
||||
/*
|
||||
var _highestPriority = 0;
|
||||
var _highestRenderID = 0;
|
||||
var _highestRenderObject: number = -1;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
|
||||
{
|
||||
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
_highestRenderObject = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (_highestRenderObject !== -1 && this._stateReset == false)
|
||||
{
|
||||
this.targetObject = this.game.input.inputObjects[_highestRenderObject];
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
//_highestRenderObject.input._touchedHandler(this);
|
||||
}
|
||||
*/
|
||||
|
||||
if (this.targetObject !== null)
|
||||
{
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
@@ -406,50 +383,6 @@ module Phaser {
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through the tracked objects
|
||||
|
||||
// Build our temporary click stack
|
||||
/*
|
||||
var _highestPriority = 0;
|
||||
var _highestRenderID = 0;
|
||||
var _highestRenderObject = null;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
{
|
||||
if (this.game.input.inputObjects[i].input.enabled)
|
||||
{
|
||||
//if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority)
|
||||
if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
|
||||
{
|
||||
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
_highestRenderObject = this.game.input.inputObjects[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_highestRenderObject !== null)
|
||||
{
|
||||
_highestRenderObject.input._pointerOverHandler(this);
|
||||
|
||||
if (this.isDown && this._stateReset == false)
|
||||
{
|
||||
_highestRenderObject.input._touchedHandler(this);
|
||||
}
|
||||
|
||||
// Now update all objects with the highest priority ID (can be more than 1)
|
||||
//for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
//{
|
||||
// if (this.game.input.inputObjects[i].input.priorityID == _highestPriority)
|
||||
// {
|
||||
// if (this.game.input.inputObjects[i].input._touchedHandler(this) == false)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -499,7 +432,7 @@ module Phaser {
|
||||
else
|
||||
{
|
||||
// Build our temporary click stack
|
||||
var _highestRenderID = 0;
|
||||
var _highestRenderID = -1;
|
||||
var _highestRenderObject: number = -1;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
|
||||
@@ -517,6 +450,7 @@ module Phaser {
|
||||
this.targetObject = this.game.input.inputObjects[_highestRenderObject];
|
||||
this.targetObject.input._pointerOverHandler(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
@@ -107,7 +107,7 @@ module Phaser {
|
||||
* @param key {string} Unique asset key of this image file.
|
||||
* @param url {string} URL of image file.
|
||||
*/
|
||||
public addImageFile(key: string, url: string) {
|
||||
public image(key: string, url: string) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
@@ -126,7 +126,7 @@ module Phaser {
|
||||
* @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 spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ module Phaser {
|
||||
* @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) {
|
||||
public atlas(key: string, textureURL: string, atlasURL?: string = null, atlasData? = null, format?:number = Loader.TEXTURE_ATLAS_JSON_ARRAY) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
@@ -222,7 +222,7 @@ module Phaser {
|
||||
* @param key {string} Unique asset key of the audio file.
|
||||
* @param url {string} URL of audio file.
|
||||
*/
|
||||
public addAudioFile(key: string, url: string) {
|
||||
public audio(key: string, url: string) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
@@ -238,7 +238,7 @@ module Phaser {
|
||||
* @param key {string} Unique asset key of the text file.
|
||||
* @param url {string} URL of text file.
|
||||
*/
|
||||
public addTextFile(key: string, url: string) {
|
||||
public text(key: string, url: string) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
@@ -273,7 +273,7 @@ module Phaser {
|
||||
* @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 start(onFileLoadCallback = null, onCompleteCallback = null) {
|
||||
|
||||
this.progress = 0;
|
||||
this.hasLoaded = false;
|
||||
|
||||
@@ -19,6 +19,11 @@ module Phaser {
|
||||
|
||||
this._game = game;
|
||||
|
||||
if (window['PhaserGlobal'] && window['PhaserGlobal'].disableAudio == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.device.webaudio == true)
|
||||
{
|
||||
if (!!window['AudioContext'])
|
||||
|
||||
Reference in New Issue
Block a user