mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
This commit is contained in:
@@ -78,6 +78,7 @@ Updates:
|
||||
* Most of the GameObjectFactory functions now have a group parameter, so you can do: game.add.sprite(x, y, frame, frameName, group) rather than defaulting to the World group.
|
||||
* Group.countLiving and countDead used to return -1 if the Group was empty, but now return 0.
|
||||
* Text can now be fixedToCamera, updated world/fixed to camera example to show this.
|
||||
* ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
|
||||
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
@@ -216,6 +216,10 @@
|
||||
"file": "invaders.js",
|
||||
"title": "invaders"
|
||||
},
|
||||
{
|
||||
"file": "matching+pairs.js",
|
||||
"title": "matching pairs"
|
||||
},
|
||||
{
|
||||
"file": "starstruck.js",
|
||||
"title": "starstruck"
|
||||
@@ -514,6 +518,22 @@
|
||||
"file": "angular+velocity.js",
|
||||
"title": "angular velocity"
|
||||
},
|
||||
{
|
||||
"file": "bounce+accelerator.js",
|
||||
"title": "bounce accelerator"
|
||||
},
|
||||
{
|
||||
"file": "bounce+knock.js",
|
||||
"title": "bounce knock"
|
||||
},
|
||||
{
|
||||
"file": "bounce+with+gravity.js",
|
||||
"title": "bounce with gravity"
|
||||
},
|
||||
{
|
||||
"file": "bounce.js",
|
||||
"title": "bounce"
|
||||
},
|
||||
{
|
||||
"file": "mass+velocity+test.js",
|
||||
"title": "mass velocity test"
|
||||
@@ -538,6 +558,10 @@
|
||||
"file": "shoot+the+pointer.js",
|
||||
"title": "shoot the pointer"
|
||||
},
|
||||
{
|
||||
"file": "snake.js",
|
||||
"title": "snake"
|
||||
},
|
||||
{
|
||||
"file": "sprite+bounds.js",
|
||||
"title": "sprite bounds"
|
||||
@@ -636,6 +660,10 @@
|
||||
"file": "animated+tiling+sprite.js",
|
||||
"title": "animated tiling sprite"
|
||||
},
|
||||
{
|
||||
"file": "colliding+with+tiling+sprite.js",
|
||||
"title": "colliding with tiling sprite"
|
||||
},
|
||||
{
|
||||
"file": "tiling+sprite.js",
|
||||
"title": "tiling sprite"
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 148 KiB |
@@ -35,7 +35,6 @@ function create() {
|
||||
// The scrolling starfield background
|
||||
starfield = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
||||
|
||||
|
||||
// Our bullet group
|
||||
bullets = game.add.group();
|
||||
bullets.createMultiple(30, 'bullet');
|
||||
|
||||
@@ -5,39 +5,44 @@ function preload() {
|
||||
game.load.image('disk', 'assets/sprites/p2.jpeg');
|
||||
}
|
||||
|
||||
var s;
|
||||
var tilesprite;
|
||||
var cursors;
|
||||
var count = 0;
|
||||
|
||||
function create() {
|
||||
s = game.add.tileSprite(0, 0, 512, 512, 'disk');
|
||||
|
||||
tilesprite = game.add.tileSprite(0, 0, 512, 512, 'disk');
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
count += 0.005
|
||||
|
||||
s.tileScale.x = 2 + Math.sin(count);
|
||||
s.tileScale.y = 2 + Math.cos(count);
|
||||
tilesprite.tileScale.x = 2 + Math.sin(count);
|
||||
tilesprite.tileScale.y = 2 + Math.cos(count);
|
||||
|
||||
s.tilePosition.x += 1;
|
||||
s.tilePosition.y += 1;
|
||||
tilesprite.tilePosition.x += 1;
|
||||
tilesprite.tilePosition.y += 1;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
s.x -= 4;
|
||||
tilesprite.x -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
s.x += 4;
|
||||
tilesprite.x += 4;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
s.y -= 4;
|
||||
tilesprite.y -= 4;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
s.y += 4;
|
||||
tilesprite.y += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
var ball;
|
||||
var tilesprite;
|
||||
var cursors;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
||||
game.load.image('ball', 'assets/sprites/pangball.png');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
ball = game.add.sprite(400, 0, 'ball');
|
||||
|
||||
ball.body.gravity.y = 6;
|
||||
ball.body.bounce.y = 1;
|
||||
|
||||
tilesprite = game.add.tileSprite(300, 450, 200, 100, 'starfield');
|
||||
tilesprite.body.immovable = true;
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(ball, tilesprite);
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
tilesprite.x += 8;
|
||||
tilesprite.tilePosition.x += 8;
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
tilesprite.x -= 8;
|
||||
tilesprite.tilePosition.x -= 8;
|
||||
}
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
tilesprite.tilePosition.y += 8;
|
||||
}
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
tilesprite.tilePosition.y -= 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteBounds(tilesprite);
|
||||
|
||||
}
|
||||
@@ -1,34 +1,41 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
var s;
|
||||
var tilesprite;
|
||||
var cursors;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
||||
|
||||
tilesprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
s.tilePosition.x += 8;
|
||||
tilesprite.tilePosition.x += 8;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
s.tilePosition.x -= 8;
|
||||
tilesprite.tilePosition.x -= 8;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
s.tilePosition.y += 8;
|
||||
tilesprite.tilePosition.y += 8;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
s.tilePosition.y -= 8;
|
||||
tilesprite.tilePosition.y -= 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,6 +67,12 @@ Phaser.Stage = function (game, width, height) {
|
||||
*/
|
||||
this.aspectRatio = width / height;
|
||||
|
||||
/**
|
||||
* @property {boolean} disableVisibilityChange - By default if the browser tab loses focus the game will pause. You can stop that behaviour by setting this property to true.
|
||||
* @default
|
||||
*/
|
||||
this.disableVisibilityChange = false;
|
||||
|
||||
/**
|
||||
* @property {number} _nextOffsetCheck - The time to run the next offset check.
|
||||
* @private
|
||||
|
||||
@@ -51,8 +51,110 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
|
||||
*/
|
||||
this.tilePosition = new Phaser.Point(0, 0);
|
||||
|
||||
this.body.width = width;
|
||||
this.body.height = height;
|
||||
|
||||
};
|
||||
|
||||
Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype);
|
||||
Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
|
||||
|
||||
/**
|
||||
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
|
||||
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
|
||||
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
|
||||
* @name Phaser.TileSprite#angle
|
||||
* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, 'angle', {
|
||||
|
||||
get: function() {
|
||||
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TileSprite#frame
|
||||
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "frame", {
|
||||
|
||||
get: function () {
|
||||
return this.animations.frame;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.animations.frame = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TileSprite#frameName
|
||||
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "frameName", {
|
||||
|
||||
get: function () {
|
||||
return this.animations.frameName;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.animations.frameName = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TileSprite#inCamera
|
||||
* @property {boolean} inCamera - Is this sprite visible to the camera or not?
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "inCamera", {
|
||||
|
||||
get: function () {
|
||||
return this._cache.cameraVisible;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
|
||||
* activated for this Sprite instance and it will then start to process click/touch events and more.
|
||||
*
|
||||
* @name Phaser.TileSprite#inputEnabled
|
||||
* @property {boolean} inputEnabled - Set to true to allow this Sprite to receive input events, otherwise false.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TileSprite.prototype, "inputEnabled", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.input.enabled);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (this.input.enabled === false)
|
||||
{
|
||||
this.input.start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.input.enabled)
|
||||
{
|
||||
this.input.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -207,7 +207,7 @@ Phaser.Pointer.prototype = {
|
||||
}
|
||||
|
||||
// Fix to stop rogue browser plugins from blocking the visibility state event
|
||||
if (this.game.paused === true && this.game.stage.scale.incorrectOrientation === false)
|
||||
if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.stage.scale.incorrectOrientation === false)
|
||||
{
|
||||
this.game.paused = false;
|
||||
return this;
|
||||
|
||||
@@ -396,18 +396,22 @@ Phaser.Loader.prototype = {
|
||||
* @param {string} url - URL of the tileset.
|
||||
* @param {number} tileWidth - Width of each single tile in pixels.
|
||||
* @param {number} tileHeight - Height of each single tile in pixels.
|
||||
* @param {number} [tileMax=-1] - How many tiles in this tileset. If not specified it will divide the whole image into tiles.
|
||||
* @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here.
|
||||
* @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here.
|
||||
* @param {number} [rows=-1] - How many tiles are placed horizontally in each row? If -1 it will calculate rows by dividing the image width by tileWidth.
|
||||
* @param {number} [columns=-1] - How many tiles are placed vertically in each column? If -1 it will calculate columns by dividing the image height by tileHeight.
|
||||
* @param {number} [limit=-1] - The maximum number of tiles to extract from the image. If -1 it will extract rows * columns worth, otherwise you can set a lower limit value.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
tileset: function (key, url, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
|
||||
tileset: function (key, url, tileWidth, tileHeight, tileMargin, tileSpacing, rows, columns, limit) {
|
||||
|
||||
if (typeof tileMax === "undefined") { tileMax = -1; }
|
||||
if (typeof tileMargin === "undefined") { tileMargin = 0; }
|
||||
if (typeof tileSpacing === "undefined") { tileSpacing = 0; }
|
||||
if (typeof rows === "undefined") { rows = -1; }
|
||||
if (typeof columns === "undefined") { columns = -1; }
|
||||
if (typeof limit === "undefined") { limit = -1; }
|
||||
|
||||
this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMax: tileMax, tileMargin: tileMargin, tileSpacing: tileSpacing });
|
||||
this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMargin: tileMargin, tileSpacing: tileSpacing, rows: rows, columns: columns, limit: limit });
|
||||
|
||||
return this;
|
||||
|
||||
|
||||
@@ -306,9 +306,9 @@ Phaser.Physics.Arcade.prototype = {
|
||||
if (object1 && object2 && object1.exists && object2.exists)
|
||||
{
|
||||
// SPRITES
|
||||
if (object1.type == Phaser.SPRITE)
|
||||
if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsSprite(object1, object2, overlapCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -320,7 +320,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// GROUPS
|
||||
else if (object1.type == Phaser.GROUP)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -332,7 +332,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// EMITTER
|
||||
else if (object1.type == Phaser.EMITTER)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -482,12 +482,10 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// Only collide valid objects
|
||||
if (object1 && object2 && object1.exists && object2.exists)
|
||||
{
|
||||
// Can expand to support Buttons, Text, etc at a later date. For now these are the essentials.
|
||||
|
||||
// SPRITES
|
||||
if (object1.type == Phaser.SPRITE)
|
||||
if (object1.type == Phaser.SPRITE || object1.type == Phaser.TILESPRITE)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -503,7 +501,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// GROUPS
|
||||
else if (object1.type == Phaser.GROUP)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -519,7 +517,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// TILEMAP LAYERS
|
||||
else if (object1.type == Phaser.TILEMAPLAYER)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsTilemapLayer(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
@@ -531,7 +529,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// EMITTER
|
||||
else if (object1.type == Phaser.EMITTER)
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE)
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ PIXI.WebGLRenderGroup = function(gl, transparent)
|
||||
|
||||
this.batchs = [];
|
||||
this.toRemove = [];
|
||||
console.log(this.transparent)
|
||||
this.filterManager = new PIXI.WebGLFilterManager(this.transparent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user