← Reference

Sprites and movement: cheat sheet

Arcade Foundations · Find each block in the MakeCode toolbox (the category is at the end of each line).

create sprite

Makes a sprite: a picture the game can move and test. Sprites; click the picture to draw your own. The kind says what it is.

let mySprite = sprites.create(img`
    . . . . . . . .
    . . 5 5 5 5 . .
    . 5 5 5 5 5 5 .
    . 5 f 5 5 f 5 .
    . 5 5 5 5 5 5 .
    . 5 f f f f 5 .
    . . 5 5 5 5 . .
    . . . . . . . .
    `, SpriteKind.Player)
The block

set x

Sets one part of the position. y counts down from the top. Sprites; choose x or y in the dropdown.

mySprite.x = 80
The block

stay in screen

Stops a sprite going off the edge. Sprites › set stay in screen.

mySprite.setStayInScreen(true)
The block

set vx

Speed across: positive moves right, negative moves left. vy is speed down. Sprites; choose vx in the dropdown.

mySprite.vx = 50
The block

on A pressed

Runs its blocks every time A is pressed (space or Z on the keyboard). Controller.

controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
    blocks
})
The block

jump from ground

The jump goes inside an if that asks whether the player is on the floor, so it only works from the ground.

controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
    if (player.bottom >= 100) {
        player.vy = -150
    }
})
The block

set background color

Fills the screen with one colour. Scene.

scene.setBackgroundColor(9)
The block

set position

Puts a sprite at x (across, 0 to 160) and y (down, 0 to 120). The middle is 80, 60. Sprites.

mySprite.setPosition(80, 60)
The block

move with buttons

The arrow keys (or WASD) move the sprite. Add two numbers for the speed across and down. Controller.

controller.moveSprite(mySprite)
The block

set velocity

How far the sprite moves every frame, across and down. It keeps moving until something changes it. Sprites.

mySprite.setVelocity(50, 0)
The block

bounce on wall

The sprite bounces back at the edge of the screen. Sprites › set bounce on wall.

mySprite.setBounceOnWall(true)
The block

change variable

Adds to a variable. Change by -1 counts down. Variables.

level += 1
The block