So i made my player jump and everything is fine and dandy.But when i look very close to his jump its not very fluent. He looks like hes climbing stairs.This is cause i use moveBy (awesome function )and hes y is always a int number.Can i solve this,or make moveBy update player movement with a number not a int? Thx
MoveBy() but with number not int?
moveBy()
already takes Number
s as parameters.
Although at first sight it can seem that it rounds to int
s to update the position, if you look closer at the code you can see that it internally stores the fractional part of the movement so that it can apply it the next time.
Maybe you’re rounding the position in some other place, or not using moveBy
consistently across code?!
Im using velocity and update y position using moveBy().The only change i make to y is by using moveBy and i allways have a round number as player’s coordinates.So…i actually can just go in moveBy function and change it for the player to update with a number not a int?
Now that i look at moveBy’s description it says it retain hes integer position…but still getting just round coordinates for player’s x and y
Yes!
It’ll always round your y
to int
(just because you can’t draw at 13.238 - i.e. at a fractional pixel), but will add the fractional part from the previous step before rounding so that the movement can look fluid.
See this (start of Entity.moveBy()
):
_moveX += x;
_moveY += y;
x = Math.round(_moveX);
y = Math.round(_moveY);
_moveX -= x;
_moveY -= y;
...
Can you share an swf to show the behaviour?
ok so here is a sample …btw console is “i” and then"o"(sry for that…) If u enter in the console u can see player has always round values at coordinates) sample.swf (59.6 KB)
Oh i got it. I looked in the code at moveBy…it is right,_moveY and X saves the 0.something part of the number.But i can only see that the this.x and this.y is updated by the x and y values(the round ones).
this.x += x;
this.y += y;
So… all i had to do is to add the _moveY and _moveX to them.Am i right?
The jumping looks fine to me. Are you using variable framerate (FP.elapsed)? Maybe it behaves differently on different computers.