izimoo

game.input event reduces framerate on mobile

Recommended Posts

I am pretty new to Phaser and enjoy it very much, and also use cocoonjs to test on a mobile device.

If I have any game.input event - like "game.input.onDown.add (function)" etc, in the update function, after a minute or so of no activity (on the mobile) my framerate goes through the floor. I am wondering why this might be.  I can add a timer to test for activity and pause the game, but I am curious if I am doing something wrong.

Below, is my html file - if I zip the html and phaser.min file, and open it on my iPhone and don't do anything it starts at 60fps.  Then after about a minute or so of inactivity, the framerate drops to 20+

Tested on various Phaser versions, including 2.4.4

<doctype html>
<html>
<head>
<meta/>
<title>test</title>
<script src="phaser.min.js"></script>
<body>
<script type="text/javascript">

var game = new Phaser.Game(320, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload() {
}

function create() {
}

function update () {
  game.input.onTap.add(function(){
    console.log("tapped")
  });
}

</script>
</body>
</html>

Share this post


Link to post
Share on other sites

You shouldn't add that event listener in the update function.  Each time it loops it's going to be adding yet another listener, and this will eat up memory very fast.  Move that code into your create function.  Should help a lot, as the listener only needs to get added once to work.

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.