Changing sprites is slow? Might be why it takes a few seconds to load Tails in MKF...
1. The sprites (duh)
2. The code (also duh)
First, I'm going to go out of order and discuss the code. From the Game Maker Documentation:
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(fname,imgnumb,precise,transparent,smooth,preload,xorig,yorig) is your function to use. The argument "fname" is the file you want to open. It is stored as a string, and therefore should be enclosed in quotation marks.
"sprites.bmp"
"sprites.gif"
If your sprites are in a subfolder, then you should refer to "folder\sprites.bmp" if it's in a folder "folder", "folder\folder\sprites.bmp" if it's in "folder" inside another "folder" or... yeah, I think you get the point here.
imgnumb splits your sprite file into the number you put for imgnumb. If you have an imgnumb of 4, it will split the file into 4 equal pieces by width for animation. It is therefore key that you KEEP YOUR SPRITES IN NEAT ORDER.
How wide your sprite file should be depends on how big your subimages are and how many there are.
File width = subimage width * imgnumb
There are quite a few more functions that modify sprite resources, but that one is the one you need for now. Note that the function returns the index of the new sprite, which you'll need to do anything with it. You can store the index in a variable, like so:
global.spr_lol=sprite_add(...
Sprites can be deleted with the sprite_delete(ind) function.
==SOUNDS==
Sounds are a bit simpler to load than sprites. In addition, they can also be deleted.
| QUOTE |
sound_add(fname,kind,preload) Adds a sound resource to the game. fname is the name of the sound file. kind indicates the kind of sound (0=normal, 1=background, 2=3d, 3=mmplayer) preload indicates whether the sound should immediately be stored in audio memory (true or false). The function returns the index of the new sound, which can be used to play the sound. (-1 if an error occurred, e.g. the file does not exist). |
fname works the same as it did with adding sprites, so no need to mention it again.
The kind depends on what file you're going to use. 0 should be for .wav files. 1 should be for .mp3 and .mid files. 2 is for, um, .wav files that you intend to be 3D sounds, and 3 is for any file type Game Maker cannot play (like OGG files).
To delete a sound, just use sound_delete(ind). Like using sprites, you're kind of in trouble if you don't keep track of the index that sound_add returns.
Well, that should be everything. Post to report mistakes, give praise, etc.
EDIT: sprite_delete(ind) derp