Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: X-coordinate and Y-coordinate change while moving  (Read 3813 times)

0 Members and 1 Guest are viewing this topic.
X-coordinate and Y-coordinate change while movin...
« on: April 17, 2011, 07:33:37 pm »
  • Let's do this.
  • *
  • Reputation: +4/-0
  • Offline Offline
  • Gender: Male
  • Posts: 211
How I can test Link's x-coordinate and y-coordinate change while moving?
It doesn't works:
if (x += 1) {...}
« Last Edit: April 18, 2011, 11:56:39 am by Rayo »
Logged
This is one of many tales Hylian lore speaks of...

Click here to check out my Deviantart!
  • Zelda Time Walker
Re: X-coordinate and Y-coordinate change while m...
« Reply #1 on: April 17, 2011, 07:47:44 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I don't even think you are trying to think logically about the issue you are running into. There are languages like C++ which allow you do do an assign (where "=" assigns a value and "==" is an equal comparison) as part of the if condition (can't think of a good example but sometimes it is useful for things involving pointers which can point to null/0 which would evaluate to false if doing so), but for something like Game Maker that kind of a statement is just silly. It is mad silly.

Game Maker has something built-in called xprevious and yprevious. If I am remembering this correctly, xprevious and yprevious are updated at the beginning of the Step Event, therefore in the code for your Step Event if you wanted to test if x or y movement occurred you would first possibly increment the x or y coordinate, then doing something like:

Quote
if (x != xprevious){...}
Logged
Re: X-coordinate and Y-coordinate change while m...
« Reply #2 on: April 17, 2011, 08:24:32 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2374
(can't think of a good example...)
One common usage I can think of would be calling a function that returns a boolean value based on its success, then using the "if" statement around it to check if it succeeded, or check if it failed by inverting it. Like this:

Code: [Select]
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Unable to initialize window class.", "Error", MB_ICONERROR | MB_OK);
return 0;
}
Logged

Xiphirx

wat
Re: X-coordinate and Y-coordinate change while m...
« Reply #3 on: April 17, 2011, 09:00:08 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
You really shouldn't be modifying the position of link directly... You want to look into 2d vectors and velocity :)
Logged
  • For The Swarm
Re: X-coordinate and Y-coordinate change while m...
« Reply #4 on: April 18, 2011, 02:39:22 am »
  • Wooper Don't Give a !@#$%
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1457
You really shouldn't be modifying the position of link directly... You want to look into 2d vectors and velocity :)

This is unnecessary advice unless you're doing something physics based and even more unnecessary for a beginner, it'll only serve to confuse him

And 4Sword brought up the easiest way to do this by far. You can also keep track of your own xprevious/yprevious values but if GameMaker has them built in then why bother?
Logged
ROLL TIDE WHAT? **** YOU!!! Geaux Tiga

~The Gaurdians of ZFGC~
Kirby, metallica48423, Max, Vash, walnut100
  • Gamers & Developers Unlimited

Xiphirx

wat
Re: X-coordinate and Y-coordinate change while m...
« Reply #5 on: April 18, 2011, 03:17:34 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Well, its better to start doing things the right way first rather than falling into a habit :P
Logged
  • For The Swarm
Re: X-coordinate and Y-coordinate change while m...
« Reply #6 on: April 18, 2011, 04:27:53 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Looking back I actually made the assumption that Rayo was using Game Maker when he didn't specify what exactly he was using. Otherwise Xiphirx if you think that your way is good enough and think that others should be using it, maybe you should post a tutorial or something demonstrating it - i.e., so that other people can learn it since your way may not be as obvious.
Logged
Re: X-coordinate and Y-coordinate change while m...
« Reply #7 on: April 18, 2011, 07:22:00 am »
  • Wooper Don't Give a !@#$%
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1457
Well, its better to start doing things the right way first rather than falling into a habit :P

Ehh... Not necessarily. Again, its only necessary if you're getting into a physics based game, and if you're doing that you've got bigger fish to fry than worrying about moving your objects with velocity rather than position.

My economics professor has a saying, KISS. Keep It Simple Stupid. I think it especially suits programming :P

And its a fair assumption that he's using GameMaker. If he isn't he should just make sure to setup an xprevious var at the beginning of the game loop, easy :D
Logged
ROLL TIDE WHAT? **** YOU!!! Geaux Tiga

~The Gaurdians of ZFGC~
Kirby, metallica48423, Max, Vash, walnut100
  • Gamers & Developers Unlimited
Re: X-coordinate and Y-coordinate change while m...
« Reply #8 on: April 18, 2011, 12:01:06 pm »
  • Let's do this.
  • *
  • Reputation: +4/-0
  • Offline Offline
  • Gender: Male
  • Posts: 211
Oh, yes I am using Game Maker 8.
Now it works:
Code: [Select]
//Right
if (x > xprevious){...}
//Left
if (x < xprevious){...}
//Down
if (y > yprevious){...}
//Up
if (y < yprevious){...}
Thank you, 4Sword!
Logged
This is one of many tales Hylian lore speaks of...

Click here to check out my Deviantart!
  • Zelda Time Walker
Re: X-coordinate and Y-coordinate change while m...
« Reply #9 on: April 18, 2011, 02:34:13 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
No problem, except that if you something like where you are checking the value of x in relation to xprevious, you should really be using the following form:

Quote
if (x > xprevious){ ... }
else if (x < xprevious){ ... }

Basically if the first condition is true, it won't check the second condition.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.042 seconds with 54 queries.