简体   繁体   中英

How do you find an objects position in Game Maker?

I am making a game in Game Maker right now and cannot figure out how to get an objects exact position and have another object move to that position. Can someone please help me?

To get an object's position simply use

xpos = instance.x;
ypos = instance.y;

where instance is the instance id (gained through some method, object id can be used if the instance is the only instantiation of the object).

To start moving towards a position you should set the speed & direction:

direction = point_direction(x,y, instance.x, instance.y);
speed = WANTEDSPEED;

The object position are two variables (x,y)

You can access them as you would do with any other variable (objectName.variable)

So these two would be, as paul23 said:

object.x
object.y

To make the object move towards a point you can better use this built-in function:

move_towards_point(object.x,object.y,speed)

It'll move by speed pixels every time it's executed so you may want to put it in the Step event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM