mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Integrated SAT. Fixed lots of examples. Fixed documentation. Added new examples and built new phaser.js file for testing.
This commit is contained in:
@@ -110,6 +110,10 @@
|
||||
}
|
||||
],
|
||||
"collision": [
|
||||
{
|
||||
"file": "body+scale.js",
|
||||
"title": "body scale"
|
||||
},
|
||||
{
|
||||
"file": "bounding+box.js",
|
||||
"title": "bounding box"
|
||||
@@ -118,6 +122,10 @@
|
||||
"file": "group+vs+group.js",
|
||||
"title": "group vs group"
|
||||
},
|
||||
{
|
||||
"file": "group+vs+self.js",
|
||||
"title": "group vs self"
|
||||
},
|
||||
{
|
||||
"file": "larger+bounding+box.js",
|
||||
"title": "larger bounding box"
|
||||
@@ -130,10 +138,6 @@
|
||||
"file": "process+callback.js",
|
||||
"title": "process callback"
|
||||
},
|
||||
{
|
||||
"file": "sprite+tiles.js",
|
||||
"title": "sprite tiles"
|
||||
},
|
||||
{
|
||||
"file": "sprite+vs+group.js",
|
||||
"title": "sprite vs group"
|
||||
@@ -142,10 +146,6 @@
|
||||
"file": "sprite+vs+sprite.js",
|
||||
"title": "sprite vs sprite"
|
||||
},
|
||||
{
|
||||
"file": "transform.js",
|
||||
"title": "transform"
|
||||
},
|
||||
{
|
||||
"file": "vertical+collision.js",
|
||||
"title": "vertical collision"
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
<script src="../src/utils/Debug.js"></script>
|
||||
<script src="../src/utils/Color.js"></script>
|
||||
|
||||
<script src="../src/physics/arcade/SAT.js"></script>
|
||||
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
|
||||
<script src="../src/physics/arcade/Body.js"></script>
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
<script src="../src/utils/Debug.js"></script>
|
||||
<script src="../src/utils/Color.js"></script>
|
||||
|
||||
<script src="../src/physics/arcade/SAT.js"></script>
|
||||
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
|
||||
<script src="../src/physics/arcade/Body.js"></script>
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
@@ -0,0 +1,46 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var sprite2;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#124184';
|
||||
|
||||
// Here we're tweening the scale of the sprite, which translates to the scale of the Body as well
|
||||
// The collision will carry on working even against the scaled body.
|
||||
|
||||
sprite = game.add.sprite(200, 300, 'gameboy', 2);
|
||||
sprite.name = 'green';
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
sprite.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(600, 270, 'gameboy', 3);
|
||||
sprite2.name = 'yellow';
|
||||
sprite2.body.rebound = false;
|
||||
|
||||
sprite2.body.velocity.x = -200;
|
||||
|
||||
game.add.tween(sprite.scale).to( { x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite, sprite2);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderPolygon(sprite.body.polygons, 'rgb(255,0,0)');
|
||||
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
|
||||
|
||||
}
|
||||
@@ -14,16 +14,15 @@ function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
sprite1 = game.add.sprite(50, 200, 'atari');
|
||||
sprite1 = game.add.sprite(150, 300, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.velocity.x = 100;
|
||||
|
||||
// This adjusts the collision body size.
|
||||
// 100x100 is the new width/height.
|
||||
// This adjusts the collision body size to be 104 x 104.
|
||||
// See the offset bounding box for another example.
|
||||
sprite1.body.setSize(100, 100, 0, 0);
|
||||
sprite1.body.setSize(104, 104, 0, 0);
|
||||
sprite1.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
||||
sprite2 = game.add.sprite(700, 320, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
@@ -40,16 +39,13 @@ function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
game.debug.renderBodyInfo(sprite1, 32, 32);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
game.debug.renderPolygon(sprite1.body.polygons, 'rgb(255,0,0)');
|
||||
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ function preload() {
|
||||
var sprite;
|
||||
var bullets;
|
||||
var veggies;
|
||||
var bulletTime = 0;
|
||||
var cursors;
|
||||
|
||||
var bulletTime = 0;
|
||||
var bullet;
|
||||
|
||||
function create() {
|
||||
@@ -44,23 +45,26 @@ function create() {
|
||||
|
||||
sprite = game.add.sprite(400, 550, 'phaser');
|
||||
|
||||
// Stop the following keys from propagating up to the browser
|
||||
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.SPACEBAR ]);
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.SPACEBAR ]);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
sprite.body.velocity.x = -200;
|
||||
sprite.body.velocity.x = -300;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
sprite.body.velocity.x = 200;
|
||||
sprite.body.velocity.x = 300;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
|
||||
@@ -68,9 +72,6 @@ function update() {
|
||||
fireBullet();
|
||||
}
|
||||
|
||||
// As we don't need to exchange any velocities or motion we can use the faster 'overlap' check instead of 'collide':
|
||||
game.physics.overlap(bullets, veggies, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
function fireBullet () {
|
||||
@@ -83,7 +84,7 @@ function fireBullet () {
|
||||
{
|
||||
bullet.reset(sprite.x + 6, sprite.y - 8);
|
||||
bullet.body.velocity.y = -300;
|
||||
bulletTime = game.time.now + 250;
|
||||
bulletTime = game.time.now + 150;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +92,12 @@ function fireBullet () {
|
||||
|
||||
// Called if the bullet goes out of the screen
|
||||
function resetBullet (bullet) {
|
||||
|
||||
bullet.kill();
|
||||
|
||||
}
|
||||
|
||||
// Called if the bullet hits one of the veg sprites
|
||||
function collisionHandler (bullet, veg) {
|
||||
|
||||
bullet.kill();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('spinner', 'assets/sprites/bluemetal_32x32x4.png', 32, 32);
|
||||
|
||||
}
|
||||
|
||||
var sprites;
|
||||
|
||||
function create() {
|
||||
|
||||
// Here we create a group, populate it with sprites, give them all a random velocity
|
||||
// and then check the group against itself for collision
|
||||
|
||||
sprites = game.add.group();
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
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);
|
||||
s.body.velocity.x = game.rnd.integerInRange(-200, 200);
|
||||
s.body.velocity.y = game.rnd.integerInRange(-200, 200);
|
||||
}
|
||||
|
||||
sprites.setAll('body.collideWorldBounds', true);
|
||||
sprites.setAll('body.bounce.x', 1);
|
||||
sprites.setAll('body.bounce.y', 1);
|
||||
sprites.setAll('body.friction', 0);
|
||||
sprites.setAll('body.minBounceVelocity', 0);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprites);
|
||||
|
||||
}
|
||||
@@ -15,14 +15,14 @@ function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
sprite1 = game.add.sprite(50, 200, 'atari');
|
||||
sprite1 = game.add.sprite(130, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.velocity.x = 100;
|
||||
|
||||
// In this example the new collision box is much larger than the original sprite
|
||||
sprite1.body.setSize(400, 50, -100, 20);
|
||||
sprite1.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
||||
sprite2 = game.add.sprite(700, 210, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
@@ -39,13 +39,13 @@ function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderRectangle(sprite1.body);
|
||||
game.debug.renderRectangle(sprite2.body);
|
||||
game.debug.renderBodyInfo(sprite1, 32, 32);
|
||||
|
||||
game.debug.renderPolygon(sprite1.body.polygons, 'rgb(255,0,0)');
|
||||
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
|
||||
|
||||
}
|
||||
|
||||
@@ -15,15 +15,13 @@ function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
sprite1 = game.add.sprite(50, 200, 'atari');
|
||||
sprite1 = game.add.sprite(150, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.velocity.x = 100;
|
||||
|
||||
// This adjusts the collision body size.
|
||||
// 100x50 is the new width/height.
|
||||
// This adjusts the collision body size to be a 100x50 box.
|
||||
// 50, 25 is the X and Y offset of the newly sized box.
|
||||
// In this case the box is 50px in and 25px down.
|
||||
sprite1.body.setSize(100, 50, 50, 25);
|
||||
sprite1.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
@@ -42,13 +40,13 @@ function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderRectangle(sprite1.body);
|
||||
game.debug.renderRectangle(sprite2.body);
|
||||
game.debug.renderBodyInfo(sprite1, 32, 32);
|
||||
|
||||
game.debug.renderPolygon(sprite1.body.polygons, 'rgb(255,0,0)');
|
||||
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
|
||||
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('tiles', 'assets/tiles/platformer_tiles.png', 16, 16);
|
||||
game.load.image('carrot', 'assets/sprites/carrot.png');
|
||||
|
||||
}
|
||||
|
||||
var tiles;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
tiles = game.add.group();
|
||||
|
||||
for (var x = 0; x < 40; x++)
|
||||
{
|
||||
var tile = tiles.create(100 + (x * 16), 300, 'tiles', 4);
|
||||
tile.body.immovable = true;
|
||||
}
|
||||
|
||||
sprite = game.add.sprite(300, 150, 'carrot');
|
||||
sprite.name = 'mushroom';
|
||||
sprite.body.collideWorldBounds = true;
|
||||
sprite.body.velocity.x = 40;
|
||||
sprite.body.velocity.y = 120;
|
||||
sprite.body.bounce.setTo(1, 1);
|
||||
|
||||
game.input.onDown.add(carryOn, this);
|
||||
|
||||
}
|
||||
|
||||
function carryOn() {
|
||||
|
||||
game.paused = false;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// object1, object2, collideCallback, processCallback, callbackContext
|
||||
game.physics.collide(sprite, tiles, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
function collisionHandler (s, t) {
|
||||
|
||||
t.alpha = 0.5;
|
||||
|
||||
console.log('---------------------------------------------');
|
||||
console.log(t.body);
|
||||
|
||||
game.paused = true;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
// game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
|
||||
game.debug.renderSpriteBody(sprite);
|
||||
// game.debug.renderSpriteBody(sprite2);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
@@ -10,12 +10,13 @@ function preload() {
|
||||
|
||||
var sprite;
|
||||
var group;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
// This will check Sprite vs. Group collision
|
||||
// This example will check Sprite vs. Group collision
|
||||
|
||||
sprite = game.add.sprite(32, 200, 'phaser');
|
||||
sprite.name = 'phaser-dude';
|
||||
@@ -24,7 +25,7 @@ function create() {
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36));
|
||||
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', game.rnd.integerInRange(0, 36));
|
||||
c.name = 'veg' + i;
|
||||
c.body.immovable = true;
|
||||
}
|
||||
@@ -32,58 +33,51 @@ function create() {
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
// Here we'll create some chillis which the player can pick-up. They are still part of the same Group.
|
||||
var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', 17);
|
||||
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', 17);
|
||||
c.name = 'chilli' + i;
|
||||
c.body.immovable = true;
|
||||
}
|
||||
|
||||
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN ]);
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite, group, collisionHandler, null, this);
|
||||
game.physics.collide(group, group);
|
||||
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
sprite.body.velocity.x = -200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
sprite.body.velocity.x = 200;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
sprite.body.velocity.y = -200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
sprite.body.velocity.y = 200;
|
||||
}
|
||||
|
||||
game.physics.collide(sprite, group, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
function collisionHandler (obj1, obj2) {
|
||||
function collisionHandler (player, veg) {
|
||||
|
||||
// If the player collides with the chillis then they get eaten :)
|
||||
// The chilli frame ID is 17
|
||||
|
||||
console.log('Hit', obj2.name);
|
||||
|
||||
if (obj2.frame == 17)
|
||||
if (veg.frame == 17)
|
||||
{
|
||||
obj2.kill();
|
||||
veg.kill();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render () {
|
||||
|
||||
// game.debug.renderQuadTree(game.physics.quadTree);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
game.load.image('flectrum', 'assets/sprites/flectrum.png');
|
||||
|
||||
}
|
||||
|
||||
var testGroup;
|
||||
var sprite1;
|
||||
var sprite2;
|
||||
var sprite3;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
game.world.setBounds(-1000, -1000, 2000, 2000);
|
||||
|
||||
testGroup = game.add.group();
|
||||
|
||||
test2();
|
||||
|
||||
}
|
||||
|
||||
function test1 () {
|
||||
|
||||
// Test 1 - 2 sprites in world space (seems to work fine with local transform?)
|
||||
sprite1 = game.add.sprite(-600, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
// sprite1.body.setSize(100, 100, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(-100, 220, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
|
||||
game.camera.focusOn(sprite1);
|
||||
game.camera.x += 300;
|
||||
|
||||
game.input.onDown.add(go1, this);
|
||||
|
||||
}
|
||||
|
||||
function test2 () {
|
||||
|
||||
// 1 sprite in world space (seems to work fine with local transform?) and 1 in a group
|
||||
|
||||
sprite1 = testGroup.create(0, -150, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.immovable = true;
|
||||
// sprite1.body.setSize(100, 100, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(-100, 140, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
|
||||
sprite3 = game.add.sprite(-200, 150, 'flectrum');
|
||||
sprite3.name = 'tall';
|
||||
|
||||
testGroup.x = -600;
|
||||
testGroup.y = 200;
|
||||
|
||||
game.camera.focusOn(sprite2);
|
||||
game.camera.x -= 300;
|
||||
|
||||
game.input.onDown.add(go2, this);
|
||||
|
||||
}
|
||||
|
||||
function go1 () {
|
||||
|
||||
sprite1.body.velocity.x = 100;
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function go2 () {
|
||||
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function update () {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
// sprite3.angle += 0.5;
|
||||
|
||||
}
|
||||
|
||||
function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
// game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
|
||||
game.debug.renderSpriteCoords(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCoords(sprite2, 300, 32);
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 32, 500);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
game.debug.renderSpriteBody(sprite3);
|
||||
|
||||
game.debug.renderGroupInfo(testGroup, 500, 500);
|
||||
game.debug.renderPixel(testGroup.x, testGroup.y, 'rgb(255,255,0)');
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ function create() {
|
||||
emitter = game.add.emitter(0, 0, 200);
|
||||
|
||||
emitter.makeParticles('diamond');
|
||||
emitter.gravity = 10;
|
||||
emitter.gravity = 200;
|
||||
|
||||
game.input.onDown.add(particleBurst, this);
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@ function create() {
|
||||
|
||||
emitter.minParticleSpeed.setTo(-200, -300);
|
||||
emitter.maxParticleSpeed.setTo(200, -400);
|
||||
emitter.gravity = 8;
|
||||
emitter.gravity = 150;
|
||||
emitter.bounce.setTo(0.5, 0.5);
|
||||
emitter.particleDrag.x = 10;
|
||||
emitter.angularDrag = 30;
|
||||
|
||||
emitter.start(false, 8000, 400);
|
||||
@@ -28,6 +27,6 @@ function create() {
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(emitter, emitter);
|
||||
game.physics.collide(emitter);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ function create() {
|
||||
flyer.body.bounce.setTo(0.8, 0.8);
|
||||
|
||||
// This sets the gravity the sprite responds to in the world, as a point
|
||||
// Leave x=0 and set y=8 to simulate falling
|
||||
flyer.body.gravity.setTo(0, 8);
|
||||
// Leave x=0 and set y=80 to simulate falling
|
||||
flyer.body.gravity.setTo(0, 80);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ function create() {
|
||||
// displays it on-screen
|
||||
// and assign it to a variable
|
||||
ball = game.add.sprite(400, 200, 'ball');
|
||||
|
||||
knocker = game.add.sprite(400, 200, 'dude');
|
||||
knocker.body.immovable = true;
|
||||
|
||||
// This gets it moving
|
||||
ball.body.velocity.setTo(200, 200);
|
||||
@@ -33,37 +35,37 @@ function create() {
|
||||
ball.body.bounce.setTo(1, 1);
|
||||
|
||||
// This sets the gravity the sprite responds to in the world, as a point
|
||||
// Here we leave x=0 and set y=8 to simulate falling
|
||||
ball.body.gravity.setTo(0, 8);
|
||||
// Here we leave x=0 and set y=80 to simulate falling
|
||||
ball.body.gravity.setTo(0, 80);
|
||||
|
||||
}
|
||||
|
||||
// Move the knocker with the arrow keys
|
||||
function update () {
|
||||
|
||||
// Enable physics between the knocker and the ball
|
||||
game.physics.collide(knocker, ball);
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
knocker.body.velocity.y = -400;
|
||||
knocker.body.velocity.y = -300;
|
||||
}
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
knocker.body.velocity.y = 400;
|
||||
knocker.body.velocity.y = 300;
|
||||
}
|
||||
else if (cursors.left.isDown)
|
||||
{
|
||||
knocker.body.velocity.x = -400;
|
||||
knocker.body.velocity.x = -300;
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
knocker.body.velocity.x = 400;
|
||||
knocker.body.velocity.x = 300;
|
||||
}
|
||||
else
|
||||
{
|
||||
knocker.body.velocity.setTo(0, 0);
|
||||
}
|
||||
|
||||
// Enable physics between the knocker and the ball
|
||||
game.physics.collide(knocker, ball);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ function create() {
|
||||
image.body.bounce.setTo(0.8, 0.8);
|
||||
|
||||
// This sets the gravity the sprite responds to in the world, as a point
|
||||
// Leave x=0 and set y=8 to simulate falling
|
||||
image.body.gravity.setTo(0, 8);
|
||||
// Leave x=0 and set y=180 to simulate falling
|
||||
image.body.gravity.setTo(0, 180);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ var launchVelocity = 0;
|
||||
function create() {
|
||||
|
||||
// set global gravity
|
||||
game.physics.gravity.y = 100;
|
||||
game.physics.gravity.y = 200;
|
||||
game.stage.backgroundColor = '#0072bc';
|
||||
|
||||
var graphics = game.add.graphics(0,0);
|
||||
|
||||
+55
-1
@@ -28,7 +28,61 @@ function create() {
|
||||
var bg = game.add.sprite(0, 0, bmd);
|
||||
bg.body.moves = false;
|
||||
|
||||
test10();
|
||||
test12();
|
||||
|
||||
}
|
||||
|
||||
function test12() {
|
||||
|
||||
// game.physics.gravity.y = 150;
|
||||
|
||||
sprite = game.add.sprite(200, 300, 'gameboy', 0);
|
||||
sprite.name = 'red';
|
||||
sprite.body.collideWorldBounds = true;
|
||||
sprite.body.checkCollision.right = false;
|
||||
// sprite.body.checkCollision.up = false;
|
||||
// sprite.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(400, 358, 'gameboy', 2);
|
||||
sprite2.name = 'green';
|
||||
sprite2.body.collideWorldBounds = true;
|
||||
sprite2.body.bounce.setTo(0.9, 0.9);
|
||||
|
||||
game.input.onDown.add(launch12, this);
|
||||
|
||||
}
|
||||
|
||||
function launch12() {
|
||||
|
||||
sprite2.body.velocity.x = -200;
|
||||
// sprite2.body.velocity.y = -60;
|
||||
|
||||
}
|
||||
|
||||
function test11() {
|
||||
|
||||
// game.physics.gravity.y = 150;
|
||||
|
||||
sprite = game.add.sprite(300, 200, 'gameboy', 0);
|
||||
sprite.name = 'red';
|
||||
sprite.body.collideWorldBounds = true;
|
||||
// sprite.body.checkCollision.down = false;
|
||||
// sprite.body.checkCollision.up = false;
|
||||
sprite.body.checkCollision.right = false;
|
||||
// sprite.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(290, 400, 'gameboy', 2);
|
||||
sprite2.name = 'green';
|
||||
sprite2.body.collideWorldBounds = true;
|
||||
sprite2.body.bounce.setTo(0.9, 0.9);
|
||||
|
||||
game.input.onDown.add(launch11, this);
|
||||
|
||||
}
|
||||
|
||||
function launch11() {
|
||||
|
||||
sprite2.body.velocity.y = -200;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('arrow', 'assets/sprites/longarrow.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var cursors;
|
||||
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#124184';
|
||||
|
||||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
sprite.body.angularVelocity = 0;
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
sprite.body.angularVelocity = -100;
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
sprite.body.angularVelocity = 100;
|
||||
}
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderBodyInfo(sprite, 16, 24);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var sprite2;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#124184';
|
||||
|
||||
// Here we're tweening the scale of the sprite, which translates to the scale of the Body as well
|
||||
// The collision will carry on working even against the scaled body.
|
||||
|
||||
sprite = game.add.sprite(200, 300, 'gameboy', 2);
|
||||
sprite.name = 'green';
|
||||
// sprite.anchor.setTo(0.5, 0.5);
|
||||
sprite.body.immovable = true;
|
||||
|
||||
sprite2 = game.add.sprite(600, 300, 'gameboy', 3);
|
||||
sprite2.name = 'yellow';
|
||||
sprite2.body.rebound = false;
|
||||
|
||||
// sprite2.body.velocity.x = -200;
|
||||
|
||||
game.add.tween(sprite2).to( { x: 0 }, 3000, Phaser.Easing.Linear.None, true);
|
||||
|
||||
// game.add.tween(sprite.scale).to( { x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite, sprite2);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderPolygon(sprite.body.polygons, 'rgb(255,0,0)');
|
||||
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
|
||||
|
||||
}
|
||||
+10
-15
@@ -15,7 +15,7 @@ var platform;
|
||||
function create() {
|
||||
|
||||
// Our ball sprite
|
||||
ball = game.add.sprite(420, 100, 'wizball');
|
||||
ball = game.add.sprite(440, 100, 'wizball');
|
||||
ball.anchor.setTo(0.5, 0.5);
|
||||
|
||||
ball.body.customSeparateX = true;
|
||||
@@ -42,25 +42,20 @@ function update() {
|
||||
circle.y = ball.y;
|
||||
|
||||
// This is a rect vs. rect collision. The callback will check the circle.
|
||||
game.physics.overlap(ball, platform, null, processCallback, this);
|
||||
game.physics.overlap(ball, platform, collisionCallback, processCallback, this);
|
||||
|
||||
}
|
||||
|
||||
function collisionCallback(a, b) {
|
||||
|
||||
ball.body.y -= 10;
|
||||
ball.body.velocity.y *= -1 * ball.body.bounce.y;
|
||||
|
||||
}
|
||||
|
||||
function processCallback(a, b) {
|
||||
|
||||
// console.log('p', a.y, b.y);
|
||||
|
||||
if (Phaser.Circle.intersectsRectangle(circle, platform.body))
|
||||
{
|
||||
console.log('boom', ball.body.overlapX, ball.body.overlapY);
|
||||
// ball.body.x = ball.body.x - ball.body.overlapX;
|
||||
// ball.body.velocity.x = platform.body.velocity.x - ball.body.velocity.x * ball.body.bounce.x;
|
||||
|
||||
ball.body.y -= 10;
|
||||
ball.body.velocity.y *= -1 * ball.body.bounce.y;
|
||||
}
|
||||
|
||||
return true;
|
||||
return (Phaser.Circle.intersectsRectangle(circle, platform.body));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
<meta charset="UTF-8" />
|
||||
<title>phaser</title>
|
||||
<base href="../"></base>
|
||||
<script src="wip/SAT.js" type="text/javascript"></script>
|
||||
<?php
|
||||
require('../../build/config.php');
|
||||
|
||||
|
||||
+13
-49
@@ -1,76 +1,40 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
|
||||
game.load.image('ball', 'assets/sprites/shinyball.png');
|
||||
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
||||
game.load.spritesheet('spinner', 'assets/sprites/bluemetal_32x32x4.png', 32, 32);
|
||||
|
||||
}
|
||||
|
||||
var gameboy;
|
||||
var sprites;
|
||||
var bmd;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#124184';
|
||||
|
||||
bmd = game.add.bitmapData(800, 600);
|
||||
bmd.fillStyle('#ffffff');
|
||||
var bg = game.add.sprite(0, 0, bmd);
|
||||
bg.body.moves = false;
|
||||
|
||||
game.physics.gravity.y = 250;
|
||||
// game.physics.gravity.x = 250;
|
||||
// Here we create a group, populate it with sprites, give them all a random velocity
|
||||
// and then check the group against itself for collision
|
||||
|
||||
sprites = game.add.group();
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'ball');
|
||||
s.body.velocity.x = game.rnd.integerInRange(-400, 400);
|
||||
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);
|
||||
s.body.velocity.x = game.rnd.integerInRange(-200, 200);
|
||||
s.body.velocity.y = game.rnd.integerInRange(-200, 200);
|
||||
s.name = 'ball' + i;
|
||||
}
|
||||
|
||||
sprites.setAll('body.collideWorldBounds', true);
|
||||
sprites.setAll('body.bounce.x', 0.9);
|
||||
sprites.setAll('body.bounce.y', 0.9);
|
||||
sprites.setAll('body.minBounceVelocity', 0.8);
|
||||
|
||||
gameboy = game.add.sprite(300, 50, 'gameboy', 0);
|
||||
gameboy.name = 'gameboy';
|
||||
gameboy.body.collideWorldBounds = true;
|
||||
gameboy.body.bounce.setTo(0.9, 0.9);
|
||||
gameboy.body.velocity.x = game.rnd.integerInRange(-400, 400);
|
||||
gameboy.body.velocity.y = game.rnd.integerInRange(-200, 200);
|
||||
sprites.setAll('body.bounce.x', 1);
|
||||
sprites.setAll('body.bounce.y', 1);
|
||||
sprites.setAll('body.friction', 0);
|
||||
sprites.setAll('body.minBounceVelocity', 0);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(gameboy, sprites);
|
||||
game.physics.collide(sprites);
|
||||
|
||||
// sprite.rotation = sprite.body.angle;
|
||||
|
||||
// if (sprite)
|
||||
// {
|
||||
// bmd.fillStyle('#ffff00');
|
||||
// bmd.fillRect(sprite.body.center.x, sprite.body.center.y, 2, 2);
|
||||
// }
|
||||
|
||||
// if (sprite2)
|
||||
// {
|
||||
// bmd.fillStyle('#ff00ff');
|
||||
// bmd.fillRect(sprite2.body.center.x, sprite2.body.center.y, 2, 2);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user