Fixed issues with the contacts and world bounds. New labs demo created.

This commit is contained in:
photonstorm
2014-02-20 04:21:14 +00:00
parent 9fcab5ef26
commit 91c0299d4c
4 changed files with 195 additions and 36 deletions
+5 -3
View File
@@ -23,14 +23,15 @@ function create() {
bg = game.add.tileSprite(0, 0, 800, 600, 'background');
bg.fixedToCamera = true;
// game.physics.gravity.y = 20;
game.physics.gravity.y = 20;
game.physics.friction = 0.5;
game.physics.setBoundsToWorld();
// game.physics.setBoundsToWorld();
var playerCG = game.physics.createCollisionGroup();
var boxCG = game.physics.createCollisionGroup();
player = game.add.sprite(50, 550, 'dude');
player.name = 'player';
player.physicsEnabled = true;
player.body.fixedRotation = true;
player.body.setCollisionGroup(playerCG);
@@ -44,6 +45,7 @@ function create() {
for (var i = 0; i < 10; i++)
{
var box = boxes.create(200 + (i * 50), 550, 'box');
box.name = 'box' + i;
box.scale.set(0.5);
box.physicsEnabled = true;
box.body.setCollisionGroup(boxCG);
@@ -62,7 +64,7 @@ function create() {
function gotBox(body1, body2, shape1, shape2) {
console.log('gotBox');
console.log('gotBox', body1.sprite.name, body2.sprite.name);
body2.sprite.kill();
+12 -24
View File
@@ -1,5 +1,6 @@
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.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, render: render });
function preload() {
@@ -24,26 +25,14 @@ function create() {
bg = game.add.tileSprite(0, 0, 800, 600, 'background');
bg.fixedToCamera = true;
// map = game.add.tilemap('level1');
game.physics.gravity.y = 20.0;
// map.addTilesetImage('tiles-1');
game.world.setBounds(0, 0, 2000, 600);
// map.setCollisionByExclusion([ 13, 14, 15, 16, 46, 47, 48, 49, 50, 51 ]);
// layer = map.createLayer('Tile Layer 1');
// Un-comment this on to see the collision tiles
// layer.debug = true;
// layer.resizeWorld();
// game.physics.setBoundsToWorld();
// game.physics.gravity.y = 9.78;
game.physics.setBoundsToWorld(true, true, false, true, false);
game.physics.world.gravity[1] = -20;
game.physics.friction = 0.5;
game.physics.enableBodySleeping = true;
game.physics.world.solver.stiffness = 1e20;
game.physics.world.solver.relaxation = 3;
@@ -65,12 +54,12 @@ function create() {
boxes = game.add.group();
for (var i = 0; i < 50; i++)
for (var i = 0; i < 100; i++)
{
var box = boxes.create(game.rnd.integerInRange(200, 700), game.rnd.integerInRange(-200, 400), 'box');
// box.scale.set(0.5);
box.scale.set(game.rnd.realInRange(0.2, 0.7));
var box = boxes.create(game.rnd.integerInRange(200, 1700), game.rnd.integerInRange(-200, 400), 'box');
box.scale.set(game.rnd.realInRange(0.2, 0.6));
box.physicsEnabled = true;
box.body.allowSleep = true;
box.body.mass = 10;
box.body.setMaterial(boxMaterial);
box.body.fixedRotation = true;
@@ -83,10 +72,7 @@ function create() {
var boxCharacterCM = game.physics.createContactMaterial(boxMaterial, characterMaterial, { friction: 0.0 }); // No friction between character and boxes
var boxGroundCM = game.physics.createContactMaterial(boxMaterial, groundMaterial, { friction: 0.6 }); // Between boxes and ground
console.log(groundCharacterCM);
console.log(boxGroundCM);
// game.camera.follow(player);
game.camera.follow(player);
cursors = game.input.keyboard.createCursorKeys();
jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
@@ -95,6 +81,8 @@ function create() {
function update() {
bg.tilePosition.x = -game.camera.view.x;
if (cursors.left.isDown)
{
player.body.moveLeft(200);