Game Programming - Episode 8 - The Screen Class

The Cherno · Intermediate ·🚀 Entrepreneurship & Startups ·13y ago

Key Takeaways

The video covers the creation of a Screen class in Java for game programming, including setting up the class structure, constructor, and pixel array. The Cherno explains how to instantiate the Screen class and set its width and height parameters.

Full Transcript

hey what is up guys My Name Is AO welcome to episode 8 of game programming okay so last time we talked about buffet image and pixels and how um how you know we'd get the raster to actually uh upload uh pixel data to our buffer and intern um displayed onto the screen so we didn't actually change anything we still had this black um screen so what we're going to do today is actually talk about how we are going to manipulate those pixels so we've created a way to actually write to those pixels but how are we going to write to them and that's what we're going to cover today so first thing I'm going to do is actually create a new class so over here on our rain um folder I'm just going to right click hit new and click class and I'll just name it screen now I usually call this class screen and essentially what it is is our screen it's our class that actually displays our pixels that's all it does it just fills pixels in with colors that we specify so I'm going to name it screen you can also name it render I've called it render in the past as well I'm calling it screen hit finish um and this new class is going to have a few different uh things first of all um it's going to actually have a width and a height so private int width and we're not going to add anything to it and we also want private int height now instead of typing it out on two lines because you can see that they are both private integers we could just get rid of this and put a comma um dividing them and create them on one line so we're creating two variables on one line and again the name the names that we're specifying are being divided by this comma um now we're not going to uh we're we're actually going to set values to them um cuz we don't need to at the moment the other thing that I'm going to do is actually create a public int and this is going to be an array um and I'll just call it pixels and I'm not I'm not actually going to set anything to that as well we're not creating it yet so these two things this is going to be the width and the height of our screen and then this is going to be the array that contains all of our pixel data what I'm going to do what I'm going to do now is actually create a Constructor for them so public screen and it's going to take two parameters width and height both integers and I'll explain all this in a minute don't worry um and what I'm simply going to say here is that this do width equals width and this do height equals height okay so what are we doing here what we're doing here is if we go back to our um game class and actually create this screen object so right under running I'm just going to type private screen screen and again we're referring to our screen object and actually what I want to do is actually put that into a new package I'm actually going to put it into a sub package or a subfolder called graphics so if I just name Graphics here in the package and then actually you know move screen to that declaration you'll see that we've got a new folder here called graphics and this folder is going to contain all our classes that actually deal with graphics and stuff like that um and if I go here you'll see that it doesn't know where where screen is so we actually have to import it because it's in a different package than the game class so we'll import that and if we go over here when we want to create it and hit up screen equals new screen oops and we'll actually do this above the jframe right right over here um we actually need to enter parameters into it and the only things that we're going to enter is the width and height so we'll simply type width and height and again this refers to this width and this height so what's happening here essentially is we're creating a new instance of screen all right a new screen object and this do width equals width means that it's actually going to make this width over here equal to our parameter equal to whatever we put over here whatever whatever we put over here and same with height it's going to make this height in this in this screen class equal to this height which is this height so it's making width equal 300 and height equal width ID 16 * 9 um the thing we'll do is we'll actually create the pixel array now so we'll just type pixels equals new int and width times Hye okay so that's all that's all we're doing okay um to sum up this episode because I've got so much work over this weekend that I'm just not having time at all for this um what we've done today is we've created a screen class and we've actually instantiated that screen class as you can see we've set it equal to new screen we've created a new instance of a screen we've created a screen for ourselves and we've applied we've applied the size of our screen to these two variables so that we can now actually deal with the with um with these variables in our actual screen class and then tomorrow when we actually go on to rendering things by using pixels you'll um you'll be able to see how that works but what we've also done we we've created an array of pixels an array an array of inges which is the size of width time height so in other words we've created one integer for each pixel in our game okay we've created one integer for each pixel that is in our in our screen in our game so yeah tomorrow we'll move on to actually drawing um the uh pixels onto the screen the individual pixels onto the screen and we'll see if we can create something cool just to demonstrate the the power of this power of this game Manion so yeah I'm I'm sorry for the short episode guys but I've got to go so yeah hope you like the video if you did please hit the like button it uh it lets me know that you that you guys are actually enjoying this you know and um I'll see you guys tomorrow [Music] bye

Original Description

Support this series and get rewards! ► http://www.patreon.com/thecherno 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 Subreddit: http://www.reddit.com/r/thecherno/ Twitter: http://www.twitter.com/thecherno Facebook: http://www.facebook.com/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 · 49 of 60

1 3D Game Programming - Episode 1 - Window
3D Game Programming - Episode 1 - Window
The Cherno
2 3D Game Programming - Episode 2 - Game Loop
3D Game Programming - Episode 2 - Game Loop
The Cherno
3 3D Game Programming - Episode 3 - Arrays
3D Game Programming - Episode 3 - Arrays
The Cherno
4 3D Game Programming - Episode 4 - Drawing Pixels!
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
5 3D Game Programming - Episode 4.5 - How Rendering Works
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
6 3D Game Programming - Episode 5 - Playing with Pixels!
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
7 3D Game Programming - Episode 6 - Performance Boosting
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
8 3D Game Programming - Episode 7 - FPS Counter
3D Game Programming - Episode 7 - FPS Counter
The Cherno
9 3D Game Programming - Episode 8 - Alpha Support and More
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
10 3D Game Programming - Episode 9 - Beginning 3D
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
11 3D Game Programming - Episode 10 - Floors and Animation
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
12 3D Game Programming - Episode 11 - Rotation
3D Game Programming - Episode 11 - Rotation
The Cherno
13 3D Game Programming - Episode 12 - User Input
3D Game Programming - Episode 12 - User Input
The Cherno
14 3D Game Programming - Episode 13 - Render Distance Limiter!
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
15 3D Game Programming - Episode 14 - Basic Mouse Movement
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
16 3D Game Programming - Episode 15 - Textures + More!
3D Game Programming - Episode 15 - Textures + More!
The Cherno
17 3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
18 3D Game Programming - Episode 16.5 - Exporting Runnable Jars
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
19 3D Game Programming - Episode 17 - Small Adjustments + Birthday!
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
20 3D Game Programming - Episode 17.5 - Creating an Applet
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
21 3D Game Programming - Episode 18 - The Beginning of Walls
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
22 3D Game Programming - Episode 18.1 - A Few More Things
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
23 Episode 18.5 - Creating an EXE File in Java
Episode 18.5 - Creating an EXE File in Java
The Cherno
24 3D Game Programming - Episode 19 - Rendering Walls
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
25 3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
26 3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
27 3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
28 3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
29 3D Game Programming - Episode 24 - Making Our Launcher Work
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
30 3D Game Programming - Episode 25 - Writing and Reading Files
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
31 3D Game Programming - Episode 26 - Custom Resolutions
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
32 3D Game Programming - Episode 27 - Decorating the Launcher
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
33 3D Game Programming - Episode 28 - Continuing our Custom Launcher!
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
34 3D Game Programming - Episode 29 - Launching The Game
3D Game Programming - Episode 29 - Launching The Game
The Cherno
35 3D Game Programming - Episode 30 - Colour Processing In-Depth
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
36 3D Game Programming - Episode 31 - Sprites!
3D Game Programming - Episode 31 - Sprites!
The Cherno
37 3D Game Programming - Episode 32 - Sprite Mapping
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
38 3D Game Programming - Episode 33 - High Resolution Rendering
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
39 3D Game Programming - Episode 34 - Entities
3D Game Programming - Episode 34 - Entities
The Cherno
40 Genesis - My Game for Ludum Dare 24
Genesis - My Game for Ludum Dare 24
The Cherno
41 Vlog + Ludum Dare Results
Vlog + Ludum Dare Results
The Cherno
42 Game Programming - Episode 1 - Resolution
Game Programming - Episode 1 - Resolution
The Cherno
43 Game Programming - Episode 2 - Threads
Game Programming - Episode 2 - Threads
The Cherno
44 Game Programming - Episode 3 - Game Loop
Game Programming - Episode 3 - Game Loop
The Cherno
45 Game Programming - Episode 4 - Window
Game Programming - Episode 4 - Window
The Cherno
46 Episode 5 - Buffer Strategy
Episode 5 - Buffer Strategy
The Cherno
47 Game Programming - Episode 6 - Graphics Initialized
Game Programming - Episode 6 - Graphics Initialized
The Cherno
48 Game Programming - Episode 7 - Buffered Image and Rasters
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
Game Programming - Episode 8 - The Screen Class
Game Programming - Episode 8 - The Screen Class
The Cherno
50 Game Programming - Episode 9 - Rendering Pixels
Game Programming - Episode 9 - Rendering Pixels
The Cherno
51 Game Programming - Episode 10 - Clearing the Screen
Game Programming - Episode 10 - Clearing the Screen
The Cherno
52 Game Programming - Episode 11 - "Out of Bounds, Baby!"
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
53 Game Programming - Episode 12 - Negative Bounds
Game Programming - Episode 12 - Negative Bounds
The Cherno
54 Game Programming - Episode 13 - Timer
Game Programming - Episode 13 - Timer
The Cherno
55 Game Programming - Episode 14 - FPS Counter
Game Programming - Episode 14 - FPS Counter
The Cherno
56 Episode 15 - Tiles
Episode 15 - Tiles
The Cherno
57 Game Programming - Episode 16 - The Map
Game Programming - Episode 16 - The Map
The Cherno
58 The Walls 2 - Minecraft PvP Survival Map
The Walls 2 - Minecraft PvP Survival Map
The Cherno
59 Game Programming - Episode 17 - Key Input
Game Programming - Episode 17 - Key Input
The Cherno
60 Game Programming - Episode 18 - Controlling The Map
Game Programming - Episode 18 - Controlling The Map
The Cherno

This video teaches how to create a Screen class in Java for game programming, covering class structure, constructor, and pixel array setup. It also demonstrates how to instantiate the Screen class and set its parameters.

Key Takeaways
  1. Create a new Java class called Screen
  2. Set up the class structure with width and height variables
  3. Create a constructor for the Screen class
  4. Instantiate the Screen class and set its width and height parameters
  5. Create a pixel array to store pixel data
💡 The Screen class is a fundamental component of game programming, responsible for rendering graphics and handling pixel data.

Related Reads

Up next
Watch this before applying for jobs as a developer.
Tech With Tim
Watch →