Game Programming - Episode 38 - Procedural Rendering
Key Takeaways
The video demonstrates procedural rendering in game programming using Java, focusing on fixing black bars and optimizing rendering for a smoother look. It covers adjusting render tile methods, fixing edge values, and expanding the rendering zone to prevent the screen from going out of bounds.
Full Transcript
hey what's up guys My Name Is AO welcome to episode 38 of game programming so yesterday I keep saying that as if this show is daily last episode is what I mean you guys know that last episode we took a look at this freaking void tile thing well not not not really this void tile thing but this this problem here solving that array index out of bounds exception where if we go out of the bounds of the map we'll just simply return a voti that's what we did last time and today we're going to take a look at fixing this um procedual generation problem basically it's not really procedural generation more like procedural um rendering but you can see that every time we move we get these black bars basically and it just does not look very good now what this is though is it's like a I don't know I really like this I really do because it it shows very clearly how how this thing is rendering because you can see that basically as as soon as we access a tile further down here it's cutting out a tile here so we're not actually rendering the entire map at once we're just rendering what we see in this little window which is beautiful as you can see we're running at freaking 4,000 frames per second and that's just freaking insane so um that's that's brilliant um then again I do have a supercomputer so you guys probably won't be running that fast but the point is we're still running extremely fast which is awesome so now we need we need to fix this because like from a technical standpoint this looks freaking amazing but from an aesthetical standpoint n not really so we we sort of want to fix that up and make this really smooth now there are a few things we need to do to actually achieve that first of all you'll you see that we've actually got three areas of black barness it's not happening to the vertical it's not happening to this this edge of the screen the top edge of the screen not exactly sure why but well it's just not so let's just roll with that um but yeah it's not happening to the top so we don't need to do anything about that that's beautiful it is happening to the bottom the left and the right so yeah let's think about that so first of all first thing you need to consider is what is happening with each Edge now the two of these edges have something in common and that is the bottom one and the right one and the reason they have something in common the thing that they have in common here is the fact that they are actually like the exceeding like things right so in other words because remember 0 0 the coordinate 0 0 is in the top left corner um in our game all right which means that this is the far right and this is like the far bottom corner this is like zero the the top and left they're both zero but the right one is width and the bottom one is height that is what those edges are equal to um and so to deal with them we'll clearly need to do something about height and width respectively to actually you know fix this fix the right and the bottom corners uh edges rather but for the left side we actually have to do something with well with zero basically we need to do something with zero now it is currently set to zero but you can see the zero just is not low enough and we actually have to go a bit lower we need to go deeper uh but we need to go a bit lower to actually fix this thing so how are we going to do that so let's let's talk about fixing the left side for a minute so to fix that we'll go into our screen. Java class and right over here in render tile that's where all the magic happens so at the moment you can see that we're actually breaking right we're breaking when XA is less than zero and now X is obviously the problematic Zone here because X is our our horizontal and that's where our problem is on the left side um it's when it's less than zero it's breaking now zero does not seem to be low enough so yeah it looks like it's actually offset by an entire tile if we go over here that's basically the size of a tile right it is if you freaking draw that there that's pretty much the size of the tile it might be like two pixels less but point is we'll just assume that that's the size of the size of the tile especially to be safe anyway so to fix that let's just simply you know set it to minus one tile that way so- one tile left so basically we can just set it to- 16 but again to Future proof this thing we can set it uh to- tile. sprite. size because tile. sprite. sizes is 16 remember in this case and we'll just you know basically multiply by -1 to make it -16 and that is it if we actually run this now first of all uh if we run this um you'll see that we crash and the reason we crash obviously is uh actually you know what let's let's debug this for you guys um you can see we've crashed here because XP value is15 so it's obviously going to be an r index out of bounds exception because pixels the index of pix pixels that is trying to look up is actually returning a negative number you can see right here it's -5 that's a problem so in order to fix that we simply need to say all right well don't break in that case if it's negative if if it goes into the negative don't necessarily break let's first of all because what remember what it's doing is it it's it's it's only breaking when it's less than -16 but what if it's -10 for example you know that's that's going to that's kind of passed through this it's not going to break in that case but what it is going to do is throw throw a reex out of bounds exception so what we'll say is all right well if if it is10 for example don't don't really break right cuz we've said it not to break which is good because before it did break let's not break but let's just let's just set it to zero so if XA is less than zero let's just set XA equal to Z and what what that will do is actually say that if it's less than zero well it's is going to make it equal Zer and as you can see that fixes our problem now our left side is beautiful now not what you guys are thinking you guys are thinking oh well that was easy let's do the same thing to X to um this and we'll just you know we'll just we'll just add on 16 to both width and height and that'll be fine no it won't be fine you can't do that can't do it for that all right what we can do however is going into our level class and actually expand this rendering Zone we can't actually do it for this is actually kind of kind of like a a phenomenon or something for some reason we can't actually do the negative stuff to x to the to the to the uh lower corner pins so x0 and y0 but we we can sort of expand the X1 and y1 so it's it's bit interesting but the thing is at the moment we're looking up X scroll plus plus screen width which gives us one basically one full like tile thing right you can see that's exactly like one full one full tile thing but then we sort of cross over here right and you can see that it's sort of off it's it's out by one tile again for both sides so what we can do is simply add on the size of one tile so literally just add on 16 till the end and again what that is going to do is it's going to get the X scroll and Y scroll values and it's going to add on the width and then it's going to add on a further 16 just just to be one tile safe so it's going to just render one more tile and that'll sort of prevent that screen thing now um what we've got here you can see is a perfectly running thing and you can see that we're still running at pretty much the same frame rate this screen recorder sort of mock things up a bit but you can see that we're running about 3,700 frames per second and uh and that's great so we fixed it with minimum performance impact again of course there will be a very very slight performance impact because we are actually rendering one one more tile horizontally and vertically and the other way horizontally as well but you know that's that's the price we pay to make our game look nice um one last thing I'll mention quickly is yeah we've got this issue here where it's 16 and it's not tile it's it's not actually the size of the tile uh there's several ways we're going to fix that um so in other words you can see that over here in our screen class we actually you manag to go to by the size which we can't do here um in our level thing but that's all right um we'll we'll fix that later on when we actually you know change this This Ti method a bit but yeah so anyway that's what we get that's what we get our beautiful result of the game which now looks really nice basically looks freaking amazing it's ready to freaking put in put a pre-alpha version up on a website and get people to download it cuz it's it's pretty damn good um but yeah that is the end of this episode I hope you enjoyed this episode if you did please hit that like button give this video a favorite cuz it was freaking amazing and I will see you guys next time goodbye
Original Description
Welcome to Game Programming, a series in which we take an in depth look at how to make a game from scratch, in Java.
----------------------------------------------------------------------------------------------------------------
Website: http://www.thecherno.com
Twitter: http://www.twitter.com/thecherno
Facebook: http://www.facebook.com/thecherno
Subreddit: http://www.reddit.com/r/thecherno/
Steam Group: http://www.steamcommunity.com/groups/thecherno
----------------------------------------------------------------------------------------------------------------
Outro music is by Approaching Nirvana: http://www.youtube.com/approachingnirvana
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from The Cherno · The Cherno · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
3D Game Programming - Episode 1 - Window
The Cherno
3D Game Programming - Episode 2 - Game Loop
The Cherno
3D Game Programming - Episode 3 - Arrays
The Cherno
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
3D Game Programming - Episode 7 - FPS Counter
The Cherno
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
3D Game Programming - Episode 11 - Rotation
The Cherno
3D Game Programming - Episode 12 - User Input
The Cherno
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
3D Game Programming - Episode 15 - Textures + More!
The Cherno
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
Episode 18.5 - Creating an EXE File in Java
The Cherno
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
3D Game Programming - Episode 29 - Launching The Game
The Cherno
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
3D Game Programming - Episode 31 - Sprites!
The Cherno
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
3D Game Programming - Episode 34 - Entities
The Cherno
Genesis - My Game for Ludum Dare 24
The Cherno
Vlog + Ludum Dare Results
The Cherno
Game Programming - Episode 1 - Resolution
The Cherno
Game Programming - Episode 2 - Threads
The Cherno
Game Programming - Episode 3 - Game Loop
The Cherno
Game Programming - Episode 4 - Window
The Cherno
Episode 5 - Buffer Strategy
The Cherno
Game Programming - Episode 6 - Graphics Initialized
The Cherno
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
Game Programming - Episode 8 - The Screen Class
The Cherno
Game Programming - Episode 9 - Rendering Pixels
The Cherno
Game Programming - Episode 10 - Clearing the Screen
The Cherno
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
Game Programming - Episode 12 - Negative Bounds
The Cherno
Game Programming - Episode 13 - Timer
The Cherno
Game Programming - Episode 14 - FPS Counter
The Cherno
Episode 15 - Tiles
The Cherno
Game Programming - Episode 16 - The Map
The Cherno
The Walls 2 - Minecraft PvP Survival Map
The Cherno
Game Programming - Episode 17 - Key Input
The Cherno
Game Programming - Episode 18 - Controlling The Map
The Cherno
More on: AI Systems Design
View skill →Related Reads
📰
📰
📰
📰
Computer Applications for Primary School Children: A Fun + Safe Guide for Ages 6-12
Dev.to · Ogunkola Adeola
From 0 to 20 Chapters: My Story‑Driven Rust Book for Kids Now Has a Bilingual Interactive Demo
Dev.to · born1987-ir
How Kids Can Build Fighting Games Stickman in Scratch
Medium · Programming
Coding Platform for Kids: A Simple Guide to Start Learning Programming
Dev.to · Coding Learning Lab
🎓
Tutor Explanation
DeepCamp AI