mariogarranz Posted October 4, 2013 Share Posted October 4, 2013 Hi there. First of all, I would like to thank Rich and the people of the Phaser team for this great framework. I just finished my first game with it and it was really helpful. One thing that I noticed while coding the game was that having my game character jump, giving him some acceleration on the Y axis, would cause different jump heights depending on the speed of the computer running the game. I guess this is because the physics are not calculated based on the timestep between each call to the update() loop, having more powerful computers to apply gravity faster than less powerful ones.Am I right about this? or maybe I am doing something wrong? Is there any way to fix this, other than implementing my own physics?Thanks in advance for your help Link to comment Share on other sites More sharing options...
rich Posted October 4, 2013 Share Posted October 4, 2013 It depends how you were making him jump There is a delta timer value in game.time that you can apply to any custom motion code to ease the value out. Also which game did you make??? Link to comment Share on other sites More sharing options...
mariogarranz Posted October 4, 2013 Author Share Posted October 4, 2013 The method I used was: 1) Add some gravity to the player sprite body:player.body.gravity.y = PLAYER_GRAVITY;2) On the update() loop, if the up key is pressed, add some speed to the player on the Y axis: if(game.input.keyboard.isDown(keys.UP)){ if(!jump){ player.velocity.y = -JUMP_ACCEL; jump = true; .... }} So I'm just letting the physics engine do the maths on the gravity. Is that wrong? It is just a simple mini game that I came up with just to learn Phaser. I started with Jesse Freeman's Phaser tutorial, but since the code was mostly outdated and it was too simple, I ended with a complete mini game trying Phaser examples and reading some info on this forum. You can try it here: https://dl.dropboxusercontent.com/u/18980037/bringiton/index.html Thank you very much for your help. shawnbless 1 Link to comment Share on other sites More sharing options...
rich Posted October 4, 2013 Share Posted October 4, 2013 Hah that's great fun mariogarranz 1 Link to comment Share on other sites More sharing options...
Jesse Freeman Posted October 4, 2013 Share Posted October 4, 2013 That's awesome! I like the new sprite animations. It's on my list to go back and update the Intro tutorial. Someone went and removed TypeScript support which forces me to have to rewrite the entire thing now mariogarranz and shawnbless 2 Link to comment Share on other sites More sharing options...
Jorasso Posted October 4, 2013 Share Posted October 4, 2013 For problems with gravity you mentioned I recommend this article:http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html shawnbless and mariogarranz 2 Link to comment Share on other sites More sharing options...
mariogarranz Posted October 4, 2013 Author Share Posted October 4, 2013 Thanks Jesse, but to be honest the new sprites suck compared to the swift animation of the player you had For problems with gravity you mentioned I recommend this article:http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html That's quite an interesting article. I was looking at this one, quite similar, before:http://gafferongames.com/game-physics/fix-your-timestep/ That's why I was asking if I should code the jump physics myself, or if I was just doing it wrong and there was another way so that just adding gravity would work at the same speed on every device. DWboutin 1 Link to comment Share on other sites More sharing options...
alex_h Posted October 4, 2013 Share Posted October 4, 2013 Yeah that http://gafferongames.com/ article is amazing, it revolutionised my understanding of how to handle physics time steps.Prior to reading it I was experiencing exactly the same problem you described, whereby the player would jump differently on different devices.Once I implemented the 'time accumulator' system from the article the jump worked identically across the various different targets I tested on. Link to comment Share on other sites More sharing options...
rich Posted October 4, 2013 Share Posted October 4, 2013 0.95 used a subdivided timestep, but it caused such jerky/irregular movement on mobile I removed it for 1.0. Looking at the code though I realise we do use an integrated velocity (you can see this in updateMotion) but for some reason the integration was never completed, so I've added that in to 1.0.7-dev just now RestingCoder and mariogarranz 2 Link to comment Share on other sites More sharing options...
mariogarranz Posted October 4, 2013 Author Share Posted October 4, 2013 Thank you very much Rich, that solved my question.This framework has the best support I've ever seen Link to comment Share on other sites More sharing options...
rich Posted October 4, 2013 Share Posted October 4, 2013 I'm tempted to try out an RK4 based timestep (which is what the gafferongames approach uses) but will wait for 1.0.8 to go into dev first. In my experience it's only really helped on desktop and generally caused issues on mobile (where frame rates are already really low), but I'll definitely give it another shot. Link to comment Share on other sites More sharing options...
claire Posted October 8, 2013 Share Posted October 8, 2013 Hi, I am facing a problem here.update and render function only work if the browser tab is selected, if I navigate my mouse to other tab or other program, update and render will stop, but the timer will keep going. I am doing a game which need update and render function to keep going if I move my cursor out of that page. Is there any solution? Link to comment Share on other sites More sharing options...
mariogarranz Posted October 8, 2013 Author Share Posted October 8, 2013 Hi, I am facing a problem here.update and render function only work if the browser tab is selected, if I navigate my mouse to other tab or other program, update and render will stop, but the timer will keep going. I am doing a game which need update and render function to keep going if I move my cursor out of that page. Is there any solution? Hi claire.Actually this question is not related to the original question on this thread. I guess it would be a better idea to open a new thread to talk about this so that if someone finds the same problem he or she may be able to find the solution easier. Anyway, since there is no complete documentation yet I'm not sure of the way pause works, but if you check the Stage class code, you will see this: visibilityChange: function (event) { if (this.disableVisibilityChange) { return; } if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) { // console.log('visibilityChange - hidden', event); this.game.paused = true; } else { // console.log('visibilityChange - shown', event); this.game.paused = false; } },So, it seems like there is a boolean property of the game stage called "disableVisibilityChange" that, if set to true, ignores tab change events on your browser. My guess is this should solve your problem:game.stage.disableVisibilityChange = true; Link to comment Share on other sites More sharing options...
claire Posted October 8, 2013 Share Posted October 8, 2013 It's working great! Thanks Attanar! Link to comment Share on other sites More sharing options...
fatcat Posted November 21, 2013 Share Posted November 21, 2013 Hi @mariogarranz Any chance you'd share the source? Thanks salvan13 1 Link to comment Share on other sites More sharing options...
salvan13 Posted November 29, 2013 Share Posted November 29, 2013 Hello everyone, I'm testing for the first time the framework, I have the same issue described here, but I don't understand the solution.This is my test:http://178.79.164.246/g/(if I open firefor element inspector the player jump very high!!) What am I doing wrong?Thx very much!!! Link to comment Share on other sites More sharing options...
jcs Posted November 29, 2013 Share Posted November 29, 2013 try using Phaser 1.1.3. the issue was addressed in the dev branch on Nov 5th and I believe 1.1.2 was released on the 1st salvan13 1 Link to comment Share on other sites More sharing options...
salvan13 Posted November 29, 2013 Share Posted November 29, 2013 thx very much, it works with Phaser 1.1.3 Link to comment Share on other sites More sharing options...
Recommended Posts