mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Updated the arcade physics examples according to the lastest changes
This commit is contained in:
parent
8fff38618d
commit
d09da54dd3
34 changed files with 185 additions and 94 deletions
|
@ -14,11 +14,13 @@ function create() {
|
|||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
sprite.rotation = game.physics.accelerateToPointer(sprite, this.game.input.activePointer, 500, 500, 500);
|
||||
game.physics.arcade.moveToPointer(sprite, game.input.activePointer, 60, 500, 500);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
arrow.rotation = game.physics.angleBetween(arrow, target);
|
||||
arrow.rotation = game.physics.arcade.angleBetween(arrow, target);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ function update() {
|
|||
|
||||
// This will update the sprite.rotation so that it points to the currently active pointer
|
||||
// On a Desktop that is the mouse, on mobile the most recent finger press.
|
||||
sprite.rotation = game.physics.angleToPointer(sprite);
|
||||
sprite.rotation = game.physics.arcade.angleToPointer(sprite);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ function create() {
|
|||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
|
||||
// We'll set a lower max angular velocity here to keep it from going totally nuts
|
||||
sprite.body.maxAngular = 500;
|
||||
|
||||
|
|
3
examples/arcade physics/angular velocity.js
vendored
3
examples/arcade physics/angular velocity.js
vendored
|
@ -13,6 +13,7 @@ function create() {
|
|||
|
||||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
|
||||
}
|
||||
|
||||
|
@ -33,7 +34,7 @@ function update() {
|
|||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
|
||||
game.physics.arcade.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,10 +20,13 @@ function create() {
|
|||
sprite = game.add.sprite(200, 300, 'gameboy', 2);
|
||||
sprite.name = 'green';
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
sprite.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(600, 270, 'gameboy', 3);
|
||||
sprite2.name = 'yellow';
|
||||
game.physics.enable(sprite2, Phaser.Physics.ARCADE);
|
||||
sprite2.body.rebound = false;
|
||||
|
||||
game.add.tween(sprite.scale).to( { x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
|
@ -34,13 +37,13 @@ function update() {
|
|||
|
||||
sprite2.body.velocity.x = -200;
|
||||
|
||||
game.physics.collide(sprite, sprite2);
|
||||
game.physics.arcade.collide(sprite, sprite2);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.physicsBody(sprite.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.physicsBody(sprite.body);
|
||||
// game.debug.physicsBody(sprite2.body);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ function create() {
|
|||
flyer.animations.add('left', [0, 1, 2, 3], 10, true);
|
||||
flyer.animations.add('right', [5, 6, 7, 8], 10, true);
|
||||
|
||||
game.physics.enable(flyer, Phaser.Physics.ARCADE);
|
||||
|
||||
// This gets it moving
|
||||
flyer.body.velocity.setTo(200, 200);
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ function create() {
|
|||
ball = game.add.sprite(400, 200, 'ball');
|
||||
|
||||
knocker = game.add.sprite(400, 200, 'dude');
|
||||
|
||||
game.physics.enable([knocker,ball], Phaser.Physics.ARCADE);
|
||||
knocker.body.immovable = true;
|
||||
|
||||
// This gets it moving
|
||||
|
@ -44,7 +46,7 @@ function create() {
|
|||
function update () {
|
||||
|
||||
// Enable physics between the knocker and the ball
|
||||
game.physics.collide(knocker, ball);
|
||||
game.physics.arcade.collide(knocker, ball);
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,8 @@ function create() {
|
|||
// This creates a simple sprite that is using our loaded image and displays it on-screen and assign it to a variable
|
||||
image = game.add.sprite(400, 200, 'flyer');
|
||||
|
||||
game.physics.enable(image, Phaser.Physics.ARCADE);
|
||||
|
||||
// This gets it moving
|
||||
image.body.velocity.setTo(200, 200);
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ function create() {
|
|||
// and assign it to a variable
|
||||
image = game.add.sprite(0, 0, 'flyer');
|
||||
|
||||
game.physics.enable(image, Phaser.Physics.ARCADE);
|
||||
|
||||
// This gets it moving
|
||||
image.body.velocity.setTo(200,200);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ function create() {
|
|||
|
||||
sprite1 = game.add.sprite(150, 300, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
game.physics.enable(sprite1, Phaser.Physics.ARCADE);
|
||||
|
||||
// Here you can visually see the two bounding boxes the sprites are using for collision.
|
||||
|
||||
|
@ -23,13 +24,14 @@ function create() {
|
|||
|
||||
sprite2 = game.add.sprite(700, 320, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
game.physics.enable(sprite2, Phaser.Physics.ARCADE);
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -43,7 +45,7 @@ function render() {
|
|||
|
||||
// game.debug.bodyInfo(sprite1, 32, 32);
|
||||
|
||||
game.debug.physicsBody(sprite1.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.spriteBounds(sprite1);
|
||||
// game.debug.spriteBounds(sprite2);
|
||||
|
||||
}
|
||||
|
|
|
@ -16,24 +16,36 @@ function create() {
|
|||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
// Set the world (global) gravity
|
||||
game.physics.gravity.y = 100;
|
||||
game.physics.arcade.gravity.y = 100;
|
||||
|
||||
// Sprite 1 will use the World (global) gravity
|
||||
sprite1 = game.add.sprite(300, 32, 'ilkke');
|
||||
sprite1.body.collideWorldBounds = true;
|
||||
sprite1.body.bounce.y = 0.8;
|
||||
|
||||
// Sprite 2 is set to ignore the global gravity and use its own value
|
||||
sprite2 = game.add.sprite(400, 32, 'ilkke');
|
||||
|
||||
|
||||
// Sprite 3 will use both the global gravity and its own value
|
||||
sprite3 = game.add.sprite(500, 32, 'ilkke');
|
||||
|
||||
// We obviously need to enable physics on those sprites
|
||||
game.physics.enable([sprite1,sprite2,sprite3], Phaser.Physics.ARCADE);
|
||||
|
||||
|
||||
sprite1.body.collideWorldBounds = true;
|
||||
sprite1.body.bounce.y = 0.8;
|
||||
|
||||
|
||||
sprite2.body.collideWorldBounds = true;
|
||||
sprite2.body.bounce.y = 0.8;
|
||||
sprite2.body.allowGravity = false;
|
||||
sprite2.body.gravity.y = 100;
|
||||
|
||||
// Sprite 3 will use both the global gravity and its own value
|
||||
sprite3 = game.add.sprite(500, 32, 'ilkke');
|
||||
|
||||
sprite3.body.collideWorldBounds = true;
|
||||
sprite3.body.bounce.y = 0.8;
|
||||
sprite3.body.gravity.y = 100;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ function create() {
|
|||
{
|
||||
var c = veggies.create(game.world.randomX, Math.random() * 500, 'veggies', game.rnd.integerInRange(0, 36));
|
||||
c.name = 'veg' + i;
|
||||
game.physics.enable(c, Phaser.Physics.ARCADE);
|
||||
c.body.immovable = true;
|
||||
}
|
||||
|
||||
|
@ -38,12 +39,14 @@ function create() {
|
|||
{
|
||||
var b = bullets.create(0, 0, 'bullet');
|
||||
b.name = 'bullet' + i;
|
||||
game.physics.enable(b, Phaser.Physics.ARCADE);
|
||||
b.exists = false;
|
||||
b.visible = false;
|
||||
b.events.onOutOfBounds.add(resetBullet, this);
|
||||
}
|
||||
|
||||
sprite = game.add.sprite(400, 550, 'phaser');
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.SPACEBAR ]);
|
||||
|
@ -53,7 +56,7 @@ function create() {
|
|||
function update() {
|
||||
|
||||
// As we don't need to exchange any velocities or motion we can the 'overlap' check instead of 'collide'
|
||||
game.physics.overlap(bullets, veggies, collisionHandler, null, this);
|
||||
game.physics.arcade.overlap(bullets, veggies, collisionHandler, null, this);
|
||||
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
|
|
|
@ -21,6 +21,7 @@ function create() {
|
|||
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'spinner');
|
||||
s.animations.add('spin', [0,1,2,3]);
|
||||
s.play('spin', 20, true);
|
||||
game.physics.enable(s, Phaser.Physics.ARCADE);
|
||||
s.body.velocity.x = game.rnd.integerInRange(-200, 200);
|
||||
s.body.velocity.y = game.rnd.integerInRange(-200, 200);
|
||||
}
|
||||
|
@ -34,6 +35,6 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprites);
|
||||
game.physics.arcade.collide(sprites);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,19 +18,23 @@ function create() {
|
|||
sprite1 = game.add.sprite(130, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
|
||||
game.physics.enable(sprite1, Phaser.Physics.ARCADE);
|
||||
// In this example the new collision box is much larger than the original sprite
|
||||
sprite1.body.setRectangle(400, 50, -100, 20);
|
||||
sprite1.body.setSize(400, 50, -100, 20);
|
||||
sprite1.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(700, 210, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
game.physics.enable(sprite2, Phaser.Physics.ARCADE);
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,9 +46,9 @@ function collisionHandler (obj1, obj2) {
|
|||
|
||||
function render() {
|
||||
|
||||
game.debug.bodyInfo(sprite1, 32, 32);
|
||||
// game.debug.bodyInfo(sprite1, 32, 32);
|
||||
|
||||
game.debug.physicsBody(sprite1.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.physicsBody(sprite1.body);
|
||||
// game.debug.physicsBody(sprite2.body);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,9 @@ function create() {
|
|||
|
||||
player = game.add.sprite(150, 320, 'player');
|
||||
player.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(player, Phaser.Physics.ARCADE);
|
||||
|
||||
player.body.collideWorldBounds = true;
|
||||
player.body.bounce.setTo(0.9, 0.9);
|
||||
player.body.linearDamping = 0.2;
|
||||
|
@ -96,13 +99,13 @@ function launch() {
|
|||
|
||||
function update() {
|
||||
|
||||
arrow.rotation = game.physics.angleBetween(arrow, player);
|
||||
arrow.rotation = game.physics.arcade.angleBetween(arrow, player);
|
||||
|
||||
// Track the player sprite to the mouse
|
||||
if (catchFlag)
|
||||
{
|
||||
distance = game.physics.distanceToPointer(arrow);
|
||||
theta = game.physics.angleToPointer(arrow);
|
||||
distance = game.physics.arcade.distanceToPointer(arrow);
|
||||
theta = game.physics.arcade.angleToPointer(arrow);
|
||||
|
||||
// Govern the distance the sprite is dragged away from launch post
|
||||
if (distance > 300)
|
||||
|
|
|
@ -34,6 +34,9 @@ function create() {
|
|||
arrow.alpha = 0;
|
||||
|
||||
player = game.add.sprite(150, 320, 'player');
|
||||
|
||||
game.physics.enable([player], Phaser.Physics.ARCADE);
|
||||
|
||||
player.anchor.setTo(0.5, 0.5);
|
||||
player.body.collideWorldBounds = true;
|
||||
player.body.bounce.setTo(0.9, 0.9);
|
||||
|
@ -75,7 +78,7 @@ function launch() {
|
|||
|
||||
function update() {
|
||||
|
||||
arrow.rotation = game.physics.angleBetween(arrow, player);
|
||||
arrow.rotation = game.physics.arcade.angleBetween(arrow, player);
|
||||
|
||||
if (catchFlag == true)
|
||||
{
|
||||
|
@ -86,7 +89,7 @@ function update() {
|
|||
arrow.alpha = 1;
|
||||
analog.alpha = 0.5;
|
||||
analog.rotation = arrow.rotation - 3.14 / 2;
|
||||
analog.height = game.physics.distanceBetween(arrow, player);
|
||||
analog.height = game.physics.arcade.distanceBetween(arrow, player);
|
||||
launchVelocity = analog.height;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ var launchVelocity = 0;
|
|||
function create() {
|
||||
|
||||
// set global gravity
|
||||
game.physics.gravity.y = 200;
|
||||
game.physics.arcade.gravity.y = 200;
|
||||
game.stage.backgroundColor = '#0072bc';
|
||||
|
||||
var graphics = game.add.graphics(0,0);
|
||||
|
@ -27,6 +27,9 @@ function create() {
|
|||
graphics.drawRect(395, 350, 10, 250);
|
||||
|
||||
analog = game.add.sprite(400, 350, 'analog');
|
||||
|
||||
game.physics.enable(analog, Phaser.Physics.ARCADE);
|
||||
|
||||
analog.body.allowGravity = false;
|
||||
analog.width = 8;
|
||||
analog.rotation = 220;
|
||||
|
@ -34,11 +37,14 @@ function create() {
|
|||
analog.anchor.setTo(0.5, 0.0);
|
||||
|
||||
arrow = game.add.sprite(400, 350, 'arrow');
|
||||
|
||||
game.physics.enable(arrow, Phaser.Physics.ARCADE);
|
||||
arrow.anchor.setTo(0.1, 0.5);
|
||||
arrow.body.allowGravity = false;
|
||||
arrow.alpha = 0;
|
||||
|
||||
ball = game.add.sprite(100, 400, 'ball');
|
||||
game.physics.enable(ball, Phaser.Physics.ARCADE);
|
||||
ball.anchor.setTo(0.5, 0.5);
|
||||
ball.body.collideWorldBounds = true;
|
||||
ball.body.bounce.setTo(0.9, 0.9);
|
||||
|
@ -74,7 +80,7 @@ function launch() {
|
|||
|
||||
function update() {
|
||||
|
||||
arrow.rotation = game.physics.angleBetween(arrow, ball);
|
||||
arrow.rotation = game.physics.arcade.angleBetween(arrow, ball);
|
||||
|
||||
if (catchFlag == true)
|
||||
{
|
||||
|
@ -85,7 +91,7 @@ function update() {
|
|||
arrow.alpha = 1;
|
||||
analog.alpha = 0.5;
|
||||
analog.rotation = arrow.rotation - 3.14 / 2;
|
||||
analog.height = game.physics.distanceToPointer(arrow);
|
||||
analog.height = game.physics.arcade.distanceToPointer(arrow);
|
||||
launchVelocity = analog.height;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,22 +15,23 @@ function create() {
|
|||
|
||||
aliens = game.add.group();
|
||||
|
||||
game.physics.gravity.y = 100;
|
||||
game.physics.arcade.gravity.y = 100;
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie');
|
||||
game.physics.enable(s, Phaser.Physics.ARCADE);
|
||||
s.name = 'alien' + s;
|
||||
s.body.collideWorldBounds = true;
|
||||
s.body.bounce.setTo(0.8, 0.8);
|
||||
s.body.linearDamping = 0;
|
||||
s.body.minVelocity.setTo(0, 0);
|
||||
s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
|
||||
}
|
||||
|
||||
car = game.add.sprite(400, 300, 'car');
|
||||
car.name = 'car';
|
||||
car.anchor.setTo(0.5, 0.5);
|
||||
game.physics.enable(car, Phaser.Physics.ARCADE);
|
||||
car.body.collideWorldBounds = true;
|
||||
// car.body.bounce.setTo(0.8, 0.8);
|
||||
car.body.allowRotation = true;
|
||||
|
@ -41,7 +42,7 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(car, aliens);
|
||||
game.physics.arcade.collide(car, aliens);
|
||||
|
||||
car.body.velocity.x = 0;
|
||||
car.body.velocity.y = 0;
|
||||
|
@ -58,22 +59,22 @@ function update() {
|
|||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
|
||||
car.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(car.angle, 300));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
for (var i = 0; i < aliens._container.children.length; i++)
|
||||
{
|
||||
game.debug.polygon(aliens._container.children[i].body.polygons);
|
||||
}
|
||||
// for (var i = 0; i < aliens._container.children.length; i++)
|
||||
// {
|
||||
// game.debug.polygon(aliens._container.children[i].body.polygons);
|
||||
// }
|
||||
|
||||
game.debug.polygon(car.body.polygons);
|
||||
// game.debug.polygon(car.body.polygons);
|
||||
|
||||
// game.debug.bodyInfo(aliens._container.children[0], 32, 32);
|
||||
game.debug.bodyInfo(aliens._container.children[0], 32, 32);
|
||||
// game.debug.bodyInfo(aliens._container.children[0], 32, 32);
|
||||
|
||||
// game.debug.bodyInfo(car, 16, 24);
|
||||
// game.debug.bodyInfo(aliens.getFirstAlive(), 16, 24);
|
||||
|
|
|
@ -15,7 +15,8 @@ function create() {
|
|||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
balls.create(game.world.randomX, game.world.randomY, 'ball');
|
||||
var ball = balls.create(game.world.randomX, game.world.randomY, 'ball');
|
||||
game.physics.enable(ball, Phaser.Physics.ARCADE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +26,9 @@ function update() {
|
|||
if (game.input.mousePointer.isDown)
|
||||
{
|
||||
// First is the callback
|
||||
// Second is the context in which the callback runs, in this case game.physics
|
||||
// Second is the context in which the callback runs, in this case game.physics.arcade
|
||||
// Third is the parameter the callback expects - it is always sent the Group child as the first parameter
|
||||
balls.forEach(game.physics.moveToPointer, game.physics, false, 200);
|
||||
balls.forEach(game.physics.arcade.moveToPointer, game.physics.arcade, false, 200);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -33,9 +33,9 @@ function update() {
|
|||
// This will update the sprite.rotation so that it points to the currently active pointer
|
||||
// On a Desktop that is the mouse, on mobile the most recent finger press.
|
||||
|
||||
sprite1.rotation = game.physics.angleToPointer(sprite1);
|
||||
sprite2.rotation = game.physics.angleToPointer(sprite2);
|
||||
sprite3.rotation = game.physics.angleToPointer(sprite3);
|
||||
sprite4.rotation = game.physics.angleToPointer(sprite4);
|
||||
sprite1.rotation = game.physics.arcade.angleToPointer(sprite1);
|
||||
sprite2.rotation = game.physics.arcade.angleToPointer(sprite2);
|
||||
sprite3.rotation = game.physics.arcade.angleToPointer(sprite3);
|
||||
sprite4.rotation = game.physics.arcade.angleToPointer(sprite4);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,20 +18,25 @@ function create() {
|
|||
sprite1 = game.add.sprite(150, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
|
||||
// This adjusts the collision body size to be a 100x50 box.
|
||||
// 50, 25 is the X and Y offset of the newly sized box.
|
||||
sprite1.body.setRectangle(100, 50, 50, 25);
|
||||
sprite1.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
|
||||
game.physics.enable([sprite1,sprite2], Phaser.Physics.ARCADE);
|
||||
|
||||
// This adjusts the collision body size to be a 100x50 box.
|
||||
// 50, 25 is the X and Y offset of the newly sized box.
|
||||
|
||||
sprite1.body.setSize(100, 50, 50, 25);
|
||||
sprite1.body.immovable = true;
|
||||
|
||||
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -43,9 +48,9 @@ function collisionHandler (obj1, obj2) {
|
|||
|
||||
function render() {
|
||||
|
||||
game.debug.bodyInfo(sprite1, 32, 32);
|
||||
// game.debug.bodyInfo(sprite1, 32, 32);
|
||||
|
||||
game.debug.physicsBody(sprite1.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.physicsBody(sprite1.body);
|
||||
// game.debug.physicsBody(sprite2.body);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ function create() {
|
|||
|
||||
sprite = game.add.sprite(300, 200, 'atari');
|
||||
sprite.name = 'atari';
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
sprite.body.collideWorldBounds = true;
|
||||
sprite.body.checkCollision.up = false;
|
||||
sprite.body.checkCollision.down = false;
|
||||
|
@ -28,10 +29,15 @@ function create() {
|
|||
|
||||
sprite2 = game.add.sprite(350, 400, 'gameboy', 2);
|
||||
sprite2.name = 'gameboy';
|
||||
|
||||
game.physics.enable(sprite2, Phaser.Physics.ARCADE);
|
||||
sprite2.body.collideWorldBounds = true;
|
||||
sprite2.body.bounce.setTo(1, 1);
|
||||
|
||||
sprite3 = game.add.sprite(0, 210, 'gameboy', 4);
|
||||
|
||||
game.physics.enable(sprite3, Phaser.Physics.ARCADE);
|
||||
|
||||
sprite3.name = 'gameboy2';
|
||||
sprite3.body.collideWorldBounds = true;
|
||||
sprite3.body.bounce.setTo(1, 1);
|
||||
|
@ -43,8 +49,8 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite, sprite2);
|
||||
game.physics.collide(sprite, sprite3);
|
||||
game.physics.arcade.collide(sprite, sprite2);
|
||||
game.physics.arcade.collide(sprite, sprite3);
|
||||
|
||||
}
|
||||
|
||||
|
@ -52,7 +58,7 @@ function render() {
|
|||
|
||||
// game.debug.bodyInfo(sprite, 16, 24);
|
||||
|
||||
game.debug.physicsBody(sprite.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.physicsBody(sprite.body);
|
||||
// game.debug.physicsBody(sprite2.body);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ function create() {
|
|||
sprite1 = game.add.sprite(0, 200, 'atari');
|
||||
sprite2 = game.add.sprite(750, 220, 'mushroom');
|
||||
|
||||
game.physics.enable([sprite1,sprite2], Phaser.Physics.ARCADE);
|
||||
|
||||
// We'll use random velocities so we can test it in our processCallback
|
||||
sprite1.body.velocity.x = 50 + Math.random() * 100;
|
||||
sprite2.body.velocity.x = -(50 + Math.random() * 100);
|
||||
|
@ -27,7 +29,7 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionCallback, processCallback, this);
|
||||
game.physics.arcade.collide(sprite1, sprite2, collisionCallback, processCallback, this);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ function create() {
|
|||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie')
|
||||
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie');
|
||||
game.physics.enable(s, Phaser.Physics.ARCADE);
|
||||
s.name = 'alien' + s;
|
||||
s.body.collideWorldBounds = true;
|
||||
s.body.bounce.setTo(1, 1);
|
||||
|
@ -23,6 +24,7 @@ function create() {
|
|||
}
|
||||
|
||||
ship = game.add.sprite(400, 400, 'ship');
|
||||
game.physics.enable(ship, Phaser.Physics.ARCADE);
|
||||
ship.body.collideWorldBounds = true;
|
||||
ship.body.bounce.setTo(1, 1);
|
||||
|
||||
|
@ -48,13 +50,13 @@ function update() {
|
|||
ship.body.velocity.y += 2;
|
||||
}
|
||||
|
||||
game.physics.collide(ship, aliens);
|
||||
game.physics.arcade.collide(ship, aliens);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.QuadTree(game.physics.quadTree);
|
||||
game.debug.QuadTree(game.physics.arcade.quadTree);
|
||||
game.debug.geom(ship.body);
|
||||
|
||||
// game.debug.text('total: ' + total.length, 32, 50);
|
||||
|
|
|
@ -20,6 +20,7 @@ function create() {
|
|||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
|
||||
s.name = 'alien' + s;
|
||||
game.physics.enable(s, Phaser.Physics.ARCADE);
|
||||
s.body.collideWorldBounds = true;
|
||||
s.body.bounce.setTo(1, 1);
|
||||
s.body.velocity.setTo(10 + Math.random() * 10, 10 + Math.random() * 10);
|
||||
|
@ -27,6 +28,7 @@ function create() {
|
|||
}
|
||||
|
||||
ship = game.add.sprite(400, 400, 'ship');
|
||||
game.physics.enable(ship, Phaser.Physics.ARCADE);
|
||||
ship.body.collideWorldBounds = true;
|
||||
ship.body.bounce.setTo(0.5, 0.5);
|
||||
|
||||
|
@ -39,7 +41,7 @@ function update() {
|
|||
aliens[i].alpha = 0.3;
|
||||
}
|
||||
|
||||
total = game.physics.quadTree.retrieve(ship);
|
||||
total = game.physics.arcade.quadTree.retrieve(ship);
|
||||
|
||||
// Get the ships top-most ID. If the length of that ID is 1 then we can ignore every other result,
|
||||
// it's simply not colliding with anything :)
|
||||
|
@ -77,7 +79,7 @@ function render() {
|
|||
}
|
||||
|
||||
game.debug.text(total.length, 32, 32);
|
||||
game.debug.QuadTree(game.physics.quadTree);
|
||||
game.debug.QuadTree(game.physics.arcade.quadTree);
|
||||
// game.debug.geom(ship);
|
||||
|
||||
game.debug.text('Index: ' + ship.body.quadTreeIndex, 32, 80);
|
||||
|
|
|
@ -24,11 +24,13 @@ function create() {
|
|||
|
||||
// game.enableStep();
|
||||
|
||||
game.physics.gravity.y = 100;
|
||||
game.physics.arcade.gravity.y = 100;
|
||||
|
||||
sprite = game.add.sprite(32, 450, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
|
||||
sprite.body.collideWorldBounds = true;
|
||||
sprite.body.bounce.setTo(0.8, 0.8);
|
||||
|
||||
|
@ -55,14 +57,14 @@ function update() {
|
|||
|
||||
sprite.rotation = sprite.body.angle;
|
||||
|
||||
bmd.fillStyle('#ffff00');
|
||||
bmd.fillRect(sprite.x, sprite.y, 2, 2);
|
||||
bmd.context.fillStyle('#ffff00');
|
||||
bmd.context.fillRect(sprite.x, sprite.y, 2, 2);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.bodyInfo(sprite, 16, 24);
|
||||
game.debug.physicsBody(sprite.body);
|
||||
// game.debug.bodyInfo(sprite, 16, 24);
|
||||
// game.debug.physicsBody(sprite.body);
|
||||
|
||||
}
|
||||
|
|
|
@ -22,16 +22,24 @@ function create() {
|
|||
bullets.createMultiple(50, 'bullet');
|
||||
bullets.setAll('anchor.x', 0.5);
|
||||
bullets.setAll('anchor.y', 0.5);
|
||||
bullets.setAll('outOfBoundsKill', true);
|
||||
|
||||
|
||||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
|
||||
bullets.forEach(function (sprite) {
|
||||
|
||||
game.physics.enable(sprite, Phaser.Physics.ARCADE);
|
||||
sprite.body.outOfBoundsKill = true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
sprite.rotation = game.physics.angleToPointer(sprite);
|
||||
sprite.rotation = game.physics.arcade.angleToPointer(sprite);
|
||||
|
||||
if (game.input.activePointer.isDown)
|
||||
{
|
||||
|
@ -50,7 +58,7 @@ function fire() {
|
|||
|
||||
bullet.reset(sprite.x, sprite.y);
|
||||
|
||||
bullet.rotation = game.physics.moveToPointer(bullet, 300);
|
||||
bullet.rotation = game.physics.arcade.moveToPointer(bullet, 300);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ function create() {
|
|||
snakeHead = game.add.sprite(400, 300, 'ball');
|
||||
snakeHead.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.physics.enable(snakeHead, Phaser.Physics.ARCADE);
|
||||
|
||||
// Init snakeSection array
|
||||
for (var i = 1; i <= numSnakeSections-1; i++)
|
||||
{
|
||||
|
@ -46,7 +48,7 @@ function update() {
|
|||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
snakeHead.body.velocity.copyFrom(game.physics.velocityFromAngle(snakeHead.angle, 300));
|
||||
snakeHead.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(snakeHead.angle, 300));
|
||||
|
||||
// Everytime the snake head moves, insert the new location at the start of the array,
|
||||
// and knock the last position off the end
|
||||
|
|
|
@ -16,7 +16,7 @@ function create() {
|
|||
fuji.anchor.setTo(0, 0.5);
|
||||
// fuji.angle = 34;
|
||||
|
||||
b = new Phaser.Rectangle(fuji.center.x, fuji.center.y, fuji.width, fuji.height);
|
||||
b = new Phaser.Rectangle(fuji.width/2, fuji.height/2, fuji.width, fuji.height);
|
||||
|
||||
//Remember that the sprite is rotating around its anchor
|
||||
game.add.tween(fuji).to({ angle: 360 }, 20000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
@ -27,11 +27,11 @@ function update() {
|
|||
|
||||
if (game.input.activePointer.justPressed())
|
||||
{
|
||||
fuji.centerOn(game.input.x, game.input.y);
|
||||
fuji.position = game.input;
|
||||
}
|
||||
|
||||
b.x = fuji.center.x - fuji.halfWidth;
|
||||
b.y = fuji.center.y - fuji.halfHeight;
|
||||
b.x = fuji.width/2 - fuji.width/2;
|
||||
b.y = fuji.height/2 - fuji.height/2;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -21,18 +21,16 @@ function create() {
|
|||
sprite = game.add.sprite(32, 200, 'phaser');
|
||||
sprite.name = 'phaser-dude';
|
||||
|
||||
// Enables the arcade physics body on the sprite
|
||||
game.physics.arcade.enable(sprite);
|
||||
|
||||
group = game.add.group();
|
||||
|
||||
// Enables the arcade physics body on all sprites this group creates
|
||||
group.enableBody = true;
|
||||
game.physics.enable(game.world, Phaser.Physics.ARCADE);
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', game.rnd.integerInRange(0, 36));
|
||||
c.name = 'veg' + i;
|
||||
game.physics.enable(c, Phaser.Physics.ARCADE);
|
||||
c.body.immovable = true;
|
||||
}
|
||||
|
||||
|
@ -41,6 +39,7 @@ function create() {
|
|||
// Here we'll create some chillis which the player can pick-up. They are still part of the same Group.
|
||||
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', 17);
|
||||
c.name = 'chilli' + i;
|
||||
game.physics.enable(c, Phaser.Physics.ARCADE);
|
||||
c.body.immovable = true;
|
||||
}
|
||||
|
||||
|
@ -51,6 +50,7 @@ function create() {
|
|||
function update() {
|
||||
|
||||
game.physics.arcade.collide(sprite, group, collisionHandler, null, this);
|
||||
game.physics.arcade.collide(group, group);
|
||||
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
|
|
|
@ -18,10 +18,14 @@ function create() {
|
|||
// This will check Sprite vs. Sprite collision
|
||||
|
||||
sprite1 = game.add.sprite(50, 200, 'atari');
|
||||
|
||||
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
||||
|
||||
game.physics.enable([sprite1,sprite2], Phaser.Physics.ARCADE);
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.velocity.x = 100;
|
||||
|
||||
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
||||
|
||||
sprite2.name = 'mushroom';
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
|
@ -30,7 +34,7 @@ function create() {
|
|||
function update() {
|
||||
|
||||
// object1, object2, collideCallback, processCallback, callbackContext
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -43,7 +47,7 @@ function collisionHandler (obj1, obj2) {
|
|||
|
||||
function render() {
|
||||
|
||||
game.debug.physicsBody(sprite1.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.physicsBody(sprite1.body);
|
||||
// game.debug.physicsBody(sprite2.body);
|
||||
|
||||
}
|
|
@ -17,22 +17,28 @@ function create() {
|
|||
|
||||
sprite1 = game.add.sprite(300, 50, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
|
||||
game.physics.enable(sprite1, Phaser.Physics.ARCADE);
|
||||
|
||||
sprite1.body.velocity.y = 100;
|
||||
|
||||
|
||||
|
||||
// This adjusts the collision body size.
|
||||
// 220x10 is the new width/height.
|
||||
// See the offset bounding box for another example.
|
||||
sprite1.body.setRectangle(220, 10, 0, 0);
|
||||
sprite1.body.setSize(220, 10, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(400, 450, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
game.physics.enable(sprite2, Phaser.Physics.ARCADE);
|
||||
sprite2.body.immovable = true;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
game.physics.arcade.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -44,7 +50,7 @@ function collisionHandler (obj1, obj2) {
|
|||
|
||||
function render() {
|
||||
|
||||
game.debug.physicsBody(sprite1.body);
|
||||
game.debug.physicsBody(sprite2.body);
|
||||
// game.debug.spriteBounds(sprite1);
|
||||
// game.debug.spriteBounds(sprite2);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue