Game Programming - Episode 21 - Creating Sprites

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

Key Takeaways

Creates sprites in Java for game programming

Full Transcript

hey what is up guys my name is a chero and welcome to episode 21 of game programming Okay so yesterday we took a look at actually creating this Sprite class which was really cool and um is the basis for all future Sprites for our game um now today um we're actually going to take it a bit slower because yesterday I really felt that I sort of jammed in all of this um when I originally started the series I intended to do like a couple lines of code each video I did like freaking 27 yesterday so yeah I'm going to be taking a bit bit slower bit more in depth so that you guys can really you know understand um and because you know that is really the purpose of this series So Okay so we've got this Sprite class now how do we actually create Sprites with it now the way we're going to do it is basically legitimately create a Sprite so let's open up paint. net this is our Sprite Sprite sheet.png that we created last episode oh sorry two episodes ago so episode 19 we actually created this bright shade. PNG file and and with a grid all right so if we go into a grid here we're just going to create a Sprite like right over here um because and this is just going to be temporary so what we'll do is we will I'll just like you guys can create whatever artwork you want I'm not going to spend too much time on artwork that isn't the uh purpose of the series but I'm just going to create some nice grass here um maybe a bit like that um and actually that should be probably lighter just some nice um some nice grass oops all right so that's legitimately my grass for now just go with it so we've created a grass texture right now and let's just save it how do we actually use this grass texture in Java in in our game um and the way we do that is pretty simple we actually need to create a Sprite out of it now you might be like hang on you're creating a Sprite in the Sprite class how does that work well it's very simple because the thing is Sprites for us are going to be static because they will not change will they no they won't once you define a Sprite it will stay the same so let's just go public um public static Sprite so we're creating a new Sprite object right here in the Sprite class and and we'll call it grass and we'll actually set it equal to new Sprite so we're creating a new Sprite and then we got to fill out all of these things so first of all how big is it it's 16 right that's the size it's 16x 16 pixels x and y are 0 and zero because it's in the top left corner of this grid and the Sprite sheet is actually we kind of need to create that one so for now we'll probably just type in can't really type in sheet um for this Sprite sheet we might just leave that cuz we actually need to create the Sprite sheet first so for now we're going to leave it as null all right obviously that's not a good idea but um for now we'll leave it as null because we haven't actually created the Sprite sheet yet but this line of code guys is what you really need to actually learn and the reason is um this is what will actually create our Sprite okay if we were to reference it from a different CL class we would simply type sprite. grass and that's it that would give us this texture now how does this work first of all again it creates a new static version of the a new static instance of the Sprite class now remember every instance of the Sprite class has unique variables all of these because none of them are static it has a unique size it's got a unique coordinate it's got a unique pixel array which means that when we access sprite. grass's pixels right because again we're creating a new Sprite object so it contains everything that's in this class um except for this because it's static um when we when we create that we actually go through all this process we load the appropriate texture the appropriate uh texture or or Sprite into the pixel array so that when we then access sprite. grass. pixels it refers to the appropriate pixels because this is the grass object and we've to we've told it to load at this coordinate all right so go through this make sure you know this code because that is how we will create Sprites from now on that is how we will use Sprites from now on as well and um and yeah so once again the size we've specified the size we've specified the coordinate of it if this was say whoops if this was for example exle whoops damn if this was for example over here right instead of up there we would have to go 01 and I hope you understand that because that's like zero that's the x value and Y is 1 so Y is one down so that is that is how that works all right so that's how you create a new Sprite and um tomorrow we'll actually take a look at create at actually creating the Sprite shet because at the moment null isn't acceptable um I just completely forgot that we hadn't created the Sprite shet yet so we will have to create a Sprite sheet and we'll do that uh in tomorrow's episode so I hope you enjoyed the episode guys if you did please hit the like button let me know what you what you thought in the comments and I will see you guys tomorrow with a brand new episode of game programming until then guys goodbye [Music]

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 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 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
49 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

Related Reads

📰
Airtool vs Odoo: Why Business Momentum Matters More Than Business Growth
Business momentum is more important than business growth, focusing on sustainable progress over rapid expansion
Dev.to · ryan Insights
📰
Tesla’s Founders Are Backing The Anti-Cybertruck
Learn how Tesla's founders are backing a new electric truck company, TELO, and what this means for the future of electric vehicles
Forbes Innovation
📰
Industrialism and the slippery slope
Learn how industrialism can impact traditional businesses and customer perceptions, and why transparency matters in building trust
Seth Godin's Blog
📰
Why African women entrepreneurs remain overtrained and underfunded
African women entrepreneurs face challenges in accessing funding despite undergoing numerous training programs, highlighting the need for more effective support systems
TechCabal
Up next
Watch this before applying for jobs as a developer.
Tech With Tim
Watch →