Home | Customize | Blog | Extras | Log In | Info
Manual | D&D icons | GML Parser | Archive | Iso City
Username: Password:  
About | Features | Directory | Banners | Contact

Designing Games with GameMaker
Designing Games with GameMaker

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.

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,removeback,smooth,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 gif images, this argument is not used; the number of images in the gif file is used instead. removeback indicates whether to make all pixels with the background color (left-bottom pixel) transparent. smooth indicates whether to smooth the edges. 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_replace(ind,fname,imgnumb,removeback,smooth,xorig,yorig) Same as above but in this case the sprite with index ind is replaced. The function returns whether it is successful.
sprite_add_sprite(fname) Adds the sprite stored the file fname to the set of sprite resources. The file must be a .gmspr file that is saved in the sprite property form in GameMaker. As this file contains all sprite settings, no further arguments are required. 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_replace_sprite(ind,fname) Same as above but in this case the sprite with index ind is replaced. The function returns whether it is successful.
sprite_create_from_screen(x,y,w,h,removeback,smooth,xorig,yorig) Creates a sprite by copying the given area from the screen. removeback indicates whether to make all pixels with the background color (left-bottom pixel) transparent. smooth indicates whether to smooth the boundaries. 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,removeback,smooth) 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,removeback,smooth,xorig,yorig) Creates a sprite by copying the given area from the surface with the given id. removeback indicates whether to make all pixels with the background color (left-bottom pixel) transparent. smooth indicates whether to smooth the boundaries. 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,removeback,smooth) 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.

Finally, you can change the collision checking mask for the sprite with the following routine. Please realize that this does not work correctly when an instance with that sprite is already present in the room.

sprite_collision_mask(ind,sepmasks,bboxmode,bbleft,bbtop,bbright,bbbottom,kind,tolerance) Changes the collision mask for the sprite with index ind. sepmasks indicates whether there must be separate collision masks for all subimages. bboxmode is the bounding box mode (0=automatic, 1=full image, 2=user defined). bbleft, bbright, bbtop, bbbottom indicate the bounding box in case of user defined bounding box. You can use 0 for all these values in the other cases. kind is the kind of mask (0=precise, 1=bounding box, 2=disk, 3=diamond). tolerance indicates the tolerance in the transparency value (0=no tolerance, 255=full tolerance).

Search Search


Alternative versions Alternative versions

You can also read this manual on one single long page (± 1.5 mb)

Also available in: Dutch French German

ZIP Download helpfile

Advertisement Advertisement

GameMaker Manual