实例变量


When you create a new object, it will come with certain variables already initialised with default values. These variables we call instance variables, since they will be created for every instance you place of the object in your game rooms, and once an instance is created the values of these variables are unique to that instance and only that instance. Some of these variables you will use a lot, like x and y, while others are required less depending on what you want to do, but in general they are very handy and where possible you should be looking to use them rather than creating your own custom variables.

Most instance variables can be set as well as read, permitting you to change the properties and behaviour of an instance simply by tweaking the value of a certain variable - you can prevent an instance from drawing, for example, by simply setting the visible built-in variable to false. Below you can find the different variables that are initialised for all instances of all objects in your game.

These variables deal with general instance properties:

These variables are all related to the sprite assigned to the instance and can be used to change what is drawn and how:

These variables deal with the collision mask:

These variables deal with the instance position and movement:

These variables are related to paths and how the instance interacts with one, if assigned:

These variables are for setting an instance to use a timeline:

There are a great number of built in variables for use with the physics functions of GameMaker Studio 2, and so to keep things clearer, they can be found in the section of the manual that covers everything related to the physics simulation: