GML Functions: Changing Sprites

The following routines are available for changing sprite properties:


 * sprite_set_offset(ind,xoff,yoff) Sets the offset of the sprite with the given index.


 * sprite_set_bbox_mode(ind,mode) Sets the bounding box mode of the sprite (0=automatic, 1=full image, 2=manual).


 * sprite_set_bbox(ind,left,top,right,bottom) Sets the bounding box of the sprite with the given index. Works only when the bounding box mode is manual.


 * sprite_set_precise(ind,mode) Sets whether the sprite with the given index uses precise collision checking (true or false).

The following routines can be used to create new sprites and to remove them.


 * sprite_duplicate(ind) Creates a duplicate of the sprite with the given index. It returns the index of the new sprite. When an error occurs -1 is returned.


 * sprite_assign(ind,spr) Assigns the indicated sprite to sprite ind. So this makes a copy of the sprite. In this way you can easily set an existing sprite to a different, e.g. new sprite.


 * sprite_merge(ind1,ind2) Merges the images from sprite ind2 into sprite ind1, adding them at the end. If the sizes don't match the sprites are stretched to fit. Sprite ind2 is not deleted!


 * sprite_add(fname,imgnumb,precise,transparent,smooth,preload,xorig,yorig) Adds the image stored in the file fname to the set of sprite resources. Many different image file types can be dealt with. When the image is not a gif image it can be a strip containing a number of subimages for the sprite next to each other. Use imgnumb to indicate their number (1 for a single image). For (animated) gif images, this argument is not used; the number of images in the gif file is used. precise indicates whether precise collision checking should be used. transparent indicates whether the image is partially transparent. smooth indicates whether to smooth the edges. preload indicates whether to preload the image into texture memory. xorig and yorig indicate the position of the origin in the sprite. The function returns the index of the new sprite that you can then use to draw it or to assign it to the variable sprite_index of an instance. When an error occurs -1 is returned.


 * sprite_add_alpha(fname,imgnumb,precise,preload,xorig,yorig) Adds the image stored in the file fname to the set of sprite resources, but this time the file has an alpha channel to indicate transparency (as for example in .png files). The arguments are the same as above (but two are missing as they are not relevant in this case). When an error occurs -1 is returned.


 * sprite_replace(ind,fname,imgnumb,precise,transparent,smooth,preload,xorig,yorig) Same as above but in this case the sprite with index ind is replaced. The function returns whether it is successful.


 * sprite_replace_alpha(ind,fname,imgnumb,precise,preload,xorig,yorig) Same as above but in this case the file has an alpha channel. The function returns whether it is successful.


 * sprite_create_from_screen(x,y,w,h,precise,transparent,smooth,preload,xorig,yorig) Creates a sprite by copying the given area from the screen. This makes it possible to create any sprite you want. Draw the image on the screen using the drawing functions and next create a sprite from it. (If you don't do this in the drawing event you can even do it in such a way that it is not visible on the screen by not refreshing the screen.) The other parameters are as above. The function returns the index of the new sprite. A work of caution is required here. Even though we speak about the screen, it is actually the drawing region that matters. The fact that there is a window on the screen and that the image might be scaled in this window does not matter.


 * sprite_add_from_screen(ind,x,y,w,h) Adds an area of the screen as a next subimage to the sprite with index ind.


 * sprite_create_from_surface(id,x,y,w,h,precise,transparent,smooth,preload,xorig,yorig) Creates a sprite by copying the given area from the surface with the given id. This makes it possible to create any sprite you want. Draw the image on the surface using the drawing functions and next create a sprite from it. The function returns the index of the new sprite. Note that alpha values are maintained in the sprite.


 * sprite_add_from_surface(ind,id,x,y,w,h) Adds an area of the surface id as a next subimage to the sprite with index ind.
 * sprite_delete(ind) Deletes the sprite from memory, freeing the memory used.

The following routine exists to change the appearance of a sprite.


 * sprite_set_alpha_from_sprite(ind,spr) Changes the alpha (transparancy) values in the sprite with index ind using the intensity values in the sprite spr. This cannot be undone.