Scratch for Java

TiledMap::spawn()

Browser availability: desktop-only.

This API requires the desktop runtime. Browser declarations may report the limitation without performing the operation.

Creates a sprite for each object of a layer whose type names a sprite class, and adds it to the stage. In Tiled, give an object the type (called "class" in newer versions of Tiled) Player, and the map makes a new Player() where the object is.

The sprite's class needs one of these constructors, tried in this order: one that takes the MapObject (to read its name and properties), one that takes (double x, double y), or one without parameters. Either way the sprite is put where the object is. An object drawn as an area (a rectangle, an ellipse or a polygon) also gives the sprite that area as its hitbox, which is how walls and water work without a costume.

Objects whose type is not a sprite class, or that have no type, are left alone, so a layer can hold markers the program reads itself.

TiledMap map = new TiledMap("level.tmx", this);
map.spawn("Objects");

Syntax

Java

.spawn(layerName)

Parameters

Name Data Type Description
layerName String the object layer

Return

List<Sprite>

spawn()

Create Shareable URL

Select Sections