• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker player x and y positions

B

bdonohue

Guest
Hey folks!

So I've been using Shaun Spalding's GameMaker Studio 2: Complete Platformer Tutorial


and I've been noticing that my player's y coordinates ALWAYS have decimal values (eg; 320.22). The x values are always whole numbers.

Anybody have any idea why this would happen? All of my platforms are locked to the grid, so all of them are located at whole number pixel locations. I also noticed that whenever I land on a platform (from jumping or falling) the numbers to the right of the decimal are always different... almost random. Sometimes it's 320.22, sometimes it's 320.32, sometimes 320.42, etc...

So I have a number of questions running through my head now... Could this cause problems? Why does it happen? Is this just some weird nuance of the Game Maker 2 engine, or would it be caused by Shaun's code? Is there some easy way to force my y values to be whole numbers? Does it even matter?

The only thing I can think of is that it is related to the gravity used in his code, since it only affects the y values.

Thanks in advance :)
 
Last edited by a moderator:
P

Pyxus

Guest
Hey folks!

So I've been using Shaun Spalding's GameMaker Studio 2: Complete Platformer Tutorial


and I've been noticing that my player's y coordinates ALWAYS have decimal values (eg; 320.22). The x values are always whole numbers.

Anybody have any idea why this would happen? All of my platforms are locked to the grid, so all of them are located at whole number pixel locations. I also noticed that whenever I land on a platform (from jumping or falling) the numbers to the right of the decimal are always different... almost random. Sometimes it's 320.22, sometimes it's 320.32, sometimes 320.42, etc...

So I have a number of questions running through my head now... Could this cause problems? Why does it happen? Is this just some weird nuance of the Game Maker 2 engine, or would it be caused by Shaun's code? Is there some easy way to force my y values to be whole numbers? Does it even matter?

The only thing I can think of is that it is related to the gravity used in his code, since it only affects the y values.

Thanks in advance :)
I mean, I assume at some point you're doing "position += a non-whole number ". If you want the x and y to be a whole number perhaps you could just round the values in the end step; Either way I don't think this is an issue with gamemaker. I suppose it could cause a problem depending on how you handle collisions but beyond that I believe its fine.
 

Slyddar

Member
my player's y coordinates ALWAYS have decimal values (eg; 320.22). The x values are always whole numbers.
Like you suspected, the code is applying the grav variable, which is 0.1, to the y value per step, so yes, it will be a decimal. Shaun sets hsp to be move * walksp, move is always an integer, and walksp is always 4, so yep, this will always equal a whole number, and since we add it onto x, x will always be a whole number. No magic, just interrupting the code.

As for problems, decimals are numbers, you will encounter them many times in coding. Don't worry about them. Unless you are doing tile collisions, where you will want to convert to integers before collisions occur, there is no issue, since Shaun's tutorial does not deal with tile collisions (alas, for that reason, it's not the best method imho, although is it a good starting point)
 
Top