Your First Game
This walkthrough creates a new project, adds a scene, and writes a component that loads a PNG sprite.
Create a New Project
- Launch the Voltage Editor.
- Choose
File > New Project. Fill in a project name and directory and click Create. - The editor creates the folder structure described in Projects and Folder Layout and opens the project.
Create a Scene
- In the Asset Browser, choose a folder for your scene. New projects default to
Scenes/, but.vscenefiles can live anywhere inside the project. - Right-click the folder and choose New Scene. Name it
GameScene. - Double-click
GameScene.vsceneto open it. The Scene Graph shows a default Camera entity.
Add an Entity
- In the Scene Graph, right-click the root and choose Create Entity. Name it
Hero. - The Inspector shows the entity's
Transform. Set Position to(0, 0).
Write a Component
In the Scripts/ folder create a new file HeroVisuals.cs:
using Voltage;
using Voltage.Sprites;
public partial class HeroVisuals : Component
{
public override void OnStart()
{
var sprite = AddComponent(new SpriteRenderer());
sprite.LoadPngFile("Content/Characters/hero.png");
}
}
Place hero.png in the project's Content/Characters/ folder.
Save the file. The editor detects the change, recompiles the scripts, and reloads the scene.
Attach the Component
- Select the
Heroentity in the Scene Graph. - In the Inspector, click Add Component and choose
HeroVisualsfrom the list. - Press
Ctrl+Sto save the scene.
Press Play
Click the Play button in the Editor Tools bar (or press F1). The scene enters Play mode. OnStart runs, LoadPngFile loads the texture, and the sprite appears at the origin of the game viewport.
Press F1 again to return to Edit mode. The scene reloads automatically if Core.ResetSceneAutomatically is true (the default).