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.

on sprite update interval

Problem it solves

You want a sprite to do something repeatedly—like fire a projectile or check its health—without cluttering the main game update loop with your own timer.

What this block does

Runs your code for a specific sprite on a repeating interval, in milliseconds.

The block

Block ID: spriteutilonspriteupdateinterval

on $target update $sprite every $interval ms block

Parameters

NameTypeDefaultMeaning
targetSpritemySpriteThe sprite to run the handler for
intervalnumber500How often to run, in ms

Example

let mySprite = sprites.create(img`.`, SpriteKind.Player)
let myEnemy = sprites.create(img`.`, SpriteKind.Enemy)
spriteutils.onSpriteUpdateInterval(mySprite, 500, function (sprite) {
    console.log("tick")
})

Add the extension

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