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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.