Page 1 of 1

xvelocity vs. x+=

PostPosted: Sat May 14, 2011 3:39 am
by 157pl
is it better to use xvelocity or x+= when moving an actor
is one faster than another

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 3:59 am
by Pattrick
xvelocity would cause the actor to keep moving when you let go of the key. x=x+ causes it to stop when you let go of the key when jumping left or right.

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 4:31 am
by 157pl
i know that just ad a xvelocity=0 on key up
but is xvelocity faster prosesor wise




r u knew i dont think i have ever seen u before

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 4:38 am
by Pattrick
I think it is the same.




I started a few days ago.

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 6:06 am
by skydereign
It depends on what you are doing. xvelocity is good for things that don't use PhysicalResponse. It also provides an easy way of handling acceleration. If you are doing a keydown event with repeat enabled though, you shouldn't use xvelocity just because it is unnecessary.

Using x+= is easier for most player controls that avoid moonwalking, and it also overcomes that problem with PhysicalResponse. Also to note, x+= can do what xvelocity can, but not exactly the other way around. In truth though, it really depends on what you are doing, and your coding preferences.

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 1:04 pm
by Game A Gogo
If you are going to make your own physic engine, you'll most likely use xvelocity and yvelocity. Since it works with real-life physics where the force vector becomes xvelocity and yvelocity

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 8:51 pm
by Rux
x+= 1 Simply means it will move the actor one pixel to the right after the even occurs, while xvelocity += 1 will continuously move the actor one pixel to the right, even after the event has already occurred. They are two completely different things.

Re: xvelocity vs. x+=

PostPosted: Sat May 14, 2011 10:29 pm
by lcl
Now that there is conversion about xvelocity and x +=, I wanted to share this with you.
I found a nice, simple way to make things like using xvelocity, but still with x +=.

1. Make real actor variable called xvel.
2. This goes to actors draw actor code:
Code: Select all
x += xvel;

3. And now use xvel just as if you were using xvelocity.

This way the effect will be same but physicalResponse() won't mess it up.
Simple but working. :)

Re: xvelocity vs. x+=

PostPosted: Sun May 15, 2011 7:18 pm
by savvy
yes, as lcl was saying in the final post i think. you can still do xvelocity or yvelocity using x or y += by using a vatiable, this is useful because it menas that physical response doesnt stop movement. it can be used as so..

(key right)
Code: Select all
speed+=1;

(key left)
Code: Select all
speed-=1;

(draw actor)
Code: Select all
x+=speed;


it has issues with stopping when it hits something when like this though, so you would need to set it to 0 or use speed-=1 when it hits things its supposed to stop on.

xvelocity and yvelocity are a constant speed in a y and x directions, adding or taking from this changes that speed and physical response makes a direct change to it.

i personally only use x and y velocity for things like jumping, then x+=speed or x+=xvel or something along those lines for movement. :D

probably not helpful but wth :P

savvy