Game Programming - Episode 21 - Creating Sprites
Skills:
AI Pair Programming60%
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
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 Pair Programming
View skill →Related Reads
📰
📰
📰
📰
Airtool vs Odoo: Why Business Momentum Matters More Than Business Growth
Dev.to · ryan Insights
Tesla’s Founders Are Backing The Anti-Cybertruck
Forbes Innovation
Industrialism and the slippery slope
Seth Godin's Blog
Why African women entrepreneurs remain overtrained and underfunded
TechCabal
🎓
Tutor Explanation
DeepCamp AI