MakeCode Games!

A fan-made community library of MakeCode Arcade games. Visit MakeCode Arcade to make a game!

← Back to extensions

Sprite Utils

A grab-bag of sprite math and rendering helpers for MakeCode Arcade: distances, angles, movement, timers, and simple drawing.

is destroyed

Problem it solves

You saved a reference to a sprite (like an enemy or a bullet), but later code might run after that sprite has already been destroyed, and touching a destroyed sprite can crash your game.

What this block does

Checks whether a sprite no longer exists or has already been destroyed, so you can safely skip code that would otherwise touch it.

The block

Block ID: spriteutilextisdestroyed

$sprite is destroyed block

Parameters

NameTypeDefaultMeaning
spriteSpritemySpriteThe sprite to check.

Returns

booleantrue if the sprite is missing or destroyed.

Example

let mySprite = sprites.create(img`.`, SpriteKind.Player)
let myEnemy = sprites.create(img`.`, SpriteKind.Enemy)
if (spriteutils.isDestroyed(myEnemy)) {
    console.log("enemy is gone")
}

Add the extension

Add github:jwunderl/arcade-sprite-util to your project, or open: Import arcade-sprite-util.