Building 2D games

Sprites & the 2D camera

Putting pixel-art sprites on screen, ordering them, tinting them and looking at them through a 2D camera.

2D in Trisgine uses its own lightweight entities: a sprite has a 2D position, an angle, a 2D scale, a draw order and a tint. It does not use the 3D transform. Sprites are drawn by the Sprite2DRendering system, from a 2D camera.

A minimal 2D scene

Here is the smallest complete 2D scene, a camera and one sprite, written as a scene file:

tgscene
configs:
update:
input:
render:
	-Sprite2DRendering
entities:
	-Camera2DMain:
		-Camera2D:10
		-Position2D:0,0
	-Hero:
		-Sprite:7A11C0DE00000004
		-Position2D:0,0
		-Scale2D:1,1
		-ZOrder:10
		-Tint:1,0.6,0.2,1

Camera2D:10 means the camera shows 10 world units vertically. The width follows the panel's aspect ratio, so a bigger number zooms out.

In the editor

  • Create a sprite: right-click the Hierarchy, then 2D Sprite. It starts with a plain white texture.
  • Create a 2D camera: make an entity (Create Empty), then Add Component > 2D Camera.
  • Select a sprite and the Inspector shows its Transform 2D section: position, angle, scale, Z-order and tint.
  • Toggle 2D in the Scene view's toolbar to edit in a flat view.
FieldScene lineNotes
Position-Position2D:x,yworld units
Angle-Angle2D:degreescounter-clockwise
Scale-Scale2D:x,ya negative value flips the sprite
Z-order-ZOrder:nhigher draws on top (−32767…32767)
Tint-Tint:r,g,b,amultiplies the image; a < 1 is see-through
Image-Sprite:<texture uuid>see below

Movement without code

Give a sprite -Velocity2D:x,y and it moves on its own (the MoveByVelocity2D system is added automatically). Add Bounce2D to the update: list and sprites bounce off the camera edges, which makes a classic screensaver.

Moving sprites with scripts

Visual scripts control sprites with 2D nodes: SetVelocity2D, GetPosition2D / SetEntityPosition2D, input actions (ActionVector2 Move, ActionPressed Jump) and FindEntity to look at other entities. A script moving a Camera2D makes it follow a sprite. Meadow Quest builds a complete top-down RPG with them.

What 2D can't do yet

  • Sprites can't be parented to other sprites.
  • Scripts can't spawn or destroy sprites; move them out of sight instead.