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.

distance between

Problem it solves

You need to know how far away an enemy, power-up, or another sprite is from the player before doing something—playing a sound, firing a projectile, or ending the game.

What this block does

Returns the distance in pixels between the centers of two sprites, points, or tile locations. If either sprite is missing or destroyed, it returns 0.

The block

Block ID: spriteutilextdistbw

distance between $a and $b block

Parameters

NameTypeDefaultMeaning
aSprite / Location / PointmySpriteFirst point to measure from
bSprite / Location / PointmyEnemySecond point to measure to

Returns

numberThe distance in pixels.

Example

let mySprite = sprites.create(img`.`, SpriteKind.Player)
let myEnemy = sprites.create(img`.`, SpriteKind.Enemy)
let distance = spriteutils.distanceBetween(mySprite, myEnemy)
console.log(distance)

Add the extension

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