mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
Version 0.9.2 update. See the change log for full details.
This commit is contained in:
parent
364492d786
commit
361b8e5779
17 changed files with 11750 additions and 3815 deletions
|
@ -100,8 +100,18 @@ module Phaser {
|
|||
|
||||
if (this._anims[name])
|
||||
{
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentAnim.play(frameRate, loop);
|
||||
if (this.currentAnim == this._anims[name])
|
||||
{
|
||||
if (this.currentAnim.isPlaying == false)
|
||||
{
|
||||
this.currentAnim.play(frameRate, loop);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentAnim.play(frameRate, loop);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -202,7 +202,20 @@ module Phaser {
|
|||
|
||||
if (this.onInitCallback !== null)
|
||||
{
|
||||
this.loader.reset();
|
||||
|
||||
this.onInitCallback.call(this.callbackContext);
|
||||
|
||||
// Is the loader empty?
|
||||
if (this.loader.queueSize == 0)
|
||||
{
|
||||
if (this.onCreateCallback !== null)
|
||||
{
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
|
||||
this._loadComplete = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ module Phaser {
|
|||
this._keys = [];
|
||||
this._fileList = {};
|
||||
this._xhr = new XMLHttpRequest();
|
||||
this._queueSize = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,20 +30,18 @@ module Phaser {
|
|||
private _onFileLoad;
|
||||
private _progressChunk: number;
|
||||
private _xhr: XMLHttpRequest;
|
||||
private _queueSize: number;
|
||||
|
||||
public hasLoaded: bool;
|
||||
public progress: number;
|
||||
|
||||
private checkKeyExists(key: string): bool {
|
||||
public reset() {
|
||||
this._queueSize = 0;
|
||||
}
|
||||
|
||||
if (this._fileList[key])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public get queueSize(): number {
|
||||
|
||||
return this._queueSize;
|
||||
|
||||
}
|
||||
|
||||
|
@ -50,6 +49,7 @@ module Phaser {
|
|||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'image', key: key, url: url, data: null, error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ module Phaser {
|
|||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'spritesheet', key: key, url: url, data: null, frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
|
@ -68,15 +69,12 @@ module Phaser {
|
|||
|
||||
public addTextureAtlas(key: string, url: string, jsonURL?: string = null, jsonData? = null) {
|
||||
|
||||
//console.log('addTextureAtlas');
|
||||
//console.log(typeof jsonData);
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
if (jsonURL !== null)
|
||||
{
|
||||
//console.log('A URL to a json file has been given');
|
||||
// A URL to a json file has been given
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: jsonURL, jsonData: null, error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
|
@ -85,24 +83,21 @@ module Phaser {
|
|||
// A json string or object has been given
|
||||
if (typeof jsonData === 'string')
|
||||
{
|
||||
//console.log('A json string has been given');
|
||||
var data = JSON.parse(jsonData);
|
||||
//console.log(data);
|
||||
// Malformed?
|
||||
if (data['frames'])
|
||||
{
|
||||
//console.log('frames array found');
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: data['frames'], error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log('A json object has been given', jsonData);
|
||||
// Malformed?
|
||||
if (jsonData['frames'])
|
||||
{
|
||||
//console.log('frames array found');
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: jsonData['frames'], error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
|
@ -118,6 +113,7 @@ module Phaser {
|
|||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'audio', key: key, url: url, data: null, buffer: null, error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
|
@ -128,6 +124,7 @@ module Phaser {
|
|||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
this._queueSize++;
|
||||
this._fileList[key] = { type: 'text', key: key, url: url, data: null, error: false, loaded: false };
|
||||
this._keys.push(key);
|
||||
}
|
||||
|
@ -243,7 +240,6 @@ module Phaser {
|
|||
break;
|
||||
|
||||
case 'textureatlas':
|
||||
//console.log('texture atlas loaded');
|
||||
if (file.jsonURL == null)
|
||||
{
|
||||
this._game.cache.addTextureAtlas(file.key, file.url, file.data, file.jsonData);
|
||||
|
@ -251,7 +247,6 @@ module Phaser {
|
|||
else
|
||||
{
|
||||
// Load the JSON before carrying on with the next file
|
||||
//console.log('Loading the JSON before carrying on with the next file');
|
||||
loadNext = false;
|
||||
this._xhr.open("GET", file.jsonURL, true);
|
||||
this._xhr.responseType = "text";
|
||||
|
@ -281,12 +276,8 @@ module Phaser {
|
|||
|
||||
private jsonLoadComplete(key: string) {
|
||||
|
||||
//console.log('json load complete');
|
||||
|
||||
var data = JSON.parse(this._xhr.response);
|
||||
|
||||
//console.log(data);
|
||||
|
||||
// Malformed?
|
||||
if (data['frames'])
|
||||
{
|
||||
|
@ -300,8 +291,6 @@ module Phaser {
|
|||
|
||||
private jsonLoadError(key: string) {
|
||||
|
||||
//console.log('json load error');
|
||||
|
||||
var file = this._fileList[key];
|
||||
file.error = true;
|
||||
this.nextFile(key, true);
|
||||
|
@ -311,6 +300,11 @@ module Phaser {
|
|||
private nextFile(previousKey: string, success: bool) {
|
||||
|
||||
this.progress = Math.round(this.progress + this._progressChunk);
|
||||
|
||||
if (this.progress > 1)
|
||||
{
|
||||
this.progress = 1;
|
||||
}
|
||||
|
||||
if (this._onFileLoad)
|
||||
{
|
||||
|
@ -335,6 +329,19 @@ module Phaser {
|
|||
|
||||
}
|
||||
|
||||
private checkKeyExists(key: string): bool {
|
||||
|
||||
if (this._fileList[key])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v0.9.1 - April 19th 2013
|
||||
* v0.9.2 - April 20th 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
|
@ -16,6 +16,6 @@
|
|||
|
||||
module Phaser {
|
||||
|
||||
export var VERSION: string = 'Phaser version 0.9.1';
|
||||
export var VERSION: string = 'Phaser version 0.9.2';
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ module Phaser {
|
|||
public renderDebug: bool = false;
|
||||
public renderDebugColor: string = 'rgba(0,255,0,0.5)';
|
||||
public renderDebugPointColor: string = 'rgba(255,255,255,1)';
|
||||
public flipped: bool = false;
|
||||
|
||||
public loadGraphic(key: string): Sprite {
|
||||
|
||||
|
@ -157,13 +158,6 @@ module Phaser {
|
|||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
//if (this.flip === true)
|
||||
//{
|
||||
// this.context.save();
|
||||
// this.context.translate(game.canvas.width, 0);
|
||||
// this.context.scale(-1, 1);
|
||||
//}
|
||||
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = this.bounds.width;
|
||||
|
@ -229,15 +223,24 @@ module Phaser {
|
|||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
|
||||
// Rotation - needs to be set from origin
|
||||
if (this.angle !== 0)
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
if (this.angle !== 0 || this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
//this._game.stage.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
}
|
||||
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
|
||||
if (this.flipped == true)
|
||||
{
|
||||
this._game.stage.context.scale(-1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
this._sx = Math.round(this._sx);
|
||||
|
@ -286,18 +289,17 @@ module Phaser {
|
|||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
|
||||
if (this.flipped === true || this.rotation !== 0)
|
||||
{
|
||||
//this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
||||
if (this.renderDebug)
|
||||
{
|
||||
this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
|
||||
}
|
||||
|
||||
//if (this.flip === true || this.rotation !== 0)
|
||||
if (this.rotation !== 0)
|
||||
{
|
||||
this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v0.9.2 - April 20th 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
* Richard Davey (@photonstorm)
|
||||
*
|
||||
* Many thanks to Adam Saltsman (@ADAMATOMIC) for the original Flixel AS3 code on which Phaser is based.
|
||||
*
|
||||
* "If you want your children to be intelligent, read them fairy tales."
|
||||
* "If you want them to be more intelligent, read them more fairy tales."
|
||||
* -- Albert Einstein
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
Phaser.VERSION = 'Phaser version 0.9.1';
|
||||
Phaser.VERSION = 'Phaser version 0.9.2';
|
||||
})(Phaser || (Phaser = {}));
|
||||
|
|
|
@ -529,8 +529,6 @@ module Phaser {
|
|||
this._game.stage.context.clip();
|
||||
}
|
||||
|
||||
//this.totalSpritesRendered = this._game.world.renderSpritesInCamera(this.worldView, sx, sy);
|
||||
//this._game.world.group.render(this.worldView, this.worldView.x, this.worldView.y, sx, sy);
|
||||
this._game.world.group.render(this, this._sx, this._sy);
|
||||
|
||||
if (this.showBorder)
|
||||
|
|
|
@ -87,11 +87,16 @@ module Phaser {
|
|||
|
||||
}
|
||||
|
||||
private onComplete() {
|
||||
public restart() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
// callback
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
|
||||
this._timeLastFrame = this._game.time.now;
|
||||
this._timeNextFrame = this._game.time.now + this.delay;
|
||||
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -146,6 +151,14 @@ module Phaser {
|
|||
|
||||
}
|
||||
|
||||
private onComplete() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
// callback
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
README.md
11
README.md
|
@ -1,9 +1,9 @@
|
|||
Phaser
|
||||
======
|
||||
|
||||
Version 0.9.1
|
||||
Version 0.9.2
|
||||
|
||||
19th April 2013
|
||||
20th April 2013
|
||||
|
||||
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
|
||||
|
||||
|
@ -18,6 +18,13 @@ For support post to the Phaser board on the [HTML5 Game Devs forum](http://www.h
|
|||
Change Log
|
||||
----------
|
||||
|
||||
V0.9.2
|
||||
|
||||
Fixed issue with create not being called if there was an empty init method.<br />
|
||||
Added ability to flip a sprite (Sprite.flipped = true) + a test case for it.<br />
|
||||
Added ability to restart a sprite animation.<br />
|
||||
Sprite animations don't restart if you call play on them when they are already running.<br />
|
||||
|
||||
V0.9.1
|
||||
|
||||
Added the new align property to GameObjects that controls placement when rendering.<br />
|
||||
|
|
|
@ -104,6 +104,10 @@
|
|||
<Content Include="sprites\align.js">
|
||||
<DependentUpon>align.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="sprites\flipped.ts" />
|
||||
<Content Include="sprites\flipped.js">
|
||||
<DependentUpon>flipped.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="tweens\bounce.js">
|
||||
<DependentUpon>bounce.ts</DependentUpon>
|
||||
</Content>
|
||||
|
|
7643
Tests/phaser.js
7643
Tests/phaser.js
File diff suppressed because it is too large
Load diff
36
Tests/sprites/flipped.js
Normal file
36
Tests/sprites/flipped.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var bot;
|
||||
var bot2;
|
||||
function create() {
|
||||
// This bot will flip properly when he reaches the edge
|
||||
bot = myGame.createSprite(myGame.stage.width, 300, 'bot');
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
bot.velocity.x = -200;
|
||||
// This one won't
|
||||
bot2 = myGame.createSprite(myGame.stage.width, 200, 'bot');
|
||||
bot2.animations.add('run');
|
||||
bot2.animations.play('run', 10, true);
|
||||
bot2.velocity.x = -150;
|
||||
}
|
||||
function update() {
|
||||
if(bot.x < -bot.width) {
|
||||
bot.flipped = true;
|
||||
bot.velocity.x = 200;
|
||||
} else if(bot.x > myGame.stage.width) {
|
||||
bot.flipped = false;
|
||||
bot.velocity.x = -200;
|
||||
}
|
||||
if(bot2.x < -bot2.width) {
|
||||
bot2.velocity.x = 200;
|
||||
} else if(bot2.x > myGame.stage.width) {
|
||||
bot2.velocity.x = -200;
|
||||
}
|
||||
}
|
||||
})();
|
57
Tests/sprites/flipped.ts
Normal file
57
Tests/sprites/flipped.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var bot: Phaser.Sprite;
|
||||
var bot2: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
// This bot will flip properly when he reaches the edge
|
||||
bot = myGame.createSprite(myGame.stage.width, 300, 'bot');
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
bot.velocity.x = -200;
|
||||
|
||||
// This one won't
|
||||
bot2 = myGame.createSprite(myGame.stage.width, 200, 'bot');
|
||||
bot2.animations.add('run');
|
||||
bot2.animations.play('run', 10, true);
|
||||
bot2.velocity.x = -150;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (bot.x < -bot.width)
|
||||
{
|
||||
bot.flipped = true;
|
||||
bot.velocity.x = 200;
|
||||
}
|
||||
else if (bot.x > myGame.stage.width)
|
||||
{
|
||||
bot.flipped = false;
|
||||
bot.velocity.x = -200;
|
||||
}
|
||||
|
||||
if (bot2.x < -bot2.width)
|
||||
{
|
||||
bot2.velocity.x = 200;
|
||||
}
|
||||
else if (bot2.x > myGame.stage.width)
|
||||
{
|
||||
bot2.velocity.x = -200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
|
@ -10,6 +10,7 @@
|
|||
teddy = myGame.createSprite(0, 0, 'teddy');
|
||||
teddy.x = myGame.stage.centerX - teddy.width / 2;
|
||||
teddy.y = myGame.stage.centerY - teddy.height / 2;
|
||||
teddy.renderDebug = true;
|
||||
}
|
||||
function update() {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
teddy = myGame.createSprite(0, 0, 'teddy');
|
||||
teddy.x = myGame.stage.centerX - teddy.width / 2;
|
||||
teddy.y = myGame.stage.centerY - teddy.height / 2;
|
||||
teddy.renderDebug = true;
|
||||
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
1
build/phaser-092.min.js
vendored
Normal file
1
build/phaser-092.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue