x

The x position of the instance.

Syntax:

x


Returns: Real


Description

The x value of an instance is the horizontal position in the current room, measured in pixels. This value can be either 0, positive or minus, where 0 is the left hand side of the room and moving right increases x, moving left decreases x (a negative value for x means that the instance has gone outside the left side of the room). You can even give x a real value like 12.345, but as you cannot get .345 of a pixel, the instance may not appear to have moved, although these values will be maintained and used internally by GameMaker: Studio and are perfectly valid.

By setting the x (and y) values you can make the object jump around the room to the position of your choice, or you can add and subtract to them by smaller amounts to give the illusion of movement without actually using the built in speed and direction functions. This should be taken into account when making your games as often one type of movement lends itself to a particular style of game-play more than another.


Example:

if keyboard_check(vk_left) x += 5;
if keyboard_check(vk_right) x -= 5;

The above code will use the arrow keys to add or subtract to the x position and so create the illusion of movement.


Back: Moving Around
Next: y
© Copyright YoYo Games Ltd. 2018 All Rights Reserved