diff --git a/examples/assets/sprites/diamonds32x24x5.png b/examples/assets/sprites/diamonds32x24x5.png new file mode 100644 index 000000000..94c2d21dd Binary files /dev/null and b/examples/assets/sprites/diamonds32x24x5.png differ diff --git a/examples/p2 physics/impact events.js b/examples/p2 physics/impact events.js new file mode 100644 index 000000000..1cc95b1ce --- /dev/null +++ b/examples/p2 physics/impact events.js @@ -0,0 +1,82 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('stars', 'assets/misc/starfield.jpg'); + game.load.image('ship', 'assets/sprites/thrust_ship2.png'); + game.load.image('ball', 'assets/sprites/shinyball.png'); + game.load.spritesheet('diamonds', 'assets/sprites/diamonds32x24x5.png', 32, 24); + +} + +var ship; +var starfield; +var diamonds; +var cursors; + +function create() { + + game.world.setBounds(0, 0, 1920, 1200); + + game.physics.startSystem(Phaser.Physics.P2JS); + game.physics.p2.defaultRestitution = 0.8; + + // starfield = game.add.tileSprite(0, 0, 800, 600, 'stars'); + // starfield.fixedToCamera = true; + + diamonds = game.add.group(); + // diamonds.enableBody = true; + // diamonds.physicsBodyType = Phaser.Physics.P2JS; + + for (var i = 0; i < 50; i++) + { + // var d = diamonds.create(game.world.randomX, game.world.randomY, 'diamonds', game.rnd.integerInRange(0, 5)); + // game.physics.p2.enable(d, true); + + var d = diamonds.create(game.world.randomX, game.world.randomY, 'ball'); + game.physics.p2.enable(d); + d.body.setCircle(16); + } + + ship = game.add.sprite(200, 200, 'ship'); + + game.physics.p2.enable(ship, true); + + game.camera.follow(ship); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function update() { + + if (cursors.left.isDown) + { + ship.body.rotateLeft(100); + } + else if (cursors.right.isDown) + { + ship.body.rotateRight(100); + } + else + { + ship.body.setZeroRotation(); + } + + if (cursors.up.isDown) + { + ship.body.thrust(400); + } + else if (cursors.down.isDown) + { + ship.body.reverse(400); + } + + // starfield.tilePosition.add(ship.body.velocity.x / 4, ship.body.velocity.y / 4); + +} + +function render() { + +} \ No newline at end of file diff --git a/examples/p2 physics/thrust.js b/examples/p2 physics/thrust.js new file mode 100644 index 000000000..d2c9b9605 --- /dev/null +++ b/examples/p2 physics/thrust.js @@ -0,0 +1,65 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('stars', 'assets/misc/starfield.jpg'); + game.load.image('ship', 'assets/sprites/thrust_ship2.png'); + +} + +var ship; +var starfield; +var cursors; + +function create() { + + game.world.setBounds(0, 0, 1920, 1200); + + game.physics.startSystem(Phaser.Physics.P2JS); + game.physics.p2.defaultRestitution = 0.8; + + starfield = game.add.tileSprite(0, 0, 800, 600, 'stars'); + starfield.fixedToCamera = true; + + ship = game.add.sprite(200, 200, 'ship'); + + game.physics.p2.enable(ship); + + game.camera.follow(ship); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function update() { + + if (cursors.left.isDown) + { + ship.body.rotateLeft(100); + } + else if (cursors.right.isDown) + { + ship.body.rotateRight(100); + } + else + { + ship.body.setZeroRotation(); + } + + if (cursors.up.isDown) + { + ship.body.thrust(400); + } + else if (cursors.down.isDown) + { + ship.body.reverse(400); + } + + starfield.tilePosition.add(ship.body.velocity.x, ship.body.velocity.y); + +} + +function render() { + +} \ No newline at end of file diff --git a/examples/p2 physics/world move.js b/examples/p2 physics/world move.js new file mode 100644 index 000000000..6f458d45e --- /dev/null +++ b/examples/p2 physics/world move.js @@ -0,0 +1,88 @@ + +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('stars', 'assets/misc/starfield.jpg'); + game.load.spritesheet('ship', 'assets/sprites/humstar.png', 32, 32); + game.load.image('ball', 'assets/sprites/shinyball.png'); + +} + +var ship; +var starfield; +var cursors; + +function create() { + + game.world.setBounds(0, 0, 1600, 1200); + + game.physics.startSystem(Phaser.Physics.P2JS); + game.physics.p2.defaultRestitution = 0.9; + + starfield = game.add.tileSprite(0, 0, 800, 600, 'stars'); + starfield.fixedToCamera = true; + + balls = game.add.group(); + balls.enableBody = true; + balls.physicsBodyType = Phaser.Physics.P2JS; + + for (var i = 0; i < 50; i++) + { + var ball = balls.create(game.world.randomX, game.world.randomY, 'ball'); + ball.body.setCircle(16); + } + + ship = game.add.sprite(200, 200, 'ship'); + ship.scale.set(2); + ship.smoothed = false; + ship.animations.add('fly', [0,1,2,3,4,5], 10, true); + ship.play('fly'); + + // Create our physics body - a 28px radius circle. Set the 'false' parameter below to 'true' to enable debugging + game.physics.p2.enable(ship, false); + ship.body.setCircle(28); + + game.camera.follow(ship); + + cursors = game.input.keyboard.createCursorKeys(); + +} + +function update() { + + ship.body.setZeroVelocity(); + + if (cursors.left.isDown) + { + ship.body.moveLeft(200); + } + else if (cursors.right.isDown) + { + ship.body.moveRight(200); + } + + if (cursors.up.isDown) + { + ship.body.moveUp(200); + } + else if (cursors.down.isDown) + { + ship.body.moveDown(200); + } + + if (!game.camera.atLimit.x) + { + starfield.tilePosition.x += (ship.body.velocity.x * 16) * game.time.physicsElapsed; + } + + if (!game.camera.atLimit.y) + { + starfield.tilePosition.y += (ship.body.velocity.y * 16) * game.time.physicsElapsed; + } + +} + +function render() { + +} \ No newline at end of file diff --git a/src/core/Camera.js b/src/core/Camera.js index f6eebd599..69727a0ae 100644 --- a/src/core/Camera.js +++ b/src/core/Camera.js @@ -275,25 +275,25 @@ Phaser.Camera.prototype = { this.atLimit.y = false; // Make sure we didn't go outside the cameras bounds - if (this.view.x < this.bounds.x) + if (this.view.x <= this.bounds.x) { this.atLimit.x = true; this.view.x = this.bounds.x; } - if (this.view.right > this.bounds.right) + if (this.view.right >= this.bounds.right) { this.atLimit.x = true; this.view.x = this.bounds.right - this.width; } - if (this.view.y < this.bounds.top) + if (this.view.y <= this.bounds.top) { this.atLimit.y = true; this.view.y = this.bounds.top; } - if (this.view.bottom > this.bounds.bottom) + if (this.view.bottom >= this.bounds.bottom) { this.atLimit.y = true; this.view.y = this.bounds.bottom - this.height; diff --git a/src/core/Group.js b/src/core/Group.js index 85c6a5804..df217d96a 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -289,15 +289,18 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists) { { if (this.physicsBodyType === Phaser.Physics.ARCADE) { - child.body = new Phaser.Physics.Arcade.Body(child); + this.game.physics.arcade.enable(child); + // child.body = new Phaser.Physics.Arcade.Body(child); } else if (this.physicsBodyType === Phaser.Physics.NINJA && this.game.physics.ninja) { - child.body = new Phaser.Physics.Ninja.Body(this.game.physics.ninja, child, 1); + this.game.physics.ninja.enable(child); + // child.body = new Phaser.Physics.Ninja.Body(this.game.physics.ninja, child, 1); } else if (this.physicsBodyType === Phaser.Physics.P2JS && this.game.physics.p2) { - child.body = new Phaser.Physics.P2.Body(this.game, child, x, y, 1); + this.game.physics.p2.enable(child); + // child.body = new Phaser.Physics.P2.Body(this.game, child, x, y, 1); } } diff --git a/src/gameobjects/TileSprite.js b/src/gameobjects/TileSprite.js index aac98731a..b7de22443 100644 --- a/src/gameobjects/TileSprite.js +++ b/src/gameobjects/TileSprite.js @@ -6,7 +6,7 @@ /** * A TileSprite is a Sprite that has a repeating texture. The texture can be scrolled and scaled and will automatically wrap on the edges as it does so. -* Please note that TileSprites have no input handler or physics bodies. +* Please note that TileSprites, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling. * * @class Phaser.TileSprite * @constructor diff --git a/src/physics/p2/World.js b/src/physics/p2/World.js index d7d4ae061..14b4f138f 100644 --- a/src/physics/p2/World.js +++ b/src/physics/p2/World.js @@ -130,9 +130,9 @@ Phaser.Physics.P2 = function (game, config) { } // Hook into the World events - this.world.on("postStep", this.postStepHandler, this); - this.world.on("postBroadphase", this.postBroadphaseHandler, this); - this.world.on("impact", this.impactHandler, this); + // this.world.on("postStep", this.postStepHandler, this); + // this.world.on("postBroadphase", this.postBroadphaseHandler, this); + // this.world.on("impact", this.impactHandler, this); this.world.on("beginContact", this.beginContactHandler, this); this.world.on("endContact", this.endContactHandler, this);