palra Posted January 10, 2014 Share Posted January 10, 2014 Hi, I just started learning Phaser, and I tried to make a simple game with a tilemap and a player with Typescript. The problem is when I start moving the character with the directionnal keys, it moves alone, randomly. I don't understand, because it worked well, and I didn't changer anything in the code. Here it is : http://pastebin.com/c92HWUq9. I'll try to put online my local version of the game. What could be the problem ? Thanks ! Link to comment Share on other sites More sharing options...
rich Posted January 11, 2014 Share Posted January 11, 2014 What actually happens? The sprite carries on moving after you press a key? If so it's because when you apply acceleration to a sprite it gets translated to velocity, and velocity will carry on influencing the motion until it is set to zero, which can happen either explicitly in your code, or be reduced to that via collision / drag. Link to comment Share on other sites More sharing options...
palra Posted January 11, 2014 Author Share Posted January 11, 2014 No, I have set acceleration and drag values witch were correct before that "bug", I don't even know if it's a bug or an error in my code. It really moves very randomly once I start moving my sprite. I just noticed that it only occurs in Chrome for Linux, not in Firefox, everything runs absolutely normally. Here's the demo : http://palra.github.io/extremecrashsaga/ Thanks for the reply ! Link to comment Share on other sites More sharing options...
ZRT Posted January 11, 2014 Share Posted January 11, 2014 Try moving with velocity, not acceleration and see what happens. And put it like this in your update() function:this.body.velocity.x = 0;this.body.velocity.y = 0; Link to comment Share on other sites More sharing options...
palra Posted January 12, 2014 Author Share Posted January 12, 2014 So, I tried with your method ZRT, it works, the sprite moves normally, but that's not what I'm expecting. In Chrome, it moves at a normal speed, but in Firefox it moves 10x slower. On Chrome, the game's refresh rate is very low, so movements looks very laggy, and in Firefox, the refresh rate is normal, so I think that it could explain the rapidity of movements in differents browsers. I just were wondering why that "bug" can only be observed in Chrome, I run this game on differents systems and computers, the results is always the same : laggy in Chrome, normal in other cases. Why ? Link to comment Share on other sites More sharing options...
rich Posted January 12, 2014 Share Posted January 12, 2014 The link you posted above is running at a solid 60fps for me in Chrome (v32). Nice idea of adding the UI controls to change the physics motion Link to comment Share on other sites More sharing options...
jcs Posted January 13, 2014 Share Posted January 13, 2014 I get extremely low frame-rates on a reasonably fast laptop (gets ~60fps for most games) - in the range from under 10 to around 25. running linux, both chrome 31 and firefox 26 while I don't know what the cause of the low frame-rate is, it is the cause of the strange behaviour: the tiles are relatively small compared to the sprite, and when the frame-rate is low (and the sprite's velocity is high) the sprite can move quite far into a tile before game code is called and the physics code "separates" the sprite from the tile. by that point the sprite is already closer to the other side of the tile and is pushed "through" the tile rather than "out" of it. if the tile is at the edge of the world (and the sprite is not allowed to leave the world) then the sprite becomes "embedded" in the tiles and when the physics engine tries to separate it out it ends up pushing it into another tile (and another and another) which makes the sprite "zoom" across the screen. (I've experienced all these same problems with low frame-rates on slower devices) Link to comment Share on other sites More sharing options...
jcs Posted January 13, 2014 Share Posted January 13, 2014 by shrinking the browser window considerably I was able to get the frame-rate up to around 60fps. I noticed that Phaser was using canvas rendering, which is considerably slower on this machine than webgl, so using webgl and/or a smaller window are probably good options. once I had the frame-rate up I noticed that your physics values are all extremely high - ranging in the thousands for many values that I "normally" see in the tens or hundreds. by using your controls to push max velocity down to under 100 (x and y, obviously), I was able to get the sprite to start behaving more sanely (stopped "sliding" around on its own etc). jumping wasn't right (jumps were much too small) but I couldn't tweak that without changing the code. in short I'd recommend: use 'auto' for the renderer (which will choose webgl when available), use a smaller game 'window', and push your physics values way down. good luck! Link to comment Share on other sites More sharing options...
rich Posted January 13, 2014 Share Posted January 13, 2014 Also, see the post I'm about to make in the forum about helping to test the new tilemap system + physics Link to comment Share on other sites More sharing options...
Recommended Posts