Assets API
Check scene asset availability and inspect exported image regions.
On this page
Use api.assets() when you need to check whether an asset is available for the current scene or inspect its exported region.
AssetsAPI assets = api.assets();
Find an asset
Look up an asset by its exported name:
if (api.assets().contains("coin")) {
AssetRegionRef coin = api.assets().region("coin");
}
If your gameplay data already stores Pixscape asset IDs, use the ID overloads:
if (api.assets().contains(42)) {
AssetRegionRef coin = api.assets().region(42);
}
Name lookup uses the asset name shown in Pixscape Studio and is case-insensitive. For example, an asset named coin is looked up as coin.
region(...) throws IllegalArgumentException when the asset is not available. Use contains(...) when absence is an expected gameplay case.
Inspect the exported region
AssetRegionRef provides the information commonly needed by gameplay code:
AssetRegionRef coin = api.assets().region("coin");
int assetId = coin.assetId();
String name = coin.name();
float pixelWidth = coin.width();
float pixelHeight = coin.height();
TextureRegion texture = coin.region();
region() returns a defensive TextureRegion snapshot. You can modify the returned TextureRegion without changing Pixscape’s stored region information or future sprite spawns.
Make dynamic assets available
Assets used by gameplay must be available for the current scene. Assets already placed in the scene are included automatically. If code will use an extra asset later, add it to Runtime Availability in Studio before export.
For direct entity creation, use api.sprites(), api.animations(), api.particles(), or api.gameObjects().
Code examples
Spawn a reward only when its visual asset is available
Spawn a coin selected by application reward logic after Studio has made its visual asset available.
String rewardAsset = "coin";
// This checks scene availability; it never loads an asset.
if (!api.assets().contains(rewardAsset)) {
return;
}
SpriteRef reward = api.sprites().spawn(rewardAsset, rewardX, rewardY)
.scale(1.25f)
.tint(1f, 0.9f, 0.35f, 1f);
// Application pickup logic tracks the spawned entity.
pickupSystem.register(reward.entity());
pickupSystem is application code. Add an asset used only from code to Runtime Availability before loading the scene.