Project

General

Profile

Gamedev basics - libgdx - draw a rectangle » History » Version 2

konstantin, 2025-01-03 21:27

1 2 konstantin
{{toc}}
2
3 1 konstantin
# Gamedev basics - libgdx - draw a rectangle
4
5
6
This is a simple guide that allows to to draw a single rectangle on the screen.
7
8
Drawing rectangle is as simple as
9
```
10
renderer.rect(100f, 100f, 20f, 20f)
11
```
12
13
14
Programming games and animations could be started without IT or programming skills. These skills will be developed along the journey.
15
16
Here is step-by-step guide, how to start with game programming.
17
18
Guide is separated in 3 main sections:
19
20
1. Preparation: software and tools.
21
1. Running and troubleshooting.
22
1. Experiments.
23
24
## Preparation: software and tools
25
26
### Install
27
28
* git
29
* java 21
30
* intellij community edition
31
32
### In idea, download the project from github
33
34
![](clipboard-202501032023-dvwme.png)
35
36
URL: https://github.com/petrukhnov/libgdx-kotlearn
37
38
Agree to import it as gradle project. If it doesn't import, refresh manually:
39
40
![](clipboard-202501032023-uqp6s.png)
41
42
## Running and troubleshooting
43
44
### Run the project
45
46
![](clipboard-202501032023-nm2ql.png)
47
48
It should open new window with green background and white rectangle:
49
50
![](clipboard-202501032023-t8vno.png)
51
52
If it is not shown, see steps below to troubleshoot.
53
54
### If doesn't work
55
56
#### Java version is not found
57
58
![](clipboard-202501032024-egamk.png)
59
60
Select jdk 21, or download if missing.
61
62
manually select it:
63
64
![](clipboard-202501032024-aq4d5.png)
65
66
## Experiments
67
68
Here are few things to try.
69
70
### Change one of the values inside rect() function
71
72
```
73
Main:29
74
shapeRenderer.rect(100f, 200f, 30f, 30f)
75
```
76
77
Rerun and observe how shape changed.
78
79
### Change rectangle color
80
81
E.g. add on line 28 `shapeRenderer.color = Color(1f, 0f, 0f, 1f)`
82
83
### Change background color