Fixed a fantastic FrameData bug. Also added support to the Emitter to handle multiple image keys and/or frames.

This commit is contained in:
Richard Davey 2013-09-10 11:09:25 +01:00
parent 5d3fe891cd
commit 4f950ae801
10 changed files with 703 additions and 281 deletions

View file

@ -3,6 +3,46 @@
{
"selected_items":
[
[
"em",
"emitY (variable)"
],
[
"emit",
"emitX (variable)"
],
[
"int",
"integerInRange"
],
[
"max",
"maxParticleSpeed"
],
[
"k",
"kill"
],
[
"pointerlo",
"pointerLockChange"
],
[
"proto",
"prototype"
],
[
"inw",
"inWorld"
],
[
"inwo",
"inWorldThreshold"
],
[
"update",
"updateBounds"
],
[
"call",
"callbackContext (argument)"
@ -163,10 +203,6 @@
"bo",
"bottom"
],
[
"max",
"maxLevels (variable)"
],
[
"al",
"allowGravity"
@ -478,68 +514,49 @@
[
"prop",
"properties"
],
[
"the",
"the_terms"
],
[
"load",
"loadPuzzleRatings"
],
[
"tr",
"true"
],
[
"font-",
"font-family"
],
[
"sca",
"scaling"
],
[
"Pos",
"Position"
],
[
"Po",
"Position"
],
[
"to",
"toString"
],
[
"phas",
"phaserSpace"
]
]
},
"buffers":
[
{
"file": "src/gameobjects/Button.js",
"file": "src/particles/arcade/Emitter.js",
"settings":
{
"buffer_size": 4621,
"buffer_size": 12517,
"line_ending": "Windows",
"name": "/**"
}
},
{
"file": "examples/particles.php",
"settings":
{
"buffer_size": 1457,
"line_ending": "Windows"
}
},
{
"file": "src/gameobjects/GameObjectFactory.js",
"file": "src/core/Game.js",
"settings":
{
"buffer_size": 2971,
"buffer_size": 9096,
"line_ending": "Windows"
}
},
{
"file": "examples/button1.php",
"file": "src/gameobjects/Sprite.js",
"settings":
{
"buffer_size": 1548,
"buffer_size": 16356,
"line_ending": "Windows"
}
},
{
"file": "src/physics/arcade/Body.js",
"settings":
{
"buffer_size": 7207,
"line_ending": "Windows"
}
}
@ -572,21 +589,40 @@
},
"file_history":
[
"/D/wamp/www/phaser/src/core/Group.js",
"/D/wamp/www/phaser/src/particles/Particles.js",
"/D/wamp/www/phaser/src/gameobjects/Sprite.js",
"/D/wamp/www/phaser/src/physics/arcade/Body.js",
"/D/wamp/www/phaser/src/math/RandomDataGenerator.js",
"/D/wamp/www/phaser/src/core/World.js",
"/D/wamp/www/phaser/src/gameobjects/RenderTexture.js",
"/D/wamp/www/phaser/examples/js.php",
"/D/wamp/www/phaser/src/particles/arcade/ArcadeParticles.js",
"/D/wamp/www/phaser/examples/rendertexture.php",
"/D/wamp/www/pixi.js/examples/example 11 - RenderTexture/index.html",
"/D/wamp/www/phaser/src/gameobjects/Graphics.js",
"/D/wamp/www/phaser/src/pixi/textures/RenderTexture.js",
"/D/wamp/www/phaser/src/input/Mouse.js",
"/D/wamp/www/phaser/src/system/Device.js",
"/D/wamp/www/phaser/src/pixi/primitives/Graphics.js",
"/D/wamp/www/phaser/examples/graphics.php",
"/D/wamp/www/phaser/src/gameobjects/GameObjectFactory.js",
"/D/wamp/www/pixi.js/examples/example 13 - Graphics/index.html",
"/D/wamp/www/phaser/src/tween/TweenManager.js",
"/D/wamp/www/phaser/src/gameobjects/Button.js",
"/D/wamp/www/phaser/examples/button1.php",
"/D/wamp/www/phaser/examples/outofbounds.php",
"/D/wamp/www/phaser/TS Tests/buttons/basic button.ts",
"/D/wamp/www/phaser/TS Source/gameobjects/GameObjectFactory.js",
"/D/wamp/www/phaser/examples/js.php",
"/D/wamp/www/phaser/src/gameobjects/TileSprite.js",
"/D/wamp/www/phaser/TS Source/ui/Button.js",
"/D/wamp/www/phaser/src/input/InputHandler.js",
"/D/wamp/www/phaser/src/gameobjects/Sprite.js",
"/D/wamp/www/phaser/src/Phaser.js",
"/D/wamp/www/phaser/build/build.php",
"/D/wamp/www/phaser/src/Intro.js",
"/D/wamp/www/phaser/build/phaser.js",
"/D/wamp/www/phaser/src/input/Input.js",
"/D/wamp/www/phaser/src/input/Pointer.js",
"/D/wamp/www/phaser/src/core/World.js",
"/D/wamp/www/phaser/src/core/Group.js",
"/D/wamp/www/phaser/examples/js-physics.php",
"/D/wamp/www/phaser/src/utils/Utils.js",
"/D/wamp/www/phaser/src/pixi/utils/Utils.js",
@ -607,7 +643,6 @@
"/D/wamp/www/phaser/src/pixi/display/DisplayObjectContainer.js",
"/D/wamp/www/phaser/src/pixi/display/DisplayObject.js",
"/D/wamp/www/phaser/src/pixi/text/BitmapText.js",
"/D/wamp/www/phaser/src/physics/arcade/Body.js",
"/D/wamp/www/phaser/src/core/Game.js",
"/D/wamp/www/phaser/examples/quadtree2.php",
"/D/wamp/www/phaser/examples/body3.php",
@ -617,7 +652,6 @@
"/D/wamp/www/phaser/examples/anchor1.php",
"/D/wamp/www/phaser/src/physics/arcade/ArcadePhysics.js",
"/D/wamp/www/phaser/src/geom/Rectangle.js",
"/D/wamp/www/phaser/src/gameobjects/GameObjectFactory.js",
"/D/wamp/www/phaser/src/tween/Tween.js",
"/D/wamp/www/phaser/TS Source/core/Group.ts",
"/D/wamp/www/phaser/TS Source/core/Group.js",
@ -682,24 +716,7 @@
"/D/wamp/www/phaser/TS Source/gameobjects/GameObjectFactory.ts",
"/D/wamp/www/phaser/TS Source/sound/Sound.js",
"/D/wamp/www/phaser/src/sound/Sound.js",
"/D/wamp/www/phaser/TS Source/sound/Sound.ts",
"/D/wamp/www/phaser/TS Source/sound/SoundManager.js",
"/D/wamp/www/phaser/TS Source/math/QuadTree.js",
"/D/wamp/www/phaser/examples/camera_cull1.php",
"/D/wamp/www/bbc-wolfblood/assets/1024/help/help_titles.json",
"/D/wamp/www/phaser/src/math/LinkedList.js",
"/D/wamp/www/phaser/TS Source/math/LinkedList.js",
"/D/wamp/www/phaser/src/animation/Parser.js",
"/D/wamp/www/phaser/examples/camera4.php",
"/D/wamp/www/phaser/examples/sprite3.php",
"/D/wamp/www/phaser/examples/camera5.php",
"/D/wamp/www/pixi.js/examples/example 6 - Interactivity/index.html",
"/D/wamp/www/phaser/src/math/Math.js",
"/D/wamp/www/phaser/src/geom/Point.js",
"/D/wamp/www/phaser/TS Source/gameobjects/TransformManager.ts",
"/D/wamp/www/phaser/TS Source/utils/SpriteUtils.ts",
"/D/wamp/www/phaser/TS Source/utils/SpriteUtils.js",
"/D/wamp/www/phaser/src/core/Camera.js"
"/D/wamp/www/phaser/TS Source/sound/Sound.ts"
],
"find":
{
@ -707,7 +724,7 @@
},
"find_in_files":
{
"height": 90.0,
"height": 0.0,
"where_history":
[
"D:\\wamp\\www\\phaser\\src\\pixi",
@ -738,6 +755,23 @@
"case_sensitive": true,
"find_history":
[
"star2",
"reset",
"this.maxSize",
"Phaser.Physics.Arcade.Body",
"integer",
"x",
"reset",
"false",
": number",
"TileSprite",
"Vec2",
"Graphics",
", false",
"add",
"Phaser.Sprite",
"TileSprite",
"reset",
"this.",
"transform.origin",
"TileSprite",
@ -848,24 +882,7 @@
"this.obj1Bounds",
"obj2Bounds",
"obj1Bounds",
"Phaser.Physics.Arcade.prototype",
"Collision",
"object1",
"this._oy",
"this._ox",
"this._y",
"this._x",
"Collision",
"Phaser.Collision",
"Collision.",
": number",
"this.oldPosition.y",
"this.position.y",
"this.oldPosition.x",
"this.position.x",
"position.x",
"Position.x",
"position.x"
"Phaser.Physics.Arcade.prototype"
],
"highlight": true,
"in_selection": false,
@ -873,6 +890,7 @@
"regex": false,
"replace_history":
[
"",
"sprite",
"if (",
"sprite",
@ -973,27 +991,28 @@
"groups":
[
{
"selected": 2,
"selected": 1,
"sheets":
[
{
"buffer": 0,
"file": "src/gameobjects/Button.js",
"file": "src/particles/arcade/Emitter.js",
"settings":
{
"buffer_size": 4621,
"buffer_size": 12517,
"regions":
{
},
"selection":
[
[
2537,
2537
8938,
8938
]
],
"settings":
{
"auto_name": "/**",
"codeintel": true,
"codeintel_config":
{
@ -1100,156 +1119,25 @@
"syntax": "Packages/JavaScript/JavaScript.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 1188.0,
"translation.y": 5852.0,
"zoom_level": 1.0
},
"type": "text"
},
{
"buffer": 1,
"file": "src/gameobjects/GameObjectFactory.js",
"file": "examples/particles.php",
"settings":
{
"buffer_size": 2971,
"buffer_size": 1457,
"regions":
{
},
"selection":
[
[
2960,
2960
]
],
"settings":
{
"codeintel": true,
"codeintel_config":
{
"JavaScript":
{
"codeintel_max_recursive_dir_depth": 2,
"codeintel_scan_files_in_project": false,
"javascriptExtraPaths":
[
]
},
"PHP":
{
"codeintel_max_recursive_dir_depth": 5,
"codeintel_scan_files_in_project": false,
"phpExtraPaths":
[
]
},
"Python":
{
"env":
{
}
}
},
"codeintel_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_live": true,
"codeintel_live_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_max_recursive_dir_depth": 10,
"codeintel_scan_exclude_dir":
{
"JavaScript":
[
"/build/",
"/min/"
]
},
"codeintel_scan_files_in_project": true,
"codeintel_selected_catalogs":
[
"PyWin32",
"jQuery",
"Rails"
],
"codeintel_snippets": true,
"codeintel_syntax_map":
{
"Python Django": "Python"
},
"sublime_auto_complete": true,
"syntax": "Packages/JavaScript/JavaScript.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 758.0,
"zoom_level": 1.0
},
"type": "text"
},
{
"buffer": 2,
"file": "examples/button1.php",
"settings":
{
"buffer_size": 1548,
"regions":
{
},
"selection":
[
[
510,
510
353,
353
]
],
"settings":
@ -1362,7 +1250,396 @@
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 328.0,
"translation.y": 166.0,
"zoom_level": 1.0
},
"type": "text"
},
{
"buffer": 2,
"file": "src/core/Game.js",
"settings":
{
"buffer_size": 9096,
"regions":
{
},
"selection":
[
[
5074,
5074
]
],
"settings":
{
"codeintel": true,
"codeintel_config":
{
"JavaScript":
{
"codeintel_max_recursive_dir_depth": 2,
"codeintel_scan_files_in_project": false,
"javascriptExtraPaths":
[
]
},
"PHP":
{
"codeintel_max_recursive_dir_depth": 5,
"codeintel_scan_files_in_project": false,
"phpExtraPaths":
[
]
},
"Python":
{
"env":
{
}
}
},
"codeintel_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_live": true,
"codeintel_live_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_max_recursive_dir_depth": 10,
"codeintel_scan_exclude_dir":
{
"JavaScript":
[
"/build/",
"/min/"
]
},
"codeintel_scan_files_in_project": true,
"codeintel_selected_catalogs":
[
"PyWin32",
"jQuery",
"Rails"
],
"codeintel_snippets": true,
"codeintel_syntax_map":
{
"Python Django": "Python"
},
"sublime_auto_complete": true,
"syntax": "Packages/JavaScript/JavaScript.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 3962.0,
"zoom_level": 1.0
},
"type": "text"
},
{
"buffer": 3,
"file": "src/gameobjects/Sprite.js",
"settings":
{
"buffer_size": 16356,
"regions":
{
},
"selection":
[
[
10652,
10652
]
],
"settings":
{
"codeintel": true,
"codeintel_config":
{
"JavaScript":
{
"codeintel_max_recursive_dir_depth": 2,
"codeintel_scan_files_in_project": false,
"javascriptExtraPaths":
[
]
},
"PHP":
{
"codeintel_max_recursive_dir_depth": 5,
"codeintel_scan_files_in_project": false,
"phpExtraPaths":
[
]
},
"Python":
{
"env":
{
}
}
},
"codeintel_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_live": true,
"codeintel_live_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_max_recursive_dir_depth": 10,
"codeintel_scan_exclude_dir":
{
"JavaScript":
[
"/build/",
"/min/"
]
},
"codeintel_scan_files_in_project": true,
"codeintel_selected_catalogs":
[
"PyWin32",
"jQuery",
"Rails"
],
"codeintel_snippets": true,
"codeintel_syntax_map":
{
"Python Django": "Python"
},
"sublime_auto_complete": true,
"syntax": "Packages/JavaScript/JavaScript.tmLanguage",
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"translation.x": 0.0,
"translation.y": 5193.0,
"zoom_level": 1.0
},
"type": "text"
},
{
"buffer": 4,
"file": "src/physics/arcade/Body.js",
"settings":
{
"buffer_size": 7207,
"regions":
{
},
"selection":
[
[
4775,
4775
]
],
"settings":
{
"codeintel": true,
"codeintel_config":
{
"JavaScript":
{
"codeintel_max_recursive_dir_depth": 2,
"codeintel_scan_files_in_project": false,
"javascriptExtraPaths":
[
]
},
"PHP":
{
"codeintel_max_recursive_dir_depth": 5,
"codeintel_scan_files_in_project": false,
"phpExtraPaths":
[
]
},
"Python":
{
"env":
{
}
}
},
"codeintel_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_live": true,
"codeintel_live_enabled_languages":
[
"JavaScript",
"Mason",
"XBL",
"XUL",
"RHTML",
"SCSS",
"Python",
"HTML",
"Ruby",
"Python3",
"XML",
"Sass",
"XSLT",
"Django",
"HTML5",
"Perl",
"CSS",
"Twig",
"Less",
"Smarty",
"Node.js",
"Tcl",
"TemplateToolkit",
"PHP"
],
"codeintel_max_recursive_dir_depth": 10,
"codeintel_scan_exclude_dir":
{
"JavaScript":
[
"/build/",
"/min/"
]
},
"codeintel_scan_files_in_project": true,
"codeintel_selected_catalogs":
[
"PyWin32",
"jQuery",
"Rails"
],
"codeintel_snippets": true,
"codeintel_syntax_map":
{
"Python Django": "Python"
},
"sublime_auto_complete": true,
"syntax": "Packages/JavaScript/JavaScript.tmLanguage"
},
"translation.x": 0.0,
"translation.y": 2666.0,
"zoom_level": 1.0
},
"type": "text"

View file

@ -15,6 +15,7 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
var p;
var p2;
function preload() {
@ -23,21 +24,27 @@
game.load.image('diamond', 'assets/sprites/diamond.png');
game.load.image('dude', 'assets/sprites/phaser-dude.png');
game.load.image('coke', 'assets/sprites/cokecan.png');
game.load.atlasJSONHash('pixies', 'assets/sprites/pixi_monsters.png', 'assets/sprites/pixi_monsters.json');
game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);
}
function create() {
p = new Phaser.Particles.Arcade.Emitter(game, 200, 100, 500);
game.stage.backgroundColor = 0x337799;
p = game.add.emitter(200, 100, 50);
// p.width = 200;
// p.height = 200;
p.makeParticles('diamond');
// keys, frames, quantity, collide
// p.makeParticles(['diamond', 'carrot', 'star']);
p.makeParticles('balls', [0,1,2,3,4,5]);
// p.makeParticles('pixies', [0,1,2,3]);
// Steady constant stream at 250ms delay and 10 seconds lifespan
// p.start(false, 10000, 250, 100);
// p.start(true, 10000);
// explode, lifespan, frequency, quantity
@ -51,9 +58,6 @@
}
function update() {
p.update();
}
function render() {

View file

@ -9,6 +9,10 @@
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
*/
Phaser.Animation.FrameData = function () {
this._frames = [];
this._frameNames = [];
};
Phaser.Animation.FrameData.prototype = {

View file

@ -23,7 +23,8 @@ Phaser.Animation.Parser = {
// How big is our image?
var img = game.cache.getImage(key);
if (img == null) {
if (img == null)
{
return null;
}
@ -33,13 +34,15 @@ Phaser.Animation.Parser = {
var column = Math.round(height / frameHeight);
var total = row * column;
if (frameMax !== -1) {
if (frameMax !== -1)
{
total = frameMax;
}
// Zero or smaller than frame sizes?
if (width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
if (width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0)
{
console.warn("Phaser.Animation.Parser.spriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
return null;
}
@ -82,9 +85,11 @@ Phaser.Animation.Parser = {
JSONData: function (game, json, cacheKey) {
// Malformed?
if (!json['frames']) {
if (!json['frames'])
{
console.warn("Phaser.Animation.Parser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
console.log(json);
throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
return;
}
// Let's create some frames then
@ -143,14 +148,16 @@ Phaser.Animation.Parser = {
JSONDataHash: function (game, json, cacheKey) {
// Malformed?
if (!json['frames']) {
if (!json['frames'])
{
console.warn("Phaser.Animation.Parser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
console.log(json);
throw new Error("Phaser.AnimationLoader.parseJSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
return;
}
// Let's create some frames then
var data = new Phaser.Animation.FrameData();
// By this stage frames is a fully parsed array
var frames = json['frames'];
var newFrame;
@ -204,8 +211,10 @@ Phaser.Animation.Parser = {
XMLData: function (game, xml, cacheKey) {
// Malformed?
if (!xml.getElementsByTagName('TextureAtlas')) {
throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing <TextureAtlas> tag");
if (!xml.getElementsByTagName('TextureAtlas'))
{
console.warn("Phaser.Animation.Parser.XMLData: Invalid Texture Atlas XML given, missing <TextureAtlas> tag");
return;
}
// Let's create some frames then

View file

@ -305,6 +305,7 @@ Phaser.Game.prototype = {
this.input = new Phaser.Input(this);
this.sound = new Phaser.SoundManager(this);
this.physics = new Phaser.Physics.Arcade(this);
this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this);
@ -391,6 +392,7 @@ Phaser.Game.prototype = {
this.tweens.update();
this.sound.update();
this.world.update();
this.particles.update();
this.state.update();
this.plugins.update();

View file

@ -91,4 +91,10 @@ Phaser.GameObjectFactory.prototype = {
},
emitter: function (x, y, maxParticles) {
return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
},
};

View file

@ -23,16 +23,13 @@ Phaser.Sprite = function (game, x, y, key, frame) {
// The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
this.lifespan = 0;
if (key)
if (key == null || this.game.cache.checkImageKey(key) == false)
{
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
}
else
{
// No texture yet
PIXI.Sprite.call(this);
key = '__default';
}
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
this.events = new Phaser.Events(this);
/**

View file

@ -10,7 +10,15 @@
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
*/
Phaser.Cache = function (game) {
this.game = game;
this._canvases = {};
this._images = {};
this._sounds = {};
this._text = {};
this.addDefaultImage();
};
Phaser.Cache.prototype = {
@ -106,6 +114,25 @@ Phaser.Cache.prototype = {
},
/**
* Adds a default image to be used when a key is wrong / missing.
* Is mapped to the key __default
*/
addDefaultImage: function () {
this._images['__default'] = { url: null, data: null, spriteSheet: false };
this._images['__default'].frame = new Phaser.Animation.Frame(0, 0, 32, 32, '', '');
var base = new PIXI.BaseTexture();
base.width = 32;
base.height = 32;
base.hasLoaded = true; // avoids a hanging event listener
PIXI.BaseTextureCache['__default'] = base;
PIXI.TextureCache['__default'] = new PIXI.Texture(base);
},
/**
* Add a new image.
* @param key {string} Asset key for the image.
@ -219,6 +246,22 @@ Phaser.Cache.prototype = {
return null;
},
/**
* Checks if an image key exists.
* @param key Asset key of the image you want.
* @return {boolean} True if the key exists, otherwise false.
*/
checkImageKey: function (key) {
if (this._images[key])
{
return true;
}
return false;
},
/**
* Get image data by key.
* @param key Asset key of the image you want.

View file

@ -1 +1,39 @@
Phaser.Particles = {}
Phaser.Particles = function (game) {
this.emitters = {};
this.ID = 0;
};
Phaser.Particles.prototype = {
emitters: null,
add: function (emitter) {
this.emitters[emitter.name] = emitter;
return emitter;
},
remove: function (emitter) {
delete this.emitters[emitter.name];
},
update: function () {
for (var key in this.emitters)
{
if (this.emitters[key].exists)
{
this.emitters[key].update();
}
}
},
};

View file

@ -12,6 +12,8 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
Phaser.Group.call(this, game);
this.name = 'emitter' + this.game.particles.ID++;
/**
* The X position of the top left corner of the emitter in world space.
*/
@ -119,12 +121,16 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
*/
this.on = false;
/**
* Determines whether the emitter is being updated by the core game loop.
*/
this.exists = true;
this.active = true;
// Needs to be a setter/getter and toggle the _container property
this.visible = true;
// The point the particles are emitted from (Emitter.x/y control the container location, i.e. all particles, this controls position within it)
/**
* The point the particles are emitted from.
* Emitter.x and Emitter.y control the containers location, which updates all current particles
* Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
*/
this.emitX = 0;
this.emitY = 0;
@ -186,42 +192,42 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
*
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
*/
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (key, quantity, multiple, collide) {
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide) {
if (typeof frames == 'undefined')
{
frames = 0;
}
quantity = quantity || this.maxParticles;
multiple = multiple || false;
collide = collide || 0;
var totalFrames = 1;
var randomFrame;
var particle;
var i = 0;
var rndKey = keys;
var rndFrame = 0;
while (i < quantity)
{
if (this.particleClass == null)
{
particle = new Phaser.Sprite(this.game, 0, 0, key);
if (typeof keys == 'object')
{
rndKey = this.game.rnd.pick(keys);
}
if (typeof frames == 'object')
{
rndFrame = this.game.rnd.pick(frames);
}
particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame);
}
else
{
// particle = new this.particleClass(this.game);
}
if (multiple)
{
/*
randomFrame = this.game.math.random()*totalFrames;
*/
}
else
{
// if (graphics)
// {
// particle.texture.loadImage(graphics);
// }
}
if (collide > 0)
{
particle.body.allowCollision.any = true;
@ -433,11 +439,47 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
*/
Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
//this.x = object.body.bounds.halfWidth - (this.width >> 1);
//this.y = object.body.bounds.halfHeight - (this.height >> 1);
this.emitX = object.center.x;
this.emitY = object.center.y;
}
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "alpha", {
/**
* Get the emitter alpha.
*/
get: function () {
return this._container.alpha;
},
/**
* Set the emiter alpha value.
*/
set: function (value) {
this._container.alpha = value;
}
});
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "visible", {
/**
* Get the emitter visible state.
*/
get: function () {
return this._container.visible;
},
/**
* Set the emitter visible state.
*/
set: function (value) {
this._container.visible = value;
}
});
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
get: function () {