janmagaraes Posted March 18, 2014 Share Posted March 18, 2014 After upgrading my little game from Phaser 1.3 to 2.0 started having an issue with collision and scaling. I have an Image that represents the ground (400x32) which belongs to the group "platform". If game.world.width is bigger than 400px, lets say 600, the scaling works fine, but the character will never walk way long the ground and will fall beyond the width x = 400 .if game.world.width is equals 400px everything works fine. Here is the relevant code:function create() { // A simple background for our game game.add.sprite(0, 0, 'sky'); //auto resize and size limits game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.scale.minWidth = 480; game.scale.minHeight = 260; game.scale.maxWidth = 1024; game.scale.maxHeight = 768; game.scale.forceLandscape = true; game.scale.pageAlignHorizontally = true; game.scale.setScreenSize(true); //game.physics.startSystem(Phaser.Physics.ARCADE); // The platforms group contains the ground and the 2 ledges we can jump on platforms = game.add.group(); // Here we create the ground. ground = platforms.create(0, game.world.height - 64, 'ground'); game.physics.enable(ground, Phaser.Physics.ARCADE); // Scale it to fit the width of the game (the original sprite is 400x32 in size) ground.scale.setTo(2, 2); // This stops it from falling away when you jump on it ground.body.immovable = true; function update() { for (var i = 0; i < enemyArray.length; i++) { if (enemyArray[i].alive) { game.physics.arcade.overlap(bullets, enemyArray[i].enemy, bulletHitEnemy , null, this); game.physics.arcade.collide(enemyArray[i].enemy, platforms); } enemyArray[i].update(); if(enemyArray[i].enemy.body.x == 0){ enemyArray[i].reset() } } /*if(n_enemy_alive ==0){ createEnemy(n_enemy); }*/ displayText(n_enemy_alive);What I am missing? Link to comment Share on other sites More sharing options...
rich Posted March 19, 2014 Share Posted March 19, 2014 Can you scale the ground and THEN enable physics for it, and see if it works that way around please? janmagaraes 1 Link to comment Share on other sites More sharing options...
jyapayne Posted March 19, 2014 Share Posted March 19, 2014 Add this after the scale.setTo call:ground.body.updateBounds(ground.scale.x, ground.scale.y); Link to comment Share on other sites More sharing options...
Larzan Posted May 9, 2015 Share Posted May 9, 2015 As of 2.3 you can use setScale to scale a Layer while automatically adapting the collision boundries.More detail here: GitHub Link to comment Share on other sites More sharing options...
Recommended Posts