2 Commits
20 changed files with 2011 additions and 1713 deletions
+31
View File
@@ -0,0 +1,31 @@
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-typescript');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
typescript: {
base: {
src: ['Phaser/**/*.ts'],
dest: 'build/phaser.js',
options: {
target: 'ES5'
}
}
},
copy: {
main: {
files: [
{src: 'build/phaser.js', dest: 'Tests/phaser.js'}
]}
},
watch: {
files: '**/*.ts',
tasks: ['typescript', 'copy']
}
});
grunt.registerTask('default', ['watch']);
}
+12 -2
View File
@@ -100,8 +100,18 @@ module Phaser {
if (this._anims[name]) if (this._anims[name])
{ {
this.currentAnim = this._anims[name]; if (this.currentAnim == this._anims[name])
this.currentAnim.play(frameRate, loop); {
if (this.currentAnim.isPlaying == false)
{
this.currentAnim.play(frameRate, loop);
}
}
else
{
this.currentAnim = this._anims[name];
this.currentAnim.play(frameRate, loop);
}
} }
} }
+13
View File
@@ -202,7 +202,20 @@ module Phaser {
if (this.onInitCallback !== null) if (this.onInitCallback !== null)
{ {
this.loader.reset();
this.onInitCallback.call(this.callbackContext); 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 else
{ {
+33 -26
View File
@@ -18,6 +18,7 @@ module Phaser {
this._keys = []; this._keys = [];
this._fileList = {}; this._fileList = {};
this._xhr = new XMLHttpRequest(); this._xhr = new XMLHttpRequest();
this._queueSize = 0;
} }
@@ -29,20 +30,18 @@ module Phaser {
private _onFileLoad; private _onFileLoad;
private _progressChunk: number; private _progressChunk: number;
private _xhr: XMLHttpRequest; private _xhr: XMLHttpRequest;
private _queueSize: number;
public hasLoaded: bool; public hasLoaded: bool;
public progress: number; public progress: number;
private checkKeyExists(key: string): bool { public reset() {
this._queueSize = 0;
}
if (this._fileList[key]) public get queueSize(): number {
{
return true; return this._queueSize;
}
else
{
return false;
}
} }
@@ -50,6 +49,7 @@ module Phaser {
if (this.checkKeyExists(key) === false) if (this.checkKeyExists(key) === false)
{ {
this._queueSize++;
this._fileList[key] = { type: 'image', key: key, url: url, data: null, error: false, loaded: false }; this._fileList[key] = { type: 'image', key: key, url: url, data: null, error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
@@ -60,6 +60,7 @@ module Phaser {
if (this.checkKeyExists(key) === false) 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._fileList[key] = { type: 'spritesheet', key: key, url: url, data: null, frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
@@ -68,15 +69,12 @@ module Phaser {
public addTextureAtlas(key: string, url: string, jsonURL?: string = null, jsonData? = null) { public addTextureAtlas(key: string, url: string, jsonURL?: string = null, jsonData? = null) {
//console.log('addTextureAtlas');
//console.log(typeof jsonData);
if (this.checkKeyExists(key) === false) if (this.checkKeyExists(key) === false)
{ {
if (jsonURL !== null) if (jsonURL !== null)
{ {
//console.log('A URL to a json file has been given');
// 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._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: jsonURL, jsonData: null, error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
@@ -85,24 +83,21 @@ module Phaser {
// A json string or object has been given // A json string or object has been given
if (typeof jsonData === 'string') if (typeof jsonData === 'string')
{ {
//console.log('A json string has been given');
var data = JSON.parse(jsonData); var data = JSON.parse(jsonData);
//console.log(data);
// Malformed? // Malformed?
if (data['frames']) 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._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: data['frames'], error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
} }
else else
{ {
//console.log('A json object has been given', jsonData);
// Malformed? // Malformed?
if (jsonData['frames']) 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._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: jsonData['frames'], error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
@@ -118,6 +113,7 @@ module Phaser {
if (this.checkKeyExists(key) === false) 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._fileList[key] = { type: 'audio', key: key, url: url, data: null, buffer: null, error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
@@ -128,6 +124,7 @@ module Phaser {
if (this.checkKeyExists(key) === false) if (this.checkKeyExists(key) === false)
{ {
this._queueSize++;
this._fileList[key] = { type: 'text', key: key, url: url, data: null, error: false, loaded: false }; this._fileList[key] = { type: 'text', key: key, url: url, data: null, error: false, loaded: false };
this._keys.push(key); this._keys.push(key);
} }
@@ -243,7 +240,6 @@ module Phaser {
break; break;
case 'textureatlas': case 'textureatlas':
//console.log('texture atlas loaded');
if (file.jsonURL == null) if (file.jsonURL == null)
{ {
this._game.cache.addTextureAtlas(file.key, file.url, file.data, file.jsonData); this._game.cache.addTextureAtlas(file.key, file.url, file.data, file.jsonData);
@@ -251,7 +247,6 @@ module Phaser {
else else
{ {
// Load the JSON before carrying on with the next file // Load the JSON before carrying on with the next file
//console.log('Loading the JSON before carrying on with the next file');
loadNext = false; loadNext = false;
this._xhr.open("GET", file.jsonURL, true); this._xhr.open("GET", file.jsonURL, true);
this._xhr.responseType = "text"; this._xhr.responseType = "text";
@@ -281,12 +276,8 @@ module Phaser {
private jsonLoadComplete(key: string) { private jsonLoadComplete(key: string) {
//console.log('json load complete');
var data = JSON.parse(this._xhr.response); var data = JSON.parse(this._xhr.response);
//console.log(data);
// Malformed? // Malformed?
if (data['frames']) if (data['frames'])
{ {
@@ -300,8 +291,6 @@ module Phaser {
private jsonLoadError(key: string) { private jsonLoadError(key: string) {
//console.log('json load error');
var file = this._fileList[key]; var file = this._fileList[key];
file.error = true; file.error = true;
this.nextFile(key, true); this.nextFile(key, true);
@@ -312,6 +301,11 @@ module Phaser {
this.progress = Math.round(this.progress + this._progressChunk); this.progress = Math.round(this.progress + this._progressChunk);
if (this.progress > 1)
{
this.progress = 1;
}
if (this._onFileLoad) if (this._onFileLoad)
{ {
this._onFileLoad.call(this._game.callbackContext, this.progress, previousKey, success); this._onFileLoad.call(this._game.callbackContext, this.progress, previousKey, success);
@@ -335,6 +329,19 @@ module Phaser {
} }
private checkKeyExists(key: string): bool {
if (this._fileList[key])
{
return true;
}
else
{
return false;
}
}
} }
} }
+2 -2
View File
@@ -1,7 +1,7 @@
/** /**
* Phaser * 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. * 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.1'; export var VERSION: string = 'Phaser version 0.9.2';
} }
+8
View File
@@ -520,6 +520,14 @@ module Phaser {
this._angle = this._game.math.wrap(value, 360, 0); this._angle = this._game.math.wrap(value, 360, 0);
} }
public set width(value:number) {
this.bounds.width = value;
}
public set height(value:number) {
this.bounds.height = value;
}
public get width(): number { public get width(): number {
return this.bounds.width; return this.bounds.width;
} }
+27 -20
View File
@@ -1,6 +1,7 @@
/// <reference path="../Game.ts" /> /// <reference path="../Game.ts" />
/// <reference path="../AnimationManager.ts" /> /// <reference path="../AnimationManager.ts" />
/// <reference path="GameObject.ts" /> /// <reference path="GameObject.ts" />
/// <reference path="../system/Camera.ts" />
/** /**
* Phaser - Sprite * Phaser - Sprite
@@ -51,6 +52,7 @@ module Phaser {
public renderDebug: bool = false; public renderDebug: bool = false;
public renderDebugColor: string = 'rgba(0,255,0,0.5)'; public renderDebugColor: string = 'rgba(0,255,0,0.5)';
public renderDebugPointColor: string = 'rgba(255,255,255,1)'; public renderDebugPointColor: string = 'rgba(255,255,255,1)';
public flipped: bool = false;
public loadGraphic(key: string): Sprite { public loadGraphic(key: string): Sprite {
@@ -125,7 +127,7 @@ module Phaser {
} }
public set frame(value?: number) { public set frame(value: number) {
this.animations.frame = value; this.animations.frame = value;
} }
@@ -133,7 +135,7 @@ module Phaser {
return this.animations.frame; return this.animations.frame;
} }
public set frameName(value?: string) { public set frameName(value: string) {
this.animations.frameName = value; this.animations.frameName = value;
} }
@@ -156,13 +158,6 @@ module Phaser {
this._game.stage.context.globalAlpha = this.alpha; 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._sx = 0;
this._sy = 0; this._sy = 0;
this._sw = this.bounds.width; this._sw = this.bounds.width;
@@ -228,15 +223,24 @@ module Phaser {
this._dy -= (camera.worldView.y * this.scrollFactor.y); this._dy -= (camera.worldView.y * this.scrollFactor.y);
} }
// Rotation // Rotation - needs to work from origin point really, but for now from center
if (this.angle !== 0) if (this.angle !== 0 || this.flipped == true)
{ {
this._game.stage.context.save(); 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.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._dx = -(this._dw / 2);
this._dy = -(this._dh / 2); this._dy = -(this._dh / 2);
if (this.flipped == true)
{
this._game.stage.context.scale(-1, 1);
}
} }
this._sx = Math.round(this._sx); this._sx = Math.round(this._sx);
@@ -285,16 +289,15 @@ module Phaser {
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh); this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
} }
if (this.renderDebug) if (this.flipped === true || this.rotation !== 0)
{ {
this.renderBounds(); //this._game.stage.context.translate(0, 0);
this._game.stage.context.restore();
} }
//if (this.flip === true || this.rotation !== 0) if (this.renderDebug)
if (this.rotation !== 0)
{ {
this._game.stage.context.translate(0, 0); this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
this._game.stage.context.restore();
} }
if (globalAlpha > -1) if (globalAlpha > -1)
@@ -306,7 +309,11 @@ module Phaser {
} }
private renderBounds() { // Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
private renderBounds(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) {
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
this._game.stage.context.fillStyle = this.renderDebugColor; this._game.stage.context.fillStyle = this.renderDebugColor;
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh); this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+2 -2
View File
@@ -1,7 +1,7 @@
/** /**
* Phaser * 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. * 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.1'; Phaser.VERSION = 'Phaser version 0.9.2';
})(Phaser || (Phaser = {})); })(Phaser || (Phaser = {}));
-2
View File
@@ -529,8 +529,6 @@ module Phaser {
this._game.stage.context.clip(); 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); this._game.world.group.render(this, this._sx, this._sy);
if (this.showBorder) if (this.showBorder)
+17 -4
View File
@@ -87,11 +87,16 @@ module Phaser {
} }
private onComplete() { public restart() {
this.isPlaying = false; this.isPlaying = true;
this.isFinished = true; this.isFinished = false;
// callback
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
}
} }
} }
+9 -2
View File
@@ -1,9 +1,9 @@
Phaser Phaser
====== ======
Version 0.9.1 Version 0.9.2
19th April 2013 20th April 2013
By Richard Davey, [Photon Storm](http://www.photonstorm.com) 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 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 V0.9.1
Added the new align property to GameObjects that controls placement when rendering.<br /> Added the new align property to GameObjects that controls placement when rendering.<br />
+4
View File
@@ -104,6 +104,10 @@
<Content Include="sprites\align.js"> <Content Include="sprites\align.js">
<DependentUpon>align.ts</DependentUpon> <DependentUpon>align.ts</DependentUpon>
</Content> </Content>
<TypeScriptCompile Include="sprites\flipped.ts" />
<Content Include="sprites\flipped.js">
<DependentUpon>flipped.ts</DependentUpon>
</Content>
<Content Include="tweens\bounce.js"> <Content Include="tweens\bounce.js">
<DependentUpon>bounce.ts</DependentUpon> <DependentUpon>bounce.ts</DependentUpon>
</Content> </Content>
+854 -818
View File
File diff suppressed because it is too large Load Diff
+36
View 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
View 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;
}
}
})();
+1
View File
@@ -10,6 +10,7 @@
teddy = myGame.createSprite(0, 0, 'teddy'); teddy = myGame.createSprite(0, 0, 'teddy');
teddy.x = myGame.stage.centerX - teddy.width / 2; teddy.x = myGame.stage.centerX - teddy.width / 2;
teddy.y = myGame.stage.centerY - teddy.height / 2; teddy.y = myGame.stage.centerY - teddy.height / 2;
teddy.renderDebug = true;
} }
function update() { function update() {
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
+1
View File
@@ -19,6 +19,7 @@
teddy = myGame.createSprite(0, 0, 'teddy'); teddy = myGame.createSprite(0, 0, 'teddy');
teddy.x = myGame.stage.centerX - teddy.width / 2; teddy.x = myGame.stage.centerX - teddy.width / 2;
teddy.y = myGame.stage.centerY - teddy.height / 2; teddy.y = myGame.stage.centerY - teddy.height / 2;
teddy.renderDebug = true;
} }
File diff suppressed because it is too large Load Diff
+1
View File
File diff suppressed because one or more lines are too long
+32
View File
@@ -0,0 +1,32 @@
{
"name": "Phaser",
"version": "0.9.1",
"description": "html5 game framework",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://photonstorm@github.com/photonstorm/phaser.git"
},
"keywords": [
"HTML5",
"game",
"canvas",
"2d"
],
"author": "Richard Davey",
"license": "BSD",
"readmeFilename": "README.md",
"gitHead": "1217bf4722768514fe15ff904dab59f848d146f4",
"devDependencies": {
"grunt": "~0.4.1",
"typescript": "~0.8.3",
"grunt-typescript": "~0.1.4",
"grunt-contrib-watch": "~0.3.1",
"grunt-contrib-connect": "~0.3.0",
"grunt-open": "~0.2.0",
"grunt-contrib-copy": "~0.4.1"
}
}