Java Programming: Let's Build a Game #2

  Рет қаралды 323,623

RealTutsGML

RealTutsGML

Күн бұрын

Make Video Games 2018 ► www.codingmade...
In this video we finish up the back end work for our game and set up the GameObject class which will make the game a lot easier to work with later down the line. If you have any questions then be sure to leave a comment or contact me on twitter; realtutsgml. If you learned something then be sure to leave a like, comment, and favorite.
Have you ever wanted to create games? Have you ever gotten fed up with it being to difficult? Well now is the time to thank me and possibly subscribe because you have just found the channel for you! Game Maker Tutorials, Java Game Programming, Unity3D Tutorials, Batch, C++ and much much more! This is the channel for you, the one stop shop for an exploration of your hidden talent as a game developer. Unleash your potential and go wild with imagination when you finally figure out how to make any game you want!
Visit CodingMadeSimple for more exclusive tutorials and get the help you need to succeed as your very own indie game developer!
www.codingmades...
Follow me on twitter for exclusive content and interaction with me!
/ realtutsgml
Follow me on Google+ to keep updated with all of my tutorials
www.google.com/...
Game Maker Studio: Programming
Game Maker Studio: Tutorial
Java Programming
Game Programming
Game Tutorial
Programming Tutorial
• Java Programming: Let'...

Пікірлер: 830
@MistaT44
@MistaT44 6 жыл бұрын
I remember coming to this tutorial last year not knowing what was going on and quit. Now I am in final year of my SE degree, done my internship for 3 months in JAVA. Now this is all understandable and looks like a piece of cake. Stay motivated guys. And great series of tutorial!
@vivanecrosis
@vivanecrosis 3 жыл бұрын
Totally agree, stick with it. Thankfully I already learnt the fundamentals of Java before coming here, so its great fun :D
@brianward5928
@brianward5928 4 жыл бұрын
I like how he says that this isn't fun and I'm jumping around like a kid because I'm enjoying myself so much
@AlecC0l
@AlecC0l 3 жыл бұрын
same
@vivanecrosis
@vivanecrosis 3 жыл бұрын
Totally is fun, especially when the boxes fly about at random!
@fjildeth
@fjildeth 3 жыл бұрын
It's fun cuz he does it in a way that we understand what's what,. it'd be boring if we didn't know, just like how I'd damn wanna sleep in my Math classes
@placek0703
@placek0703 4 жыл бұрын
Using abstract class, threads, abstract methods. Explaining only loop "for"
@Domenic367
@Domenic367 4 жыл бұрын
omg i thought the same thing lol. He explains the things people already should know but not the unusual.
@tanishtyagi1301
@tanishtyagi1301 4 жыл бұрын
@@Domenic367 yeah
@dadik7466
@dadik7466 4 жыл бұрын
@@tanishtyagi1301 like to do this tutorial, you have to know a java a little
@mizzeti
@mizzeti 3 жыл бұрын
Haven't you paid attention? I am literally a beginner and I understood what abstract methods are.
@placek0703
@placek0703 3 жыл бұрын
@@mizzeti i know what is abstract method but its just funny that he spend more time on explaining for loop than explaining abstract method.
@markuscwatson
@markuscwatson 4 жыл бұрын
to create the rectangle I am having trouble instantiating the Player Object any tips?
@martijnkupers2021
@martijnkupers2021 7 жыл бұрын
why do you use an LinkedList instead of ArrayList? Nice tutorial btw, learned a few usefull things thanks to it!
@joaomig1
@joaomig1 5 жыл бұрын
LinkedList is faster at adding and removing objects.
@_slier
@_slier 9 жыл бұрын
why use linkedList instead of normal list?
@rohantripathy3734
@rohantripathy3734 6 жыл бұрын
Hey!!! I can't find the white patch
@ahmadhajoj1125
@ahmadhajoj1125 5 жыл бұрын
Why you created x and y its the enemy variables? And protected can be accessed just by object?
@hakansjoberg4965
@hakansjoberg4965 8 жыл бұрын
Great work! Thx.
@MrBestboy321
@MrBestboy321 7 жыл бұрын
My white boxes aren't showing up after I put the move command in
@MrBestboy321
@MrBestboy321 7 жыл бұрын
It happens when I add the velX = something
@davemorris6308
@davemorris6308 7 жыл бұрын
Are you saying they disappear off the screen after you try to move with a button like W or UP ARROW?
@mohhamedali4249
@mohhamedali4249 8 жыл бұрын
for me, when I change the x int for the object it doest do anything, only the y int makes the object move, idk what I did wrong
@mohhamedali4249
@mohhamedali4249 8 жыл бұрын
+Mohhamed Ali never mind I figured it out
@fatinkhan
@fatinkhan 8 жыл бұрын
+Mohhamed Ali what did you do?
@carpinchoboludo
@carpinchoboludo 9 жыл бұрын
What program are you using to code in?
@ayeama5070
@ayeama5070 9 жыл бұрын
Eclipse IDE, www(DOT)eclipse(DOT)org/downloads/
@carpinchoboludo
@carpinchoboludo 9 жыл бұрын
thanks
@watercoconut13
@watercoconut13 9 жыл бұрын
} public static void main(String args[]){ new Game(); } } it keeps saying Exception in thread "main" java.lang.Error: Unresolved compilation problems: how do i fix this
@lechi_2002
@lechi_2002 8 жыл бұрын
In Eclipse, use alt + shift + s to generate getters and setters
@asbestosrecuperation
@asbestosrecuperation 8 жыл бұрын
I believe the point of it was not to do it faster, but to explain it to the audience.
@TheKlopka
@TheKlopka 6 жыл бұрын
all you need is to press alt s
@marianaguimaraes7357
@marianaguimaraes7357 6 жыл бұрын
Orrr click on the right mouse button, source and Generate getters and setters ;)
@pranavpolakam5371
@pranavpolakam5371 5 жыл бұрын
Tudor Lechintan thanks I've used eclipse for a couple years now and I didn't know about that shortcut 😅😅 thanks again!
@Norogoth
@Norogoth 4 жыл бұрын
alt + insert for IntelliJ
@wehubbard
@wehubbard 8 жыл бұрын
Explains protected -- skims right past serialVersionUID, synchronized, threading, and BufferStrategy. #tutorial
@gerechjorney5547
@gerechjorney5547 5 жыл бұрын
ikr, protected its like super basic, and some of that shit i never even heard about it
@landro3552
@landro3552 5 жыл бұрын
@@gerechjorney5547 When I execute the code it gets really laggy. I can't really click anything without thaving to wait 20 sec to get feedback. Cursor moves normally. Someone knows why?
@amuzak9063
@amuzak9063 5 жыл бұрын
@@landro3552 How many game objects do you have running?
@blackmamba208
@blackmamba208 5 жыл бұрын
Brother explained frickin' for loop
@LetsPlayCodx
@LetsPlayCodx 5 жыл бұрын
Lol it made me think I was dumb for not not knowing what they are
@myrus5722
@myrus5722 3 жыл бұрын
If you get an error of the handler being “null”, move the line new “Window(WIDTH, HEIGHT …” below the line “handler = new Handler()”
@smartidiot1156
@smartidiot1156 2 жыл бұрын
Thank you so much, i was so confused and almost had to go through both the videos again to see what was going wrong in my code
@myrus5722
@myrus5722 2 жыл бұрын
SmartIdiot Yeah I remember that taking me a while to figure out. I think he addresses it somewhere in the middle of the next part I’d my memory is correct. Glad I saved you time :)
@_kijetesantakalu
@_kijetesantakalu 8 жыл бұрын
17:18 That's odd. I paused the videp, and when I ran my game, and I saw the white box, I said "Check that out", and when I un-pause the video, I head "Check that out"
@atrune
@atrune 7 жыл бұрын
Great video thanks, really made it easy to get everything going! the only thing I find pretty funny is you gloss over things like inheritance and abstract classes, but then at 12:45 you completely explain the workings of a for loop.
@Turk656
@Turk656 4 жыл бұрын
Mate, you've saved my ass in my software dev midterm project. I was pulling my hair out trying to get my implementation to work, your vids helped me understand what's what while not taking 3 years to get to the damn point lol
@eugene1776
@eugene1776 3 жыл бұрын
the most frustrating thing is having a problem and having no idea what it is or how to fix it :/
@DecoratorFawn82
@DecoratorFawn82 8 жыл бұрын
Anyone who's having trouble with their squares moving to fast, then add: lastTime = now; In the Game class in the run()-method below the line: delta += (now - lastTime) / ns; Like this: delta += (now - lastTime) / ns; lastTime = now; while (delta >= 1) { tick(); delta--; }
@saacology
@saacology 8 жыл бұрын
omg ty soo much! ive watched the first three videos 7 times and couldn't find the fix, this helps alot!!! ty!
@noureddineziani9067
@noureddineziani9067 7 жыл бұрын
Dude you're Awesome I was like daaamn my wooden pc is going to fast !! thx so much !! for beginners : add : lastTime =now just after the line : delta+=(now - lastTime)/ns;
@bidoof3493
@bidoof3493 7 жыл бұрын
Ziani Nordine That was part of the code he wrote?? my squares are still going too fast
@Ryan-cy2jl
@Ryan-cy2jl 7 жыл бұрын
congratulations? you told people to add a line of code that already existed.....
@chrisZACKwhitehead
@chrisZACKwhitehead 6 жыл бұрын
Thank you SO MUCH! I was wondering why my program was so speedy! This definitely fixed it.
@bebojo21
@bebojo21 5 жыл бұрын
*If you're getting an Exception in thread NullPointerException error* put 'handler = new Handler();' *before* 'new Window(WIDTH, HEIGHT, "Game", this);' he talks about it in the beginning of the 3rd episode.
@licolhavaiia2205
@licolhavaiia2205 5 жыл бұрын
I love you
@DiligentGalaxy6
@DiligentGalaxy6 5 жыл бұрын
Thanks so much!
@flamme78420
@flamme78420 8 жыл бұрын
10:54 Pro tip: On eclipse, if you want to write out all the getters and setters, you can! but you could also go to Source>Generate Getters and setters, pick the attributes you want to get and set and TADA, eclipse does the boring stuff for you!
@dudejoe8705
@dudejoe8705 8 жыл бұрын
+Bruno Robert I know! Use it ALL.. THE... TIME!!
@fatiharslan7849
@fatiharslan7849 4 жыл бұрын
Explains protected, constructor and for loop skips everything else
@leapbtw
@leapbtw 3 жыл бұрын
why explaining abstract classes when you can explain for loops
@vivanecrosis
@vivanecrosis 3 жыл бұрын
He is giving us homework. Thankfully I know most of that before I came here, so its not too bad.
@kowski567
@kowski567 4 жыл бұрын
when i do: handler = new Handler(); i get an error that says: Cannot instantiate the type Handler
@loganquisdorf7428
@loganquisdorf7428 4 жыл бұрын
For some reason it won’t call back to my graphics variable, it’s all typed in correctly but it says graphics can not be resolved to a type
@pizzasteve205
@pizzasteve205 4 жыл бұрын
@@loganquisdorf7428 im getting the exact same thing, im not 100% sure what is causing it
@_kijetesantakalu
@_kijetesantakalu 8 жыл бұрын
Programming coming at cha with supersonic speed i... public class Game extends Canvas implements Runnable{ private static final long serialVersionUID = 1550691097823471818L; public static final int WIDTH = 640, HEIGHT = WIDTH / 12 * 9; private Thread thread; private boolean running = false; private Handler handler; public Game(){ new Window(WIDTH, HEIGHT, "thing", this);
@user-rf4vc7mt4d
@user-rf4vc7mt4d 4 жыл бұрын
lmao im beginning to feel like a code god code god
@asutoshvariar
@asutoshvariar 4 жыл бұрын
@@user-rf4vc7mt4d All the coders from the front to back nod, back nod.
@daemon4683
@daemon4683 8 жыл бұрын
3:10... The most botched explanation of anything ever! LOL. Jk, good job once again.
@RealTutsGML
@RealTutsGML 8 жыл бұрын
+daemon Lol
@danieltrottier8599
@danieltrottier8599 8 жыл бұрын
+RealTutsGML You saved it by making the player class.
8 жыл бұрын
Please zoom it next time :)
@MaeveFirstborn
@MaeveFirstborn 8 жыл бұрын
Protected means that this is protected means protected means that this is protected.
@Ian-pc5it
@Ian-pc5it 7 жыл бұрын
public - visible to external classes, sub-classes, and within the class protected - visible to sub-classes, and within the class private - visible only within the class the field or method was defined in (and to the JVM)
@FaCu1430
@FaCu1430 3 жыл бұрын
Hi! For those who are trying this with any Linux distribution and are having lag problems, you can add: "System.setProperty("sun.java2d.opengl", "true");" In the main. Windows has graphics accelerators enabled by default, but that's not the case for Linux. It will reduce your FPS but the game will run smoother. Great videos btw!
@ryanfisher9187
@ryanfisher9187 Жыл бұрын
That was a huge help, thank you very much!
@DanFletcher90
@DanFletcher90 8 жыл бұрын
Nice job with these tutorials! I'm relatively new to Java, so this is a nice way to get more familiar with it, while building something fun.
@leapbtw
@leapbtw 3 жыл бұрын
12:40 i like how he is explaining for loops and not the list thing but ok
@koekeritisVideos
@koekeritisVideos 9 жыл бұрын
What's the difference between a linkedList and an arrayList?
@Halvard1992
@Halvard1992 8 жыл бұрын
+koekeritis probably a bit late, but since it's the top comment I figured I'd leave an answer. Arrays are immutable, so if you want to add an element to them, you've got to create a whole new array. Meaning that arrayList's actually are creating new arrays under the hood each time you add an element. As you can imagine re-creating arrays of hundreds or thousands of elements is quite inefficient. That's where linkedLists come in handy. All elements have links to it's next element, so they're easy to replace - kind of like legos, to simplify it. Arrays are however MUCH faster for finding an element at a specific index.
@koekeritisVideos
@koekeritisVideos 8 жыл бұрын
+Professor Chaos Thank you for the explanation, albeit a bit late. Since I posted this comment my programming skills have evolved, but I never knew this until now.
@WurstschneideBrot
@WurstschneideBrot 8 жыл бұрын
+koekeritis It's okay, because this is very useful for people with the same problem like me ;)
@koekeritisVideos
@koekeritisVideos 8 жыл бұрын
WurstschneideBrot ;)
@Kritya
@Kritya 8 жыл бұрын
+koekeritis To clarify, the difference between the two isn't really something you see from the programming side, the differences are things the computer handles. To get to index 7 in a linkedlist from index 0 you need to go through 1, 2, 3, 4, 5, 6 following this links, while in an arraylist you can jump straight to index 7. Lookup is quicker in an arraylist, however once the arraylist is full and you try to add something it has to rebuild the entire list, this creates inconsistencies in timings for adding elements which isn't present in linkedlist, where each add takes the same amount of time. Most people lean towards arraylist due to the quicker lookup, however in a scenario where adding an element is time critical and needs to be consistent in terms of time take linkedlist is the option to go with.
@7own878
@7own878 3 жыл бұрын
Nothing beats the joy of a seeing a small white box on a black background with 2500 FPS for the first time.
@GichiKya
@GichiKya 8 жыл бұрын
In the Handler class for the functions tick and render, I'd recommend not using the get function since it is a linked list and the get function is rather slow. Use an iterator if you know how or use this for each loop: for (GameObject obj : object) { obj.tick(); } It won't cause any lag for simple games like this but it's best to get into the habit of keeping things as efficient as possible.
@isabellstahl5579
@isabellstahl5579 9 жыл бұрын
Why not auto generating getters and setters? would take 10 seconds :/
@nickhahn8773
@nickhahn8773 9 жыл бұрын
Could you please explain how you're doing this. Im really new to this... or at least give me a video or website. Thanks and happy developing. ^^
@isabellstahl5579
@isabellstahl5579 9 жыл бұрын
+Nick Hahn use eclipse for this, there is an option for this
@YuKi-ky5lr
@YuKi-ky5lr 9 жыл бұрын
+Nick Hahn Go to source and press generate getters and setters
@manykoalas2735
@manykoalas2735 7 жыл бұрын
alt + shift + s > Generate Getters and Setters (I realise, you've either moved on or figured it out by now )
@LoldemortII
@LoldemortII 7 жыл бұрын
I could cry, I didn't know that existed T_T
@yoink7324
@yoink7324 5 жыл бұрын
At 17:40 in the video, when I do the handler.addObject code, the square pops up at the very top left of the little screen, same with the second square. Does anyone know why?
@anyoldjoe4539
@anyoldjoe4539 5 жыл бұрын
you may have written =+ instead of +=
@CybrNight
@CybrNight 8 жыл бұрын
For the for loop you could have done for (GameObject tempObject : object){ tempObject.tick(); } and the same for the render method
@austingeometry3540
@austingeometry3540 5 жыл бұрын
This help me a lot Thanks for the code.
@ahmadhajoj1125
@ahmadhajoj1125 5 жыл бұрын
Your really good teacher brother now i start understand you cuz my english was bad because i read google alot i improved my english now i am going good with ur videos can you please make applications also not games i wanna learn apps bro
@UsernameNULL755
@UsernameNULL755 9 жыл бұрын
one question: why did we need that enum? we could determine the type of an object by using "instanceof" operator
@brujua7
@brujua7 5 жыл бұрын
Your proposal its a bad practice, now you are tied to the class.
@trythrusting9980
@trythrusting9980 4 жыл бұрын
It's put simply: Easier to use. All you have to do now is just add into Enum and you are good to go
@__juniper
@__juniper 4 жыл бұрын
I've checked several times, my code is exactly the same as in the video, but my squares aren't moving at all, anyone else had this problem?
@__juniper
@__juniper 4 жыл бұрын
Nevermind figured it out after rewatching, turns out I forgot to put handler.tick(); in Game.java's tick() method.
@ItsSkyHighlights
@ItsSkyHighlights 3 жыл бұрын
12:14 // As of right now, you can also write the for-loop like this: for(GameObject tempObject : this.objects) { tempObject.tick(); } // Same thing for render: for(GameObject tempObject : this.objects) { tempObject.render(g); }
@dr4ghs
@dr4ghs 8 жыл бұрын
Just a little tip on the tick and render methods in the Handler class. Those for loops can be replaced with a for each loop like this: for(GameObject o : object) o.tick(); Basically is the same thing, but since you won't modify the object that are gonna be ticked, this loop is more efficent. Great video tho.
@bratttn
@bratttn 9 жыл бұрын
Array list works ALOT better with index access than linked list. A beginner's mistake. Also a local variable is recommended fot the size() reference before starting a loop, since a list size() is a method and the access to it is slower than to a primitive type.
@regalrayquaza7609
@regalrayquaza7609 5 жыл бұрын
Does anybody know why I should waste time with getter and setter methods when I can just access the variable directly? like if I have a Player p can't I just say p.x = 100 instead of p.setX(100)? It seems like its quicker and neater with no downside to me, yet everything I see insists on using such methods. Can anyone clear this up for me?
@RealTutsGML
@RealTutsGML 5 жыл бұрын
It's better to make your variables private. If the variables are private then you can't access it through the dot operator like p.x That's why the getters and setters methods are put in. Notice how they are public methods changing private variables.
@jhbigler6401
@jhbigler6401 4 жыл бұрын
using get() on a linked list in a loop is not the most efficient way to iterate through a linked list, because the get() method for linked lists has a linear run time (this matters if you have a large amount of elements in the list). You might want to instead use: for(GameObject g : object) { //do something with g }
@aeronamics
@aeronamics 2 жыл бұрын
Exactly my thought, perhaps better to use a arraylist 😊
@tymocha9
@tymocha9 10 жыл бұрын
at 14:54 addObject for me says void is an invalid type for variable addObject. Help Pls!
@kylemyers1956
@kylemyers1956 8 жыл бұрын
in your tick and render method it might be better to use iterators since you are using a LinkedList. that way you don't have to follow the whole list every time and can just step through. I am not sure how java implements linked lists but unless it knows where every element is (basically a tier 1 tree at that point) that would make complexity O(n) rather than O(n!). ex : for(ListIterator i = object.listIterator(0); i.hasNext();){ GameObject tempObject = i.next(); ... or beter still use the for each loop for (GameObject tempObject : object){ tempObject.render(g); } Just a suggestion though, I liked the video though so good job.
@DanFletcher90
@DanFletcher90 8 жыл бұрын
+Kyle Myers Hi, Java's LinkedList is a DoublyLinked list and has a pointer to both the head and the tail - but what you said makes perfect sense. When iterating through a LinkedList it's better to use an Iterator rather than using get() each time. Your way also looks nice and clean too :) Another more verbose way for others who might be reading this: Iterator i = object.iterator(); // creates iterator of GameObject. assigns it to 'i'. while (i.hasNext()) { // when this is false, there are no more objects left in the LinkedList. GameObject tempObject = i.next(); // next() always returns the next object in the LinkedList. tempObject.render(g); } Of course you have to import Java.util.iterator too.
@kylemyers1956
@kylemyers1956 8 жыл бұрын
Thanks for your feedback. I think that your way definitely helps to understand what is going on, so thanks for the clarification.
@joshua.lau_
@joshua.lau_ 8 жыл бұрын
Can someone help PLS i typed in handler = new Handler(); handler.addObject(new Player(100, 100, ID.Player)); already, but the player square isn't showing up. I followed exactly what he did. Any ideas?
@joshua.lau_
@joshua.lau_ 8 жыл бұрын
+DiamondOrespawn I found the problem. Check if your getters and setters have extra words....
@jamesbaldock4140
@jamesbaldock4140 8 жыл бұрын
+DiamondOrespawn 16:34, did you set render for Player correctly?
@AlexBoscan
@AlexBoscan 7 жыл бұрын
you have to delete the abstract keyword in the player class like here: package com.tutorial.main; import java.awt.Color; import java.awt.Graphics; public class Player extends GameObject { public Player(int x, int y, ID id) { super(x, y, id); // TODO Auto-generated constructor stub } public void tick() { } public void render(Graphics g) { g.setColor(Color.white); g.fillRect(x, y, 32, 32); } }
@cameronheydeman3591
@cameronheydeman3591 9 жыл бұрын
The excitement when you have a white box!
@grzegorzsmolak8947
@grzegorzsmolak8947 2 жыл бұрын
14:21 wouldn't it be better to use ArrayList instead of LinkedList? I don't think that get() fuction is very fast on LinkedList
@Co1010z
@Co1010z 2 жыл бұрын
Yes the handler render and tick methods run in O(n^2) because LinkedList get takes O(n) time. Using an arraylist is better.
@NUAProductions1
@NUAProductions1 9 жыл бұрын
Help pls, I did everything you did but my white box doesn't show up.
@NUAProductions1
@NUAProductions1 9 жыл бұрын
code: pastebin.com/RfwH7RXa
@ishersagay1237
@ishersagay1237 9 жыл бұрын
***** rick roled
@ishersagay1237
@ishersagay1237 9 жыл бұрын
Nerf Army did u
@itachi-ff8sx
@itachi-ff8sx 9 жыл бұрын
+Albin Eriksson same problem checked the code like million times same thin only difference is that i am working in netbeans
@itachi-ff8sx
@itachi-ff8sx 9 жыл бұрын
+G0ldRog3r nah still having the problem
@MLGGuy420
@MLGGuy420 8 жыл бұрын
Exception in thread "Thread-2" java.lang.IndexOutOfBoundsException: Index: 50, Size: 50 at java.util.LinkedList.checkElementIndex(Unknown Source) at java.util.LinkedList.get(Unknown Source) at com.fardindadev.TestGame.Handler.render(Handler.java:20) at com.fardindadev.TestGame.Game.render(Game.java:101) at com.fardindadev.TestGame.Game.run(Game.java:69) at java.lang.Thread.run(Unknown Source) i got those errors
@mycatis4257
@mycatis4257 4 жыл бұрын
Sorry for the question, but when we use the variable i in Handler I get an error because "Variable 'i' is already defined in the scope". Does anybody know how I can fix it?
@GuillaumeRivard98
@GuillaumeRivard98 7 жыл бұрын
Hey @RealTutsGML I already follow a course, but I'm interested by your book, how much you are selling it? thx for your video, that help me a lot :)
@pridful6103
@pridful6103 4 жыл бұрын
Hey man i like your videos, keep it up. I followed your instructions, but when i run the game, for some reason, the white boxes that we created dont show up ..
@mikaelkolehmainen9098
@mikaelkolehmainen9098 4 жыл бұрын
If the squares just teleport of your screen try this: Instead of using double amountOfTicks = 60.0; double ns = amountOfTicks / amountOfTicks just use this: double ns = 10000000 you can tweak the speed by changing how many 0 there are.
@dontcareaboutnames5608
@dontcareaboutnames5608 3 жыл бұрын
Is there any way to make it even slower?
@mikaelkolehmainen9098
@mikaelkolehmainen9098 3 жыл бұрын
@@dontcareaboutnames5608 I don't remember fully, but I think it was with adding more 0s to the double ns
@thephrog9812
@thephrog9812 4 жыл бұрын
i need help the box isn't showing up on my window
@vishalkotha2068
@vishalkotha2068 8 жыл бұрын
Am I the only one who focused on the Frame Per Second and saw that the last FPS printed by the game loop is "2013"
@vishalkotha2068
@vishalkotha2068 8 жыл бұрын
+TheRuler OfOlympia At the beginning
@tam7117
@tam7117 6 жыл бұрын
no , i saw that too
@jacobericsson195
@jacobericsson195 7 жыл бұрын
it is acctually quite satisfying to watch you work. i¨v never done any programming at all, it is just satisfying to watch this vid haha. keep up the good work man!
@MysticalApple
@MysticalApple 5 жыл бұрын
At 20:16, I paused the video and spent a while trying to figure out why my boxes were shrinking. Until it hit me. Optical Illusions.
@singhasportschannel
@singhasportschannel 4 жыл бұрын
If your window is all screwed up put this code in the window.java package com.tutorial.main; import java.awt.Canvas; import java.awt.Dimension; import javax.swing.JFrame; public class Window extends Canvas{ private static final long serialVersionUID = -240840600533728354L; public Window(int width, int height, String title, Game game) { JFrame frame = new JFrame(title); frame.setPreferredSize(new Dimension(640, 480)); frame.setMaximumSize(new Dimension(640, 480)); frame.setMinimumSize(new Dimension(640, 480)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.add(game); frame.setVisible(true); game.start(); } }
@WeiseGuy91
@WeiseGuy91 8 жыл бұрын
Around 18:10, you have the two squares moving. Your squares move very smoothly. Mine have an obvious pause, tick (move right 1 pixel), pause, tick, etc. It's about half a second to a full second between movements (I can make a video/gif if needed). My FPS in console is showing 10,000 or higher, so I'm not sure what's going on. Any ideas?
@NoahtheEpicGuy
@NoahtheEpicGuy 6 жыл бұрын
This is not hating on you, but I just needed to say this: "It's not the most fun thing to do..." I disagree. Coding in general is really fun for me, so if you aren't having fun doing back-end stuff, you most likely don't like scripting as much as someone who finds anything to do with coding fun. But, I could be completely wrong, and again, I'm just stating an opinion and it's probably wrong.
@NoahtheEpicGuy
@NoahtheEpicGuy 3 жыл бұрын
I've written an Object Handler and GameObject code so many times, I don't think I'll ever forget it. But assembly is still something I need to get down with object-based games. Eh, not that hard though.
@yusufcline3756
@yusufcline3756 7 жыл бұрын
For The Ones Who Don't Want To Write It All Out: package com.tutorial.main; import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferStrategy; public class Game extends Canvas implements Runnable{ private static final long serialVersionUID = 1L; public static final int WIDTH = 640, HEIGHT = WIDTH / 12 * 9; private Thread thread; private boolean running = false; public Game(){ new Window(WIDTH, HEIGHT, "Let's Build A Game!", this); } public synchronized void start(){ thread = new Thread(this); thread.start(); } public synchronized void stop(){ try{ thread.join(); running = false; }catch(Exception e){ e.printStackTrace(); } } public void run(){ long lastTime = System.nanoTime(); double amountOfTicks = 60.0; double ns = 1000000000 / amountOfTicks; double delta = 0; long timer = System.currentTimeMillis(); int frames = 0; while(running){ long now = System.nanoTime(); delta += (now - lastTime) / ns; lastTime = now; while(delta >= 1){ tick(); delta--; } if(running) render(); frames++; if(System.currentTimeMillis() - timer > 1000){ timer =+ 1000; System.out.println("FPS: " + frames); frames = 0; } } stop(); } private void tick(){ } private void render(){ BufferStrategy bs = this.getBufferStrategy(); if(bs == null){ this.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.green); g.fillRect(0, 0, WIDTH, HEIGHT); g.dispose(); bs.show(); } public static void main(String args[]){ new Game(); } }
@bebojo21
@bebojo21 5 жыл бұрын
Thanks for this, just one problem is that 'timer =+ 1000;' needs to be 'timer += 1000;'
@djdols3301
@djdols3301 5 жыл бұрын
the constructor simply creates a window tho. it doesnt call the run method. so how did the game even run just like in the video?
@andrewkandasamy
@andrewkandasamy 4 жыл бұрын
@@djdols3301 Run is automatically called as part of thread.start. Start creates a new thread and applies the run() method to it.
@bitterlemonboy
@bitterlemonboy 4 жыл бұрын
Is this how you are going to learn programming? Just copying codes?
@patriik1373
@patriik1373 4 жыл бұрын
@@bitterlemonboy Nope :D but i have an error in Handler in public void render(Graphics g) { } There is an error void is an invalid type for the variable render help :D Oh fixed it now thanks patriik for fixing it :D
@Exilis
@Exilis 4 жыл бұрын
Why do random velX and velY with a fixed starting point always result in 22 objects that move in a perfect expanding square formation?
@ScibbieGames
@ScibbieGames 9 жыл бұрын
The box doesn't show up on my screen.
@benmessabihtoufik1975
@benmessabihtoufik1975 5 жыл бұрын
same problem here !
@CollidaCube
@CollidaCube 3 жыл бұрын
ngl these videos would be so much shorter if you didnt explain things as much as you do. People shouldn't be watching this anyway until they learn more about java.
@gamerdude3144
@gamerdude3144 9 жыл бұрын
Hey man, great tutorial, thank you! I'm having trouble on my mac getting the white boxes to appear. I can get the 1st and 2nd box to appear, but once I throw in the randoms, my window just shows up grey. Any thoughts?
@chestermlcek9044
@chestermlcek9044 9 жыл бұрын
Hey, when I opened the program, my boxes were moving, but at like the speed of light. I think it might be because of my gameloop, but I don't know where. can someone plz halp?
@tropical2153
@tropical2153 4 жыл бұрын
i got this problem 4 years later
@live4fun977
@live4fun977 4 жыл бұрын
@@tropical2153 check the values of your volX and volY variables. If they are high then the boxes will probably move fast.
@Hasan-Al-Khazraji
@Hasan-Al-Khazraji 4 жыл бұрын
I need help ASAP, the final part where he starts using velocity is not working for me. I have the squares they just are not moving. Please help
@Hobbestarcraft
@Hobbestarcraft 9 жыл бұрын
The amount of errors i get IS TOO DAMN HIGH! please help me!
@brodesseus3904
@brodesseus3904 5 жыл бұрын
I keep getting errors stating "color" and "white" in player.java cannot be resolved to a variable. Also for some reason everywhere with the word "render" is giving me an error too. I have basically copypasted all of the code from this and the first video into eclipse
@samrhermz3001
@samrhermz3001 4 жыл бұрын
does anyone have the source code for this video.. seeing the source code for each step-video would be very nice
@TeamExileFTW
@TeamExileFTW 9 жыл бұрын
im having problems with enum & setting colors, please help?
@hydra1346
@hydra1346 4 жыл бұрын
did you use the proper imports? if you are not using eclipse you will have to add the imports in yourself
@fabse404
@fabse404 Жыл бұрын
I know it's just a beginner tutorial and maybe you did this on purpose, but i think iterating over a Linkendlist would be more efficient with an for each loop or an iterator instead of the get method. Since the get method runs through the whole list everytime and a for each just gets the next element of the linked list. Maybe a Generator would be a good idea aswell (but maybe way to abstract for the target audience) just a small annotation tho, I really enjoy your work, thanks a lot :) I just started learning java, so you are very helpfull! EDIT: so the Function would look something like this: public void tick() { objects.forEach((temp) ->{ temp.tick(); }); }
@benmessabihtoufik1975
@benmessabihtoufik1975 5 жыл бұрын
i'm using intellij , the square is not showing ! need Help PLZ!!! the player is created like in the tuto, but idk why it's not showing on the window .
@MrMagicthunderx
@MrMagicthunderx 5 жыл бұрын
in Game class > method Render. did you place the code handler.render(g) above bs.dispose();. if not that's why . (I'm also using intelij)
@benmessabihtoufik1975
@benmessabihtoufik1975 5 жыл бұрын
@@MrMagicthunderx i did place handler.render(g) so , that's not the problem ,i'm still looking for an error , but everything seems right ... thanks for your help !
@benmessabihtoufik1975
@benmessabihtoufik1975 5 жыл бұрын
@@MrMagicthunderx oh , i just got the problem in class "Player", instead of writing g.fillrec() i wrote g.setClipe() , and that was a mistake that made me lose a lot of time (i have a lot of time to waste so ... XD) .... now i can press a like ! XD
@the_average_canadian
@the_average_canadian 8 жыл бұрын
Hey so I added everything up until velX = 1 in the player class at 18:09 and followed along pretty well, but when I run my program my objects don't float across the screen slowly, they fly out of the window at hyperspeed. Anything I can do to fix?
@the_average_canadian
@the_average_canadian 8 жыл бұрын
+Caleb Berger Nevermind, I figured it out. Basically i had used a bufferedImage instead of a fillrect so it was being very laggy until I did some optimization and now it's good :3
@MyAlfabetagamma
@MyAlfabetagamma 9 жыл бұрын
I don't know why, but if I render the object static it shows up, but as soon as I set it in motion it does not even show up on the window. For debug I decided to log the x position of the main object and these are the results: 193888 97072 97019 193857 290624 387411 97193 484217 193563 386904 290262 Ooooh, nevermind, I used pow (10, 6) / amountOfTicks rather than pow (10, 9) / amountOfTicks. It works perfectly now.
@austingallup8844
@austingallup8844 4 жыл бұрын
Has anyone else gotten this error? I can't seem to find out exactly where its coming from. Exception in thread "Thread-0" java.lang.NullPointerException at chess.Game.tick(Game.java:77) at chess.Game.run(Game.java:57) at java.base/java.lang.Thread.run(Thread.java:830)
@abdullafarid8334
@abdullafarid8334 5 жыл бұрын
HELP PLS. My compiler is giving me this error whenever I try to run my game : "Error: java: package object does not exist". It's indicating to the "GameObject tempObject = new object.get(i);" lines in both the tick and render methods in the Handler class, specifically to the get(i) part because when i hover over it with my mouse it says "Cannot resolve symbol 'get'". I dont know what to do D:
@spawn142001
@spawn142001 3 жыл бұрын
Another question. What's the difference between in game.java using r = new Random(); And in the player.java using the Random r = new Random(); Definitely do not understand this. Java tutorials always literally go from explaining... And this is how you make an integer. With int. And this is class dog. With method bark. Literally doesn't do shit. Way too simplified. To skipping entirely over all the Java syntax nuances like in this tutorial. Theres no ground tutorial that explains all the different code in different contexts for classes.
@maco9946
@maco9946 8 жыл бұрын
i keep getting random null pointer exceptions, by random i mean sometimes they will crash the game. and other times the game will run fine.. error occurs in class Game, inside method render() line "handler.render(g);" and in method run() on line "render();".. not sure how to solve it..
@Exilis
@Exilis 4 жыл бұрын
This is years old now but don't apologize for teaching the necessary backbone. It's not boring.
@aortizc82
@aortizc82 9 жыл бұрын
Tip: don't write your getters and setters by hand. Right click on the code area > Source > Generate getters and setters > choose which then hit ok.
@mrkeyl4443
@mrkeyl4443 10 жыл бұрын
Every time I put velX = 1; under public Player(int x, int y, ID id){ , the white square will fail to appear. When I remove it, everything is okay. Can somebody help me? I'm pretty new to all of this. Thanks.
@dingjerry9472
@dingjerry9472 2 жыл бұрын
When I type in: handler.addObject(new Player(100, 100, ID.Player)); the system shows Cannot instantiate the type player. How can I fix it😆
@spawn142001
@spawn142001 3 жыл бұрын
I really need someone to tell me why at 15:30 we type private Handler handler; //and he states "and now we create and instance of our handler" And then in public game new window method. He types. handler = new Handler(); Codes slightly different but as far as I can tell and this is where java is so f****** different an alien to those coming from python he created two instances of handler. Not one. I thought we just created a Handler and stored it under the name/variable handler. So wtf is handler = new Handler(); I really need to understand the difference between these two lines of code. Why is it nessescary to have both? Like in python from what I remember you don't type shit twice. To make an instance of it. Java literally has you do this for everything. The math behind the looping on the object list, and the FPS tick loop, getters setters methods classes I understand all of that. Can someone please explain or link a video as to why the hell Java appears to be so redundant. As in half the time we're typing things in twice in a slightly different way. Is the private Handler handler; loading the Handler.java into the game.java to run? And then we create the instance with handler = new Handler();? Does the second lower case handler in Handler handler, what were naming Handler.java to reference it when we say handler = new Handler ();
@mizzeti
@mizzeti 3 жыл бұрын
@RealTutsGML I cannot get mine to work. Using buffer strategy 3 does not clean up the canvas properly, changing it to 1 makes it better but it is still uggly and flickery. I checked the code and it is the same except for different colors. Any advice?
@olehendricks6160
@olehendricks6160 2 жыл бұрын
So, in high school we were told to name our parameters not x but pX to make clear that it is the parameter x and not x itself. Before i was like: More work nahhhhh but now i realy understand my teacher! Still very easy to follow! Good video! But i still dont know what a Canvas is...
@neblex3014
@neblex3014 3 жыл бұрын
for some reason the white box isn’t coming up for me even tho i typed handler.addObject(new Player(100, 100, ID.Player));
@jabaridestine2768
@jabaridestine2768 4 жыл бұрын
Nobody will probably not see this comment, but if you do, please tell me how I'm not making ANYTHING pop up on my window. It's literally just gray, no matter what i do.
@raffaelepapa834
@raffaelepapa834 10 жыл бұрын
I really like these new tutorials you're making, the way you're explaining stuff is quite clear and I've enjoyed every single minute of the video...please keep it up
@alexli6935
@alexli6935 7 жыл бұрын
I don't see the point in using an enum. I don't really know what they are, but for all the purposes that you use it for, it would be more readable and easier to just use the command instanceof. (format : say you have an object named animal, you could type: if(animal instanceof horse){ do stuff; }
@whynottohavefun375
@whynottohavefun375 7 жыл бұрын
screw jedies, I'm a get(i)
@JMZReview
@JMZReview 4 жыл бұрын
WTF? You didn't explain: BufferStrategy serialVersionUID synchronized threading. What the hell do those mean?
@AndyBandi2000
@AndyBandi2000 4 жыл бұрын
I am still following this, trying to learn Java... I understand java as much as i can create simple programs, but to reach this level of game creation, I understand what you are doing, but I need to learn it so I can do it myself, anywhere you can point me to the right direction to start learning from somewhere? how do i search this? (like in tutorials, what am i looking for?)
@Nieosl
@Nieosl 3 жыл бұрын
if i run the game after i have done handler.addObject(new Player(100, 100, ID.Player)); it won't show the rectangle
@angrybirdgaming9057
@angrybirdgaming9057 9 жыл бұрын
Exception in thread "Thread-2" java.lang.NullPointerException at com.game.main.Game.tick(Game.java:69) at com.game.main.Game.run(Game.java:52) at java.lang.Thread.run(Unknown Source) Help please!
@angrybirdgaming9057
@angrybirdgaming9057 9 жыл бұрын
- My bg doesnt show up
@angrybirdgaming9057
@angrybirdgaming9057 9 жыл бұрын
package com.game.main; import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferStrategy; public class Game extends Canvas implements Runnable { private static final long serialVersionUID = -473349850293143017L; public static final int WIDTH = 640, HEIGHT = WIDTH/12 * 9; private Thread thread; private boolean running = false; private Handler handler; public Game(){ new Window(WIDTH,HEIGHT,"A Game", this); handler = new Handler(); } public synchronized void start(){ running = true; thread = new Thread(this); thread.start(); } public synchronized void stop(){ try{ thread.join(); running = false; } catch(Exception e){ e.printStackTrace(); } } public void run(){ long lastTime = System.nanoTime(); double amountOfTicks = 60.0; double ns = 1000000000 / amountOfTicks; double delta = 0; long timer = System.currentTimeMillis(); int frames = 0; while(running){ long now = System.nanoTime(); delta += (now = lastTime) /ns; lastTime = now; while(delta >= 1){ tick(); delta--; } if(running) render(); frames++; if(System.currentTimeMillis() - timer > 1000){ timer += 1000; System.out.println("FPS: " + frames); frames = 0; } } stop(); } private void tick(){ handler.tick(); } private void render(){ BufferStrategy bs = this.getBufferStrategy(); if(bs == null){ this.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.black); g.fillRect(0, 0, WIDTH, HEIGHT); handler.render(g); g.dispose(); bs.show(); } public static void main(String args[]){ new Game(); } }
@japoniumbr
@japoniumbr 8 жыл бұрын
+Angry Bird Gaming try putting handler constructor before window constructor im game() method
@MrCudou
@MrCudou 7 жыл бұрын
Holy shit that worked... But he put it underneath in the TUT. Any idea why its causing problems for some people but not others?
@lordzephyron3631
@lordzephyron3631 7 жыл бұрын
Dude, I spent an hour trying to figure this out and should have just read the comments. Thank you so much
@TheValkyron
@TheValkyron 7 жыл бұрын
i don't get who you're targeting at. previously you assume we know what a bufferstrategy is, but here you console us about the complexity of the idea of class constructor? and btw the code in run() method is not really that bad. it just ticks 60 times per sec and renders as many times as the parent while loop runs. and it updates FPS at most once per second
@kaikubota6536
@kaikubota6536 9 жыл бұрын
can anyone help me. i keep getting errors that dont allow me to run the program but ive ran over the code and it looks exactly the same to me any help is greatly appreciated! heres for my Game.Jave class - pastebin.com/QPzgxArD FYI the farthest i got was getting the window to open, but the color and everything else from there on didnt work ;(
@energized5785
@energized5785 4 жыл бұрын
Not explained properly! Ended up making an amazing shooter game with 50 million waves and 800 higly customizable player types that went to number one immediatly.
Java Programming: Let's Build a Game #3
16:46
RealTutsGML
Рет қаралды 197 М.
I Spent 100 HOURS Making a Game With NO GAME ENGINE
13:42
Fuelvin
Рет қаралды 342 М.
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 10 МЛН
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 82 М.
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 186 М.
The Most Legendary Programmers Of All Time
11:49
Aaron Jack
Рет қаралды 567 М.
Making a Game with Java with No Experience
8:41
Goodgis
Рет қаралды 378 М.
Intro to Competitive Programming
11:41
Junferno
Рет қаралды 777 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 715 М.
Java Programming: Let's Build a Game #4
19:18
RealTutsGML
Рет қаралды 241 М.
Game Ideas Explained - 8 Ways to Generate Video Game Ideas [2021]
10:25
FizzBuzz: One Simple Interview Question
7:18
Tom Scott
Рет қаралды 3,5 МЛН