actes

performance issue using arcade physics on mobile

Recommended Posts

Hello, 

I've tried to code a FlappyBird-clone in phaser but i have performance issues on mobile devices. When I run the game everything works fine but when the player falls (because of the gravity), it doesn't seem "smooth" anymore and the game lags. I've run the game on a LG G3 and a Sony Xperia Z.

thanks in advance:D

var game = new Phaser.Game(288, 512, Phaser.WEBGL);

var mainState = {
    preload: function() {
        game.load.image('flappy' ,'img/flappy.png');
        game.load.image('bg' ,'img/bg.png');
        game.load.image('btn' ,'img/btn.png');
        game.load.image('ground' ,'img/ground.png');
    },
    create: function() {
        game.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;
        
        game.physics.startSystem(Phaser.Physics.ARCADE);
        
        this.bg = game.add.sprite(0, 0, 'bg');
        
        this.ground = game.add.sprite(0, game.height - 112, 'ground');
        
        game.physics.arcade.enableBody(this.ground);
        this.ground.body.immovable = true;
        
        this.player = game.add.sprite(game.world.centerX, game.world.centerY, 'flappy');
        this.player.anchor.set(0.5);
        
        game.physics.arcade.enableBody(this.player);
        this.player.body.bounce.set(0.2);
        this.player.body.gravity.y = 500;
        
        game.input.onTap.add(this.jump, this);
    },
    update: function() {
        game.physics.arcade.collide(this.player, this.ground);
    },
    jump: function() {
        this.player.body.velocity.y = -200;
    }
};

game.state.add('main', mainState);
game.state.start('main');

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.