Added Matching Pairs game and updated fixed to camera example.

This commit is contained in:
photonstorm
2013-12-16 15:16:44 +00:00
parent 39cae4cc09
commit 7917eac255
8 changed files with 322 additions and 45 deletions
+5 -5
View File
@@ -30,8 +30,8 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
parent = parent || '';
state = state || null;
if (typeof transparent == 'undefined') { transparent = false; }
if (typeof antialias == 'undefined') { antialias = true; }
if (typeof transparent === 'undefined') { transparent = false; }
if (typeof antialias === 'undefined') { antialias = true; }
/**
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
@@ -43,8 +43,6 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
*/
this.parent = parent;
// Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too?
/**
* @property {number} width - The Game width (in pixels).
*/
@@ -372,11 +370,13 @@ Phaser.Game.prototype = {
*/
setUpRenderer: function () {
/*
if (this.device.trident)
{
// Until Pixi works with IE11
// Pixi WebGL renderer on IE11 doesn't work correctly with masks, if you need them you may want to comment this block out
this.renderType = Phaser.CANVAS;
}
*/
if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
{
+4 -3
View File
@@ -1044,12 +1044,13 @@ Phaser.Group.prototype = {
* @param {number} returnType - How to return the data from this method. Either Phaser.Group.RETURN_NONE, Phaser.Group.RETURN_TOTAL or Phaser.Group.RETURN_CHILD.
* @param {function} [callback=null] - Optional function that will be called on each matching child. Each child of the Group will be passed to it as its first parameter.
* @param {Object} [callbackContext] - The context in which the function should be called (usually 'this').
* @return {any} Returns either a numeric total (if RETURN_TOTAL was specified) or the child object.
*/
iterate: function (key, value, returnType, callback, callbackContext, args) {
if (returnType === Phaser.Group.RETURN_TOTAL && this._container.children.length === 0)
{
return -1;
return 0;
}
if (typeof callback === 'undefined')
@@ -1145,7 +1146,7 @@ Phaser.Group.prototype = {
* Call this function to find out how many members of the group are alive.
*
* @method Phaser.Group#countLiving
* @return {number} The number of children flagged as alive. Returns -1 if Group is empty.
* @return {number} The number of children flagged as alive.
*/
countLiving: function () {
@@ -1157,7 +1158,7 @@ Phaser.Group.prototype = {
* Call this function to find out how many members of the group are dead.
*
* @method Phaser.Group#countDead
* @return {number} The number of children flagged as dead. Returns -1 if Group is empty.
* @return {number} The number of children flagged as dead.
*/
countDead: function () {
+35 -13
View File
@@ -47,15 +47,19 @@ Phaser.GameObjectFactory.prototype = {
* @param {number} y - Y position of the new sprite.
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @returns {Phaser.Sprite} the newly created sprite object.
*/
sprite: function (x, y, key, frame) {
sprite: function (x, y, key, frame, group) {
return this.world.create(x, y, key, frame);
if (typeof group === 'undefined') { group = this.world; }
return group.create(x, y, key, frame);
},
/**
* DEPRECATED - will be removed in Phaser 1.2
* Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
*
* @method Phaser.GameObjectFactory#child
@@ -125,11 +129,14 @@ Phaser.GameObjectFactory.prototype = {
* @param {number} height - the height of the tilesprite.
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
* @param {string|number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.TileSprite} The newly created tileSprite object.
*/
tileSprite: function (x, y, width, height, key, frame) {
tileSprite: function (x, y, width, height, key, frame, group) {
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
if (typeof group === 'undefined') { group = this.world; }
return group.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
},
@@ -141,11 +148,14 @@ Phaser.GameObjectFactory.prototype = {
* @param {number} y - Y position of the new text object.
* @param {string} text - The actual text that will be written.
* @param {object} style - The style object containing style attributes like font, font size , etc.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Text} The newly created text object.
*/
text: function (x, y, text, style) {
text: function (x, y, text, style, group) {
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
if (typeof group === 'undefined') { group = this.world; }
return group.add(new Phaser.Text(this.game, x, y, text, style));
},
@@ -161,11 +171,14 @@ Phaser.GameObjectFactory.prototype = {
* @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
* @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
* @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Button} The newly created button object.
*/
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, group) {
return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
if (typeof group === 'undefined') { group = this.world; }
return group.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
},
@@ -175,11 +188,14 @@ Phaser.GameObjectFactory.prototype = {
* @method Phaser.GameObjectFactory#graphics
* @param {number} x - X position of the new graphics object.
* @param {number} y - Y position of the new graphics object.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Graphics} The newly created graphics object.
*/
graphics: function (x, y) {
graphics: function (x, y, group) {
return this.world.add(new Phaser.Graphics(this.game, x, y));
if (typeof group === 'undefined') { group = this.world; }
return group.add(new Phaser.Graphics(this.game, x, y));
},
@@ -208,9 +224,12 @@ Phaser.GameObjectFactory.prototype = {
* @param {number} y - Y position of the new bitmapText object.
* @param {string} text - The actual text that will be written.
* @param {object} style - The style object containing style attributes like font, font size , etc.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.BitmapText} The newly created bitmapText object.
*/
bitmapText: function (x, y, text, style) {
bitmapText: function (x, y, text, style, group) {
if (typeof group === 'undefined') { group = this.world; }
return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style));
@@ -250,11 +269,14 @@ Phaser.GameObjectFactory.prototype = {
* @param {number} y - Y position of the new tilemapLayer.
* @param {number} width - the width of the tilemapLayer.
* @param {number} height - the height of the tilemapLayer.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.TilemapLayer} The newly created tilemaplayer object.
*/
tilemapLayer: function (x, y, width, height, tileset, tilemap, layer) {
tilemapLayer: function (x, y, width, height, tileset, tilemap, layer, group) {
return this.world.add(new Phaser.TilemapLayer(this.game, x, y, width, height, tileset, tilemap, layer));
if (typeof group === 'undefined') { group = this.world; }
return group.add(new Phaser.TilemapLayer(this.game, x, y, width, height, tileset, tilemap, layer));
},
+18
View File
@@ -90,6 +90,18 @@ Phaser.Text = function (game, x, y, text, style) {
*/
this.scale = new Phaser.Point(1, 1);
/**
* An object that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
* @property {boolean} fixedToCamera - Fixes this object to the Camera.
* @default
*/
this.fixedToCamera = false;
/**
* @property {Phaser.Point} cameraOffset - If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
*/
this.cameraOffset = new Phaser.Point();
/**
* @property {object} _cache - A mini cache for storing all of the calculated values.
* @private
@@ -141,6 +153,12 @@ Phaser.Text.prototype.update = function() {
return;
}
if (this.fixedToCamera)
{
this.x = this.game.camera.view.x + this.cameraOffset.x;
this.y = this.game.camera.view.y + this.cameraOffset.y;
}
this._cache.dirty = false;
this._cache.x = this.x;