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
Parameters
| Name | Type | Default | Meaning |
|---|---|---|---|
| kind | Sprite kind | — | The kind of sprite to search for |
| distance | number | 50 | The search radius, in pixels |
| sprite | Sprite / Location / Point | mySprite | The 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.