2D: first objects and running a level
Coordinates, hierarchy, visibility, camera and first-run diagnosis.
What makes a 2D level
Entity2D stores position, rotation and scale. This type alone neither draws anything nor creates collisions.
| Task | Suitable type |
|---|---|
| Display an image | Sprite2D with a Texture assigned |
| Control a character with physical collisions | CharacterBody2D with a CollisionShape2D child |
| Detect entry into an area | Area2D with a CollisionShape2D child |
| Add an interface | Control; CanvasLayer for a separate layer |
| Change the view of the game world | Camera2D |
Character visuals and collision geometry are separate objects. Sprite2D does not acquire collisions because its texture depicts a wall. Start with the first 2D game, which configures shapes, layers, movement and hit handling.
Coordinates and the parent
In 2D, positive X points right and positive Y points down. Vector2.Up is (0, -1). Position is local; GlobalPosition is in the corresponding canvas space.
A child Entity2D's final placement depends on its parent CanvasItem transform, including rotation and scale. An ordinary Entity between them breaks this chain. TopLevel has separate rules: it does not inherit its parent CanvasItem transform. See 2D transforms.
A canvas coordinate unit does not necessarily equal a physical screen pixel: Camera2D zoom and stretch settings change the result. Do not compensate for a camera error by changing Position arbitrarily.
Work in the editor
Switch to the 2D workspace. Select an object in the tree, then edit Position, Rotation and Scale in the inspector or use the move, rotate and scale tools. To locate an object, use the action that focuses the selection. Check its key in the editor shortcut settings: bindings can be changed.
The 2D workspace is an editor view, not a guaranteed game frame. Simple 2D output does not require Camera2D; when using one, check the final view by running the document. For a HUD that must not move with the world, use canvas layers.
Choose Control for interfaces: its sizes, anchors and containers address window layout. Entity2D with manually assigned coordinates does not replace a responsive interface.
Verify the first result
- Assign a texture to Sprite2D and place it in the visible area.
- Run the intended document: the image must appear in the game, not only in the editor.
- Move the parent and confirm that its child behaves as intended.
- If physics is needed, configure the shape, layers and masks separately; test an actual collision.
| Problem | Check |
|---|---|
| Nothing is visible | Texture, object and parent Visible flags, Modulate alpha, camera position |
| Another object covers it | Draw order, ZIndex and CanvasLayer |
| Passes through a wall | Physics body type, CollisionShape2D, layers and masks |
| Interface moves with the world | CanvasLayer and HUD hierarchy |
| Position changes unexpectedly | Position versus GlobalPosition, parent type, rotation and scale |
Next tasks: movement, sprite animation, tile-based levels.