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.

get sprites of kind within distance

Problem it solves

You need to find every enemy (or coin, or bullet) near the player—for example to check which ones are in range of an area attack.

What this block does

Returns every sprite of a given kind within the given distance of a sprite, point, or tile location, sorted from nearest to farthest.

The block

get all sprites of kind $kind within $distance pixels from $sprite block

Parameters

NameTypeDefaultMeaning
kindSprite kindThe kind of sprite to search for
distancenumber50The search radius, in pixels
spriteSprite / Location / PointmySpriteThe center of the search

Returns

Sprite[]The matching sprites, nearest first.

Example

let mySprite = sprites.create(img`.`, SpriteKind.Player)
let myEnemy = sprites.create(img`.`, SpriteKind.Enemy)
let nearby = spriteutils.getSpritesWithin(SpriteKind.Enemy, 50, mySprite)
console.log(nearby.length)

Add the extension

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