MoveBy() but with number not int?


(billy2000) #1

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 :smile: )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 :smile:


(azrafe7) #2

moveBy() already takes Numbers as parameters.

Although at first sight it can seem that it rounds to ints 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?!


(billy2000) #3

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?


(billy2000) #4

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


(azrafe7) #5

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?


(billy2000) #6

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)


(Jacob Albano) #7

I pressed every button on my keyboard and couldn’t get him to jump.


(billy2000) #8

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?


(billy2000) #9

Oh sry…its “L”…forgot to telll…sry again >.<


(Jacob Albano) #10

The jumping looks fine to me. Are you using variable framerate (FP.elapsed)? Maybe it behaves differently on different computers.


(billy2000) #11

no,Im using fixed framerate.


(billy2000) #12

also the scale of the game is x2 …if this has any relevance…