Skip to content

Commit

Permalink
πŸ“ add user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Horsty80 committed Oct 25, 2023
1 parent c08aa0e commit 2e40d11
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/godot/tilemap.md β†’ docs/godot/15-tilemap.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 14
sidebar_position: 15
---

# Tilemap
Expand Down
2 changes: 1 addition & 1 deletion docs/godot/particles.md β†’ docs/godot/16-particles.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 15
sidebar_position: 16
---

# Particles
Expand Down
2 changes: 1 addition & 1 deletion docs/godot/light.md β†’ docs/godot/17-light.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 16
sidebar_position: 17
---

# Light
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 17
sidebar_position: 18
---

# Animations
Expand Down
2 changes: 1 addition & 1 deletion docs/godot/tweens.md β†’ docs/godot/19-tweens.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 18
sidebar_position: 19
---

# Tweens
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/godot/laser.md β†’ docs/godot/20-laser.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 19
sidebar_position: 20
---

# Lasers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 20
sidebar_position: 21
---

# Create multiple levels
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 21
sidebar_position: 22
---

# Level transition
Expand Down
67 changes: 67 additions & 0 deletions docs/godot/23-user-interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
sidebar_position: 23
---

# User interface

There are 4 kinds of Nodes:
- 2D πŸ”΅
- 3D πŸ”΄
- Control 🟒
- Other βšͺ️

## Control Nodes

Labels, images, progress bars, buttons, areas with colors, text input, graphs, menus, videos.

2D Nodes are placed via pixel positions.
Control Nodes work via anchors and container.

Create a new scene, select a **Canvas Layer** that will contain all our UI elements. The canvas will be positioned on top of the game.
So every label, texture, etc. will be visible inside the screen game.

There are 2 ways to place a control node.
Anchors and Containers

Anchors are the green needles in the topleft of a control node

Containers are parent nodes that determine the position of their children

(You can also use x and y properties or drag the Control Node to the position you want but that is almost never a good idea)

### Anchors

We have acces to panel of anchors on top of the screen.

![Anchors](/img/anchors.png)

But we can also use the **Layout** menu to setup the anchors.

![Layout](/img/layout.png)

Is like in css, we have **Anchor Points** with top, bottom, left, right.
The value inside `right` is calculated from the left position of the node.
So `left: 0` and `right: 0` will make the node with no width.
However, if we set `left: 0` and `right: 100`, the node will have a width of 100.
For the `top` and `bottom` is the same. The `bottom` value is calculated from the `top` position of the node.
And `top: 0.5` and `bottom: 0.5` will make the node at the center of the screen, with no height.
However, if we set `top: 0.5` and `bottom: 0.6`, the node will have a height of 0.1. etc.

Remember, in 2D, x and y are the top left corner of the node.
The start position are (0, 0) and the end position are (1, 1).
So we navigate between this number.

### Containers

It's like flexbox or Grid in css.

We can use **HBoxContainer** or **VBoxContainer**. It's working with children.
You have **GridContainer** it's workin like a grid in css with column.

## Progress bar

We need to add a progress bar, Godot has 2: A plain one and a textured one.
They are both set in the same way.
The textured need 3 images: background, over and progress image.

To position the progress bar, we can use container and the best container for that is **MarginContainer**. It's like a div with margin in css. If we position the progress bar on bottom center, with the margin, the progress bar will be always at the bottom center of the screen with the good margin.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added static/img/anchors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2e40d11

Please sign in to comment.