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