izimoo Posted February 11, 2016 Share Posted February 11, 2016 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> Link to comment Share on other sites More sharing options...
fillmoreb Posted February 11, 2016 Share Posted February 11, 2016 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. Link to comment Share on other sites More sharing options...
izimoo Posted February 11, 2016 Author Share Posted February 11, 2016 Thank you very much, that worked a treat. It is obvious now that you say it :-) I just got a bit confused looking at some of the examples and stuck it in the wrong place. Link to comment Share on other sites More sharing options...
fillmoreb Posted February 11, 2016 Share Posted February 11, 2016 Not a problem. Link to comment Share on other sites More sharing options...
Recommended Posts