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