Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Sprites moves alone


palra
 Share

Recommended Posts

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

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

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

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...