GML - Expanding and shrinking sprite
From Global Programming Syntax
Sometimes as a special effect, you might want a sprite to exapand to a certain size then contract/shrink to a certain size and repeat the process untill the stage ends. This can also be useful for things like teleporters and stage exit signs.
Example Code
The following is a script that will allow square sprites to do that and if the sprite is not a square shape (rectangular instead) it will automatically make them square. To use this script, first make sure the object that you are going to use does not have a sprite associated with it. Just for this example, it will be called 'object0'. After making sure there is no sprite assigned to object0 or that the sprite is totally invisible, place the following in the create event of object0.
globalvar gsprite, gsprites,gminsize,gmaxsize,gspeed,gswitch;
gminsize=16; //minimum width/height (must be square)
gmaxsize=64; //maximum width/height (must be square)
gspeed=1; //speed of process
gsprite=sprite0; //set the sprite
//don't edit below
gsprites=gminsize;
gswitch=1;
So after you have place the above code in the create event, you will find 4 variables that will need configuring. Configure them according to what the comments say. After that place the following code in the draw event.
if (gswitch=1) {
if (gsprites>gmaxsize) {
gswitch=0;
gsprites-=gspeed;
} else {
gsprites+=gspeed;
}
} else {
if (gsprites<gminsize) {
gswitch=1;
gsprites+=gspeed;
} else {
gsprites-=gspeed;
}
}
draw_sprite_stretched(gsprite,sprite_index,x,y,gsprites,gsprites);
Now when running the script, you should be able to see the image expanding and shrinking at the speed and sizes you specified in the create event. Enjoy.
