Sprites and images
Each object has a sprite associated with it. This is either a single image or it consists of multiple images. For each instance of the object the program draws the corresponding image on the screen, with its origin (as defined in the sprite properties) at the position (x,y) of the instance. When there are multiple images, it cycles through the images to get an animation effect. There are a number of variables that affect the way the image is drawn. These can be used to change the effects. Each instance has the following variables:
visible If visible is true (1) the image is drawn, otherwise it is not drawn. Invisible instances are still active and create collision events; only you don't see them. Setting the visibility to false is useful for e.g. controller objects (make them non-solid to avoid collision events) or hidden switches. sprite_index This is the index of the current sprite for the instance. You can change it to give the instance a different sprite. As value you can use the names of the different sprites you defined. Changing the sprite does not change the index of the currently visible subimage. sprite_width* Indicates the width of the sprite. This value cannot be changed but you might want to use it. sprite_height* Indicates the height of the sprite. This value cannot be changed but you might want to use it. sprite_xoffset* Indicates the horizontal offset of the sprite as defined in the sprite properties. This value cannot be changed but you might want to use it. sprite_yoffset* Indicates the vertical offset of the sprite as defined in the sprite properties. This value cannot be changed but you might want to use it. image_number* The number of subimages for the current sprite for the instance (cannot be changed). image_index When the image has multiple subimages the program cycles through them. This variable indicates the currently drawn subimage (they are numbered starting from 0). You can change the current image by changing this variable. The program will continue cycling, starting at this new index. (The value can have a fractional part. In this case it is always rounded down to obtain the subimage that is drawn.) image_speed The speed with which we cycle through the subimages. A value of 1 indicates that each step we get the next image. Smaller values will switch subimages slower, drawing each subimage multiple times. Larger values will skip subimages to make the motion faster.Example
Sometimes you want a particular subimage to be visible and don't want the program to cycle through all of them. This can be achieved by setting the speed to 0 and choosing the correct subimage. Assume you have an object that can rotate and you create a sprite that has subimages for a number of orientations (counter-clockwise). Then, in the step event of the object you can set
image_index = direction * image_number/360;
image_speed = 0;
}
Contributor: Mark Overmars

Related: