Skip to content

PixelSpriteTexture

Extends ImageTexture. Read from the plugin's source on every build.

One frame of a sprite from the Pixel tab, as a texture. Put it anywhere a Texture2D goes: a TextureRect, a Sprite2D, a TileSet atlas.

Set document to a .jcsprite, and frame for any frame but the first. It updates as you draw in the Pixel tab, and when you save while the game runs, with no export step. Set palette to draw it in other colours; the sprite file doesn’t change.

Example: the example game’s village sky, Hub/Sky, is a TextureRect holding one of these over village_sky.jcsprite, set in the scene. From code, with a second texture showing the villager in villager_gold.jcpalette:

var sky := PixelSpriteTexture.new()
sky.document = load("res://examples/art/village_sky.jcsprite")
var rect: TextureRect = $Hub/Sky
rect.texture = sky
var gold := PixelSpriteTexture.new()
gold.document = load("res://examples/art/villager.jcsprite")
gold.palette = load("res://examples/art/villager_gold.jcpalette")
var portrait := TextureRect.new()
portrait.texture = gold
add_child(portrait)

Properties

document

@export var document: PixelDocument

The document this texture shows a frame of, rebuilt as the document changes.

frame

@export var frame: int = 0

Which frame of the document to show, clamped to the frames it has, so a document that loses frames leaves its textures showing something.

palette

@export var palette: PixelPalette

A palette to draw this texture in, instead of the sprite’s own colours. The sprite’s first swatch is drawn as this palette’s first swatch, its second as the second, and so on. The sprite file is never changed, so two textures can show the same sprite in different colours. Set it to null to go back to the sprite’s own colours.

Example: the example game’s second slime, Meadow/Slime2/Sprite, wears slime_red.jcpalette over slime.jcsprite. A texture takes the same palette, and null puts the document’s colours back:

var texture := PixelSpriteTexture.new()
texture.document = load("res://examples/art/slime.jcsprite")
texture.palette = load("res://examples/art/slime_red.jcpalette")
texture.palette = null

Methods

set_layer_visible

func set_layer_visible(name: String, on: bool) -> void

Shows or hides the layer called name on this texture alone: the document’s PixelLayer.visible is not written, so another texture or node on the same document is unchanged. Rebuilds now.

is_layer_visible

func is_layer_visible(name: String) -> bool

Whether the layer called name shows here: this texture’s override when it has one, else the document’s own flag; false for no such layer.

clear_layer_overrides

func clear_layer_overrides() -> void

Drops every override set_layer_visible made, back to the document’s own flags.

rebuild

func rebuild() -> void

Redraws the texture now. Call it after changing the sprite’s pixels from code to see the change this frame instead of the next.

Signals

document_changed

signal document_changed

Emitted after the texture is redrawn: when you set document or palette, change a layer’s visibility, call rebuild, or save the sprite while the game runs.

palette_changed

signal palette_changed(palette: PixelPalette)

Emitted once the texture is redrawn in the palette you set.

JamChip, by GlitterSnack. MIT licence. Built from the source on every merge. Its artwork and screenshots are made with JamChip.