scratchtext
Write Scratch projects as text, then compile them to a .sb3 file you can open
on scratch.mit.edu. You can also go the other way:
turn an existing .sb3 back into a .scratch file with all its images.
Install
# Global — adds the `scratchtext` command
npm install -g scratchtext
# Or run once without installing
npx scratchtext game.scratch
# Or install straight from the packaged tarball
npm install -g ./scratchtext-1.0.0.tgz
Then use scratchtext anywhere:
scratchtext --help
scratchtext game.scratch # -> game.sb3
scratchtext game.sb3 # -> game/ (source + images)
From source (for development):
npm install
npm run build # compiles src/ -> dist/
npm run dev -- game.scratch # run without building (via tsx)
> The examples below use scratchtext; from a source checkout use
> node dist/cli.js instead.
1. Using your own images
Drop .png, .jpg, or .svg files next to your .scratch file, or in an
images/ or assets/ subfolder, then refer to them by name.
my-game/
├─ game.scratch
└─ images/
├─ cat.png
└─ sky.svg
sprite "Cat" {
costume "cat.png" // shorthand: costume is named "cat"
costume "happy" = "cat.png" // or give it your own name
on flag { say("hi!") }
}
stage {
backdrop "sky" = "sky.svg"
}
- The costume/backdrop size and rotation center come from the real image
dimensions, so pictures appear at their natural size and rotate around their
middle.
- A bare
costume "cat.png" names the costume after the file (cat).
- Need images from somewhere else? Add a search folder:
node dist/cli.js game.scratch --assets ./shared-art
Compile it:
node dist/cli.js game.scratch # -> game.sb3
node dist/cli.js game.scratch -o out.sb3 # -> out.sb3
See examples/images-demo.scratch for a working example.
2. Converting a .sb3 back to text
Point the tool at a .sb3 and it writes a folder containing the .scratch
source plus every costume and backdrop image.