3 - Canvas - New Beginner 2D Game Programming
Вставка
- Опубліковано 4 жов 2024
- We don't do much in this tutorial, but we discuss how graphics will be displayed to the screen!
Need source code? See my website: codenmore.gith...
Follow me on Twitter - @CodeNMore - / codenmore
Comment, PM, or Tweet me for help!
Teaching to understand all subjects to the fullest extent! - Навчання та стиль
Its good that you talk fast, you pack a lot of info in short videos.
I rather watch short tutorial videos like yours then +45min videos explain what you explained in 6mins.
Or does he .pack(); it
...
>:)
this reply made me want to eat cheese. I dunno.
xD
import UA-cam.CodeNMore.Videos.GameProgramming.3.Canvas
video.pack();
yeah it's very good you can learn how to start in game programming in like 1 hour
Amazing tutorial, so easy to understand not only the concepts but also your voice, for a non-native english speaker like myself. Hope you continue to share your knowledge with us in the future!
emisor Will do!
5:25 why did you make width and height variables but not a String variable for your title?
@@jaybartgis5148 they did it in tutorial 2
This is an awesome learning experience. I as a 14 year old trying to make a name for my self in the game making world found this really helpful so thank you. Keep up the good work.
how did it go friendo?
I just discovered this series, and am already loving it! I wanted to move on from Processing to something a little more hands on and technical. Just what I needed!
hey there you forgot to add (import java.awt.Dimension;)
hahha,yes!i found it out in his source code file on his website
You seem like a smart person, you talk really fast and super understandable. great explanations!
Fantastic tutorial, very detailed and easy to follow. I began watching a different tutorial before this one and found that the narrator was incredibly hard to keep up with and never described the functionality of any of the methods he was using , making it quite hard to learn anything. This tutorial, however, goes into great detail and explains everything. Thank you so much for creating this series, it's been extremely helpful in my endeavor of creating 2D Java games.
Hey CodeNMore I really like this series so far! even though the video is old its very helpful for me in college my course is BSI.T(Information Technology)
This tutorial series is going at a good pace. Keep up the good work!
These are actually so good, you're a natural
Don't worry I don't think your quick talking would be a problem it's actually one of the reason i watch your video:D
great videos, no issues with your speaking speed or the quality everything is perfectly readable
I know these videos are kinda old now, but I'm liking them a lot so far! I learned something new last episode :D Thanks for making these.
I think we have to import packages for dimension in 2019-12 eclipse version
THANK YOU a lot!
Very helpful
didnt get it
YOU ARE AMAZING. you are the only person who I ever learned from and I am now fluent.
I totally understand what you said. One of the best teacher on UA-cam!
This tutorial is awesome. Not just this video, ALL of them!
Thanks for this, especially if you have no idea wehere to begin using java after taking a few coursers!
Where you wrote canvas.setPreferredSize(new Dimension(width, height));
canvas.setMaximumSize(new Dimension(width, height));
canvas.setMinimumSize(new Dimension(width, height));
I got an error that wont allow me to proceed any further.
+Beristainbear i did too. found out i didnt import java.awt.Dimension, which im not sure if he mentioned that at all.
+Josh Cicconeokodo Yea I figured it out a minute after I posted this comment. Lol
I think he used the ctrl+shift+o shortcut, so we did not see it.
Yiyi Zhang He said he did it with this shortcut
I just started learning how to create games and i dot really have java experience, this tutorials are awesome man! great job!
im getting excited!
much better than any other tutorial thank you so much.
looking good so far
DUDE THANK YOU! IM MAKING IN ANDROID AND ITS SO AWESOME! BEST TUTORIAL!
That canvas analogy is nice!
Love it! Keep 'em coming! Really appreciate the guidance.
You have the best tutorials on youtube man keep it up!
you are a great teacher and i love these videos!
Thank you for teaching us!
Thank you for teaching us! It is a good tutorial.
Easy to follow, really good :) Thank you!
Best tutorial ever
dang right
I only have one question: why public width and height and not private in Game class?
So that other classes might be able to use width and height
This is a great series! Everything is working great so far, but we haven't gotten to the complex stuff yet. :P When do you think you will have the next video up?
Just got a new computer - so soon!
Neat!
I have an error on
"canvas = new Canvas();"
It says it's undefined for the type display
Did you say:
private Canvas canvas;
Because if you didn't then thats why.
Awesome !!! I'm so glad I can keep up with this series ..hope you make more of these awesome videos after you get your new computer.
oooh....thanks a lot....your vdos help a lot...i had no idea from where should i start...
Aha! I found my new teacher!!!
Me too
@@ericgadzi7801 me too
I have everything under canvas = new Canvas();, however, it's giving me an error message saying "Cannot find symbol - class Dimension". What's going on?
His voice is somewhat annoying (personally), but this guy has helped me so much... I really appreciate it, keep at it.
Keep it up man! hopefully see them a bit more often. I'm using public static final int for the width and height values in the display class, is this acceptable instead of having to keep putting the values in separate classes?
You very well could - you'll have to change just a couple of things throughout the series, but it'll work. The only downfall there is that your game won't be able to support multiple displays of multiple sizes, but that should be OK with most games!
Great Job man! Keep up the good work!
Awesome tutorial keep up the good work! :D
Let me say: "Fuck am I glad to see those kinds of videos!"
Like I've been struggling with finding proper documentation and it all resulted in me being totally confused but this...hey this is far better. I like the way you explain everything and what every function/method does etc.
Keep it up pal ;)
tank you so nuch!
I mean,i know im 2 yrs late,and u prob wont even see this comment but this is for those who are now just learning java on their own in this video its/better/faster/more quality to write code from "Game" class like this :
public class Game extends Display {
public Game(String naslov,int sirina,int visina){
super(naslov,sirina,visina);
And thats simply that,Game class gets all variables and methods from Display class and simply by writing this constructor i pasted,it should work aswell. :)
Well I just did you liar
get all ur tutorials out! i want to see more! more! more!
To add a color to a canvas, do this:
canvas.setBackground(new Color(255, 255, 255));
You can change that 255 to any value that is in the RGB scale (13, 29, 199 - for example. You must have: minimum = 1 and maximum = 255).
To find a correct RGB value, search on Google "rgb color picker" and a rgb picker will appear.
That is one of the canvas' functionality without a bg image.
prntscr.com/i1y1om
if u cant run your project try: setLocationRelativeTo(null); instead of setLocation(null);
Whats the difference between a Canvas and a JPanel?
Thank you for your sharing
in createDisplay(), why don't you create a single dimension instance and then use it for all the size-setters?
quick question, did you need to create the variable "width, height, title" in the game class for the program to work? because if you call new Game("title", 400, 400); the new display(title, width, height) inherits the value from public Game(String title, int width, int height);
Hi ! Loved the tutorial ! but The 'new Dimension is not working for me?';
question: why not use "extend" instead of create a class inside it
Hello CodeNMore,
What is the difference between canvas and paint and paintComponent and Jpanel?
Why most of the youtube tutorials use Jpanel and paint?
whats the difference, when we add "this.width & this.height" into Game constructor. Because the window will be created without it also...
I have some queries like
private JFrame frame;
private Canvas canvas;
what does this mean
and is the createdisplay(); a syntax
what does canvas = new canvas or frame = new Jframe means
I mean like I wanna know the structure of this so later I can know how these codes worked so I can correct errors instead of just checking someone else' project or stuff
Thanx a lot, you are a very good teacher :D
Why should you make a seperate Game class from your Launcher class?
Thanks this speed is actually perfect for me lol! =D
This is way too amazing!
Why do you use a canvas over a JPanel? You are using a Swing GUI so why add an AWT object?
So I'm trying to make a game that has a native resolution of 256x240. The window is way too small to use very well, so I'm trying resize the window to scale up the game and make it bigger. However, I have no idea how to actually do that. What happens when I set the size of the content pane of the jframe and the canvas is that the window resizes and becomes bigger, but the game is still drawn in the native resolution at the top left of the window. What do I need to do? And could you cover window size options in a future video?
just set it to false at setResizable(False);
I have to make my display public otherwise it won't compile. Will this cause errors for me later on?
+funkey man it shouldn't, but you probably wrote something incorrectly that is causing that error...I would check your code, but it probably won't affect anything.
amazing teacher
How did u import Canvas?
Why are the width and height in Game Class public?
I'm using this tutorial to make a game for a G+ community.
Love your Videos!
hey why do we need a game class if its the same as display ? it kinda seems like i missed an episode or smtg
I Have a problem Dimensional cannot be resolved to a type what should i do??
how come in the game class's constructor there is no private String title?
is their a video that has all of these episodes in one?
it says dimension isnt a type
you have to import it
y dont we need an object to call methods from static main?
I am getting an error on my String title, private Display display, and Game at 4:54
Hello, can I ask a question? Why is it that in the Game class, the "title" reference variable is made a local variable inside the Constructor, rather than declaring it outside the constructor like in the Display class? (namely, String title, and then this.title = title)
You very well could store title in the Game class, but I tend to avoid duplicating data. The Display class is storing the title as a member variable. Since the Game class has a reference to the Display, if we ever need the title we can simply do display.getTitle(). That way the current title is only ever set in one place.
I'm really confused, what is the point of "private Display display;"? it just doesn't make any sense
sir can u help me plz because the compiler is showing error in the Dimension
Why isn't the game not running properly when started from a Runnable JAR file ?
Can anyone help me about this ?
Is using JPanlel better than using Canvas?
thanks your videos so much!!!!
P/s: from VietNam
What library should i use?!
What did you click to get the import window at 1:03?
So what would I do instead if I _did_ want the window to be resizable? Do I create a method in the Game class that updates everything and make sure to call it every time the window is resized?
just set resizable to true
I had a weird problem where the Launcher wouldn't recognize the Game class so i copied everything in it, deleted my launcher and recreated it, pasting everything into it. i hope that helps someone.
error code:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The constructor Game(String, int, int) is undefined at dev.codenmore.tilegame.Launcher.main(Launcher.java:6)
Good teacher but i was never good at OOP i just cant wrap my head around why in Game.java i create a public Game which has title, width, height then a new display which also has a title, width, height why define it twice i mean it all works up to this point but why is it working??! Maybe i am more of an artist and i am a UI designer not a Programmer but i will not give up to learn java!!
4:51 de aynısını yaptım.display yerleri hata veriyor.
what does new Display(.....) do in main?
can i have java draw imgs on this Canvas? thanks Josh
hey coden I'm getting a Syntax error on token does anyone know what this means?
getting error in Dimension part pls help.using bluej
I can't create a new Dimension, it says Dimension cannot be resolved to a type
You need to add import java.awt.Dimension to your code under import java.awt.Canvas
why wasn't "this.title = title;" needed in game constructor?
Because the game class doesn't need to know about the title of the frame.
I set the width and height there just so we could access it without going through the Display class. If we ever need the title in our game we'll have to access it from the Display class, but the width and height we can just access from our Game class because we will need to use those a LOT!
the game class says theirs an error
i made mine automatically get the size of your screen and divide it by two using this code:
package dev.game.tilegame.display;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class Display {
private JFrame frame;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
private String title;
int screenHeight = screenSize.height / 2;
int screenWidth = screenSize.width / 2;
public Display(String title) {
this.title = title;
createDisplay();
}
private void createDisplay() {
frame = new JFrame(title);
frame.setSize(screenWidth, screenHeight);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
I cant find the Canvas import
I'm using netbeans and when I add frame.add(canvas); I get an error that reads:
Javadoc not found. Either Javadoc documentation for this item does not exist or you have not added specified Javadoc in the Java Platform Manager or the Library Manager.
Any advice? thanks in advance!
advice: dont use netbeans
im getting an error of setpreferredsize that dimension type component is not applicable for this argument....what does this mean ???
thanx in advanced ....
code?
I had to import the java.awt.Dimension for it to work
i try to run mine all it says is selection does not contain a main type
+Jay Pop plese i need help anyone?
the dimension class cannot find symbol
it would be insanely usefull if you gave us the error message and the corresponding lines or method.