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.

angle from

Problem it solves

You want an enemy to face or move toward the player, but you only have the two sprites' positions, not the direction between them.

What this block does

Returns the angle, in radians, pointing from one sprite, point, or tile location to another. If either is missing, it returns 0.

The block

Block ID: spriteutilextanglebw

angle from $a to $b block

Parameters

NameTypeDefaultMeaning
aSprite / Location / PointmySpriteStarting point
bSprite / Location / PointmyEnemyTarget point

Returns

numberThe angle in radians from a to b.

Example

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

Add the extension

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