I know this was already marked as solved, but wanted to share my example.
Use the left mouse button to trigger an explosion of coins. MAX_TRIGGER determines how many coins will be used in each triggered explosion. As you click, it'll set the next batch of available coins. When the explosion is over, those coins are released back into the pool to be reused again. You can click all day long repeatedly and have coins constantly flying about, but never use more than 50 sprites.
SetWindowSize( 800, 600, 0 )
setVirtualResolution(800,600)
#CONSTANT MAX_COINS = 50 // Maximum number of coins to reserve in memory
#CONSTANT MAX_TRIGGER = 10 // Maximum coins to use in each triggered event
// Coin properties
Type CoinUDT
id as integer
x as float
y as float
dx as float
dy as float
alpha as float
EndType
// Coin array
coins as CoinUDT[MAX_COINS]
// Make a simple coin
c = makeColor(255,255,255)
DrawEllipse(20, 20, 20, 20, c, c, 1)
ci = getImage(0,0,41,41)
coins[0].id = createSprite(ci) // Create the first coin sprite
setSpriteVisible(coins[0].id, 0) // Hide it by default
setSpriteOffset(coins[0].id, 20, 20) // Offset origin to middle of coin image
// Clone the coin for the rest of the sprites
for i = 1 to MAX_COINS-1
coins[i].id = cloneSprite(coins[0].id)
next i
repeat
// Left click to trigger a coin explosion
if getRawMouseLeftPressed()
mx = getRawMouseX()
my = getRawMouseY()
// This is used to limit how many sprites will be used
// for this triggered event
count = 0
// Strictly for visual effects, get a random color
r = random(0,255)
g = random(0,255)
b = random(0,255)
// Loop through all coins
for i = 0 to MAX_COINS-1
// If coin isn't visible, then it's not being used yet.
if getSpriteVisible(coins[i].id) = 0
inc count // increment our counter
// position coins at mouse coordinates with some variation
coins[i].x = mx + random(0, 100)-50
coins[i].y = my + random(0, 100)-50
// Determine a random direction to project the coin towards
a = random(0, 360)
coins[i].dx = cos(a)
coins[i].dy = sin(a)
// Reset coin alpha
coins[i].alpha = 255
setSpritePositionByOffset(coins[i].id, mx, my)
// Show the sprite
setSpriteVisible(coins[i].id, 1)
setSpriteColor(coins[i].id, r, g, b, 255)
endif
// If we've set 10 coins in this event, exit
// the FOR loop early because we have all we need
if count = MAX_TRIGGER then exit
next i
endif
// Loop through all coins to update their status
for i = 0 to MAX_COINS-1
// If coin is visible, it's active.
if getSpriteVisible(coins[i].id) = 1
// Update coin position
coins[i].x = coins[i].x + coins[i].dx*8
coins[i].y = coins[i].y + coins[i].dy*8
// Fade the coin out of existance
coins[i].alpha = coins[i].alpha - 6
setSpriteColorAlpha(coins[i].id, coins[i].alpha)
setSpritePositionByOffset(coins[i].id, coins[i].x, coins[i].y)
// If coin has completely faded away, turn it off
// so it can be reused.
if coins[i].alpha <= 0
setSpriteVisible(coins[i].id, 0)
endif
endif
next i
sync()
until getRawKeyPressed(27) = 1 // Press ESC to exit
end