mirror of
https://github.com/wassname/phaser.git
synced 2026-07-17 01:30:32 +08:00
ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user