📓
engine
  • Kakara Engine
  • Debugging
  • Getting Started
    • Getting the Engine
    • A New Game
    • Game Items
    • Components
    • Textures
    • Model Loading
    • The Camera
    • Player Input
      • Practical use of the Input
    • Lighting
    • User Interface
  • Scene System
    • Scene System
  • Render System
    • Extensible Render Pipeline
      • Standard Shader Format
      • Voxel Shader Format
      • Particle Shader Format
      • Lighting Shader Format
      • Custom Pipelines
  • Java Documentation
Powered by GitBook
On this page
  • Component Canvas
  • Object Canvas
  • Debug Canvas

Was this helpful?

  1. Getting Started

User Interface

PreviousLightingNextScene System

Last updated 2 years ago

Was this helpful?

Almost all video games have 2D text or elements on the screen that acts as a HUD. This is accomplished in the Kakara Engine through the User Interface system. In order to add these types of elements to the screen you must use a Canvas. The Kakara Engine has two canvases built in: The ComponentCanvas, ObjectCanvas, and DebugCanvas.

Component Canvas

The ComponentCanvas displays UIComponents, which are 2D elements such as: Text, Sprites, Shapes, etc.

To add a ComponentCanvas you construct it in the loadGraphics method of a Scene.

ComponentCanvas componentCanvas = new ComponentCanvas(this);

Text text = new Text("Example Text", Font.getFont("Roboto"));
text.setTextAlign(TextAlign.CENTER);
text.setLineWidth(130);
text.addConstraint(new HorizontalCenterConstraint());
text.addConstraint(new VerticalCenterConstraint());
        
componentCanvas.add(text);

add(componentCanvas);

Object Canvas

The object canvas allows you to add 3D objects to the User Interface. 3D objects on the User Interface will always be at the same position on screen no mater what happens to the camera.

ObjectCanvas objectCanvas = new ObjectCanvas(this);
        
Mesh cubeMesh = new Mesh(CubeData.vertex, CubeData.texture, CubeData.normal, CubeData.indices);
Material material = new Material(new Texture(rm.getResource("Example_Cube.png"), this));
cubeMesh.setMaterial(material);
UIObject cube = new UIObject(cubeMesh);
cube.setPosition(500, 400);
cube.applyRotation(60, 60, 60);
cube.setScale(300);
objectCanvas.add(cube);
        
add(objectCanvas);

Debug Canvas

The debug canvas is a useful tool to help you debug your game. This canvas is not meant to be used in production.

DebugCanvas debugCanvas = new DebugCanvas();
add(debugCanvas);
Text on a ComponentCanvas.
Example of a Cube on the User Interface
An example of the Debug Canvas in use.