ashes999 Posted October 2, 2014 Share Posted October 2, 2014 I started using this excellent Phaser tutorial: http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game I skipped to part nine. I added a method called createStar(), which I call twice when a user collects a star: function collectStar (player, star) { // Removes the star from the screen star.kill(); createStar(Math.random() * (800 - 96)) createStar(Math.random() * (800 - 96)) // Add and update the score score += 10; scoreText.text = 'Score: ' + score;}function createStar(x) { // Create a star inside of the 'stars' group var star = stars.create(x + (Math.random() * 60) - 30, 0, 'star'); // Let gravity do its thing star.body.gravity.y = 100; // This just gives each star a slightly random bounce value star.body.bounce.y = 0.4 + Math.random() * 0.2; if (starsText !== 'undefined'&& starsText != null && stars != 'undefined' && stars != null) { starsText.text = 'Stars: ' + stars.total; }}(Note: in the initial for-loop, pass in i * 70 to reproduce the original behaviour.) As you can imagine, eventually, you can get to lots and lots of stars. On my Ubuntu VM, I clock in around 800 stars before the FPS drops to 30. Some observations:- The game stutters when I move into a place where I collect a ton of stars -- looks like the collision handling- Once I reach around 10-15 FPS (first noticed at 13 FPS), I sometimes try to jump onto the bottom platform but fall through instead. Is this a bug? In other frameworks, when you control the update call, you can usually call it with a small value if a large amount of time elapses, eg. if one second passed since the last call, you advance game time by calling update(100ms) ten times. This is supposed to be the fix for high-speed (or low-FPS) physics. Full PasteBin is here: http://pastebin.com/TpjQrxAQ Link to comment Share on other sites More sharing options...
xerver Posted October 2, 2014 Share Posted October 2, 2014 Basically, with the way physics are implemented in Arcade that is gonna happen sometimes. The only 100% way to prevent this is to implement continuous collision detection (ccd) which is I believe out of scope for what arcade physics is trying to accomplish. Link to comment Share on other sites More sharing options...
ashes999 Posted October 2, 2014 Author Share Posted October 2, 2014 If that's true, is there a different physics engine that solves this problem? Not being able to guarantee stable physics at low framerates is pretty problematic, what with the large range of available phone hardware (not to mention PC/web). Link to comment Share on other sites More sharing options...
xerver Posted October 2, 2014 Share Posted October 2, 2014 The only one I know of that actually uses CCD right now is Box2D, and it is pretty beefy and not natively integrated into Phaser so you will need to integrate on your own. Link to comment Share on other sites More sharing options...
Recommended Posts