Jump to content

Simple phaser game lag on Android


georgenasr87
 Share

Recommended Posts

Hi,

I'm developing an html5 game using phaser + cocoonjs. So far there is only 1 sprite with velocity set, so basically it just moves from right to left. As simple as it sounds, running this on android device (and sometimes in chrome) I noticed that the sprite doesn't move smoothly, it's laggy!

 

I'm not sure if there is a better way to animate the sprite that makes it smooth.

 

Here is the code I have, I also attached the full application.

 

 

/// <reference path="js/phaser.min.js" />
var w = window.innerWidth;
var h = window.innerHeight;
 
var game = new Phaser.Game(w, h, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var speed = -250;
 
function preload() {
    game.load.image('trainHead', 'img/trainHead3.png');
}
 
function create() {
    var globalY = game.world.height / 3;
    trainUnitHeight = h / 8;
    trainUnitWidth = w / 5;
 
    // Train head
    trainHead = game.add.sprite(game.world.width, globalY, 'trainHead');
    trainHead.anchor.setTo(0.5);
    SetDimensions(trainHead, trainUnitWidth, trainUnitHeight);
    game.physics.arcade.enable(trainHead);
    trainHead.body.velocity.x = speed;
}
 
function update() {
}
 
function SetDimensions(sprite, width, height) {
    sprite.width = width;
    sprite.height = height;
}
 
 
Any help/suggestions are greatly appreciated! Thanks!!

repro.zip

Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

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