Jump to content

Phaser 2.x - Image is scaled to fit the screen but collision only work in some parts


janmagaraes
 Share

Recommended Posts

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

  • 1 year later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...