Project

General

Profile

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

Revision 1 (konstantin, 2025-01-03 21:26) → Revision 2/3 (konstantin, 2025-01-03 21:27)

{{toc}} 

 # Gamedev basics - libgdx - draw a rectangle 


 This is a simple guide that allows to to draw a single rectangle on the screen. 

 Drawing rectangle is as simple as 
 ``` 
 renderer.rect(100f, 100f, 20f, 20f) 
 ``` 


 Programming games and animations could be started without IT or programming skills. These skills will be developed along the journey. 

 Here is step-by-step guide, how to start with game programming. 

 Guide is separated in 3 main sections: 

 1. Preparation: software and tools. 
 1. Running and troubleshooting. 
 1. Experiments. 

 ## Preparation: software and tools 

 ### Install 

 * git 
 * java 21 
 * intellij community edition 

 ### In idea, download the project from github 

 ![](clipboard-202501032023-dvwme.png) 

 URL: https://github.com/petrukhnov/libgdx-kotlearn 

 Agree to import it as gradle project. If it doesn't import, refresh manually: 

 ![](clipboard-202501032023-uqp6s.png) 

 ## Running and troubleshooting 

 ### Run the project 

 ![](clipboard-202501032023-nm2ql.png) 

 It should open new window with green background and white rectangle: 

 ![](clipboard-202501032023-t8vno.png) 

 If it is not shown, see steps below to troubleshoot. 

 ### If doesn't work 

 #### Java version is not found 

 ![](clipboard-202501032024-egamk.png) 

 Select jdk 21, or download if missing. 

 manually select it: 

 ![](clipboard-202501032024-aq4d5.png) 

 ## Experiments 

 Here are few things to try. 

 ### Change one of the values inside rect() function 

 ``` 
 Main:29 
 shapeRenderer.rect(100f, 200f, 30f, 30f) 
 ``` 

 Rerun and observe how shape changed. 

 ### Change rectangle color 

 E.g. add on line 28 `shapeRenderer.color = Color(1f, 0f, 0f, 1f)` 

 ### Change background color