xvelocity vs. x+=

Game Editor comments and discussion.

xvelocity vs. x+=

Postby 157pl » Sat May 14, 2011 3:39 am

is it better to use xvelocity or x+= when moving an actor
is one faster than another
User avatar
157pl
 
Posts: 109
Joined: Thu May 13, 2010 10:49 pm
Location: AZ
Score: 3 Give a positive score

Re: xvelocity vs. x+=

Postby Pattrick » Sat May 14, 2011 3:59 am

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.
User avatar
Pattrick
 
Posts: 9
Joined: Sun May 08, 2011 6:40 am
Location: Chicago
Score: 1 Give a positive score

Re: xvelocity vs. x+=

Postby 157pl » Sat May 14, 2011 4:31 am

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
User avatar
157pl
 
Posts: 109
Joined: Thu May 13, 2010 10:49 pm
Location: AZ
Score: 3 Give a positive score

Re: xvelocity vs. x+=

Postby Pattrick » Sat May 14, 2011 4:38 am

I think it is the same.




I started a few days ago.
User avatar
Pattrick
 
Posts: 9
Joined: Sun May 08, 2011 6:40 am
Location: Chicago
Score: 1 Give a positive score

Re: xvelocity vs. x+=

Postby skydereign » Sat May 14, 2011 6:06 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: xvelocity vs. x+=

Postby Game A Gogo » Sat May 14, 2011 1:04 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: xvelocity vs. x+=

Postby Rux » Sat May 14, 2011 8:51 pm

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.
I'm not good at coming up with signatures...
User avatar
Rux
 
Posts: 645
Joined: Sun Apr 29, 2007 9:26 pm
Location: Sitting on your moniter invisable.
Score: 35 Give a positive score

Re: xvelocity vs. x+=

Postby lcl » Sat May 14, 2011 10:29 pm

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. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: xvelocity vs. x+=

Postby savvy » Sun May 15, 2011 7:18 pm

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
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest