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!
  • Навчання та стиль

КОМЕНТАРІ • 179

  • @LMleet06
    @LMleet06 8 років тому +137

    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.

    • @fredgreen7287
      @fredgreen7287 7 років тому +17

      Or does he .pack(); it
      ...
      >:)

    • @cheesymcnugget3740
      @cheesymcnugget3740 7 років тому +1

      this reply made me want to eat cheese. I dunno.

    • @jay-hb7el
      @jay-hb7el 6 років тому

      xD

    • @jay-hb7el
      @jay-hb7el 6 років тому +5

      import UA-cam.CodeNMore.Videos.GameProgramming.3.Canvas
      video.pack();

    • @roland144
      @roland144 6 років тому

      yeah it's very good you can learn how to start in game programming in like 1 hour

  • @emisor9272
    @emisor9272 9 років тому +50

    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!

    • @CodeNMore
      @CodeNMore  9 років тому +14

      emisor Will do!

    • @jaybartgis5148
      @jaybartgis5148 7 років тому

      5:25 why did you make width and height variables but not a String variable for your title?

    • @squelgames3780
      @squelgames3780 3 роки тому

      @@jaybartgis5148 they did it in tutorial 2

  • @jacobwalker7046
    @jacobwalker7046 7 років тому +10

    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.

  • @HeraldOD
    @HeraldOD 6 років тому +3

    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!

  • @suvantmsuvantheminecraftia7407
    @suvantmsuvantheminecraftia7407 6 років тому +7

    hey there you forgot to add (import java.awt.Dimension;)

    • @hamnabutt3000
      @hamnabutt3000 3 роки тому

      hahha,yes!i found it out in his source code file on his website

  • @bewaryoftherabbithole8011
    @bewaryoftherabbithole8011 3 роки тому

    You seem like a smart person, you talk really fast and super understandable. great explanations!

  • @x32asm81
    @x32asm81 9 років тому +2

    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.

  • @Jirou08-hehe
    @Jirou08-hehe 4 роки тому +2

    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)

  • @mikeorz5644
    @mikeorz5644 9 років тому +2

    This tutorial series is going at a good pace. Keep up the good work!

  • @ScienceAlliance
    @ScienceAlliance 4 роки тому +2

    These are actually so good, you're a natural

  • @OlsZn
    @OlsZn 8 років тому

    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

  • @nerionx
    @nerionx 6 років тому

    great videos, no issues with your speaking speed or the quality everything is perfectly readable

  • @printlnPrints
    @printlnPrints 7 років тому

    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.

  • @zumriahmed1739
    @zumriahmed1739 4 роки тому +10

    I think we have to import packages for dimension in 2019-12 eclipse version

  • @charleswiseman5727
    @charleswiseman5727 7 років тому

    YOU ARE AMAZING. you are the only person who I ever learned from and I am now fluent.

  • @vietvuduc1899
    @vietvuduc1899 6 років тому

    I totally understand what you said. One of the best teacher on UA-cam!

  • @j7438
    @j7438 6 років тому

    This tutorial is awesome. Not just this video, ALL of them!

  • @michaelcrowell4444
    @michaelcrowell4444 8 років тому +1

    Thanks for this, especially if you have no idea wehere to begin using java after taking a few coursers!

  • @beristainbear3924
    @beristainbear3924 8 років тому +18

    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.

    • @joshokodo
      @joshokodo 8 років тому +10

      +Beristainbear i did too. found out i didnt import java.awt.Dimension, which im not sure if he mentioned that at all.

    • @beristainbear3924
      @beristainbear3924 8 років тому

      +Josh Cicconeokodo Yea I figured it out a minute after I posted this comment. Lol

    • @nappingyiyi
      @nappingyiyi 5 років тому +3

      I think he used the ctrl+shift+o shortcut, so we did not see it.

    • @zok_6619
      @zok_6619 4 роки тому

      Yiyi Zhang He said he did it with this shortcut

  • @olegaizin9732
    @olegaizin9732 8 років тому

    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!

  • @maxwell9561
    @maxwell9561 6 років тому

    much better than any other tutorial thank you so much.

  • @TheCsel
    @TheCsel 9 років тому +1

    looking good so far

  • @jemak365
    @jemak365 7 років тому +3

    DUDE THANK YOU! IM MAKING IN ANDROID AND ITS SO AWESOME! BEST TUTORIAL!

  • @asterixgallier8102
    @asterixgallier8102 5 років тому

    That canvas analogy is nice!

  • @truthByFire
    @truthByFire 9 років тому +1

    Love it! Keep 'em coming! Really appreciate the guidance.

  • @jakegerard1870
    @jakegerard1870 4 роки тому

    You have the best tutorials on youtube man keep it up!

  • @siddharthahajra5800
    @siddharthahajra5800 7 років тому +1

    you are a great teacher and i love these videos!
    Thank you for teaching us!

  • @yuqihu2538
    @yuqihu2538 7 років тому +1

    Thank you for teaching us! It is a good tutorial.

  • @paulinekelly9932
    @paulinekelly9932 9 років тому +1

    Easy to follow, really good :) Thank you!

  • @jillerkore
    @jillerkore 4 роки тому +1

    Best tutorial ever

  • @WiredDrummer
    @WiredDrummer 8 років тому +8

    I only have one question: why public width and height and not private in Game class?

    • @JMZReview
      @JMZReview 4 роки тому +1

      So that other classes might be able to use width and height

  • @ferritlord1964
    @ferritlord1964 9 років тому +1

    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?

  • @GamingWithGoku
    @GamingWithGoku 4 роки тому +4

    I have an error on
    "canvas = new Canvas();"
    It says it's undefined for the type display

    • @JMZReview
      @JMZReview 4 роки тому +3

      Did you say:
      private Canvas canvas;
      Because if you didn't then thats why.

  • @prithug
    @prithug 9 років тому +1

    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.

  • @HabiburRahman-xs9gb
    @HabiburRahman-xs9gb 8 років тому

    oooh....thanks a lot....your vdos help a lot...i had no idea from where should i start...

  • @RamenFriend
    @RamenFriend 9 років тому +7

    Aha! I found my new teacher!!!

  • @spartanretro
    @spartanretro 7 років тому +1

    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?

  • @mmesoemmanuel6542
    @mmesoemmanuel6542 5 років тому

    His voice is somewhat annoying (personally), but this guy has helped me so much... I really appreciate it, keep at it.

  • @jimie93
    @jimie93 9 років тому +1

    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?

    • @CodeNMore
      @CodeNMore  9 років тому +1

      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!

  • @DragonMinerToons
    @DragonMinerToons 9 років тому +2

    Great Job man! Keep up the good work!

  • @lillagubbn
    @lillagubbn 9 років тому +1

    Awesome tutorial keep up the good work! :D

  • @aljosaskorjanc1475
    @aljosaskorjanc1475 7 років тому

    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 ;)

  • @zuzu_musa4325
    @zuzu_musa4325 3 роки тому +1

    tank you so nuch!

  • @jukzjee5822
    @jukzjee5822 5 років тому +1

    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. :)

  • @MightyTango
    @MightyTango 9 років тому +1

    get all ur tutorials out! i want to see more! more! more!

  • @Cesqr
    @Cesqr 6 років тому

    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

  • @privataccount6332
    @privataccount6332 4 роки тому

    if u cant run your project try: setLocationRelativeTo(null); instead of setLocation(null);

  • @harissohail55
    @harissohail55 8 років тому +1

    Whats the difference between a Canvas and a JPanel?

  • @gsh9947
    @gsh9947 7 років тому

    Thank you for your sharing

  • @TheDarkOne629
    @TheDarkOne629 8 років тому

    in createDisplay(), why don't you create a single dimension instance and then use it for all the size-setters?

  • @jerah8059
    @jerah8059 5 років тому

    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);

  • @thewideinstitute7872
    @thewideinstitute7872 2 роки тому

    Hi ! Loved the tutorial ! but The 'new Dimension is not working for me?';

  • @zarasuto7216
    @zarasuto7216 6 років тому

    question: why not use "extend" instead of create a class inside it

  • @pukka4140
    @pukka4140 8 років тому

    Hello CodeNMore,
    What is the difference between canvas and paint and paintComponent and Jpanel?
    Why most of the youtube tutorials use Jpanel and paint?

  • @rohitmajnekar
    @rohitmajnekar 5 років тому

    whats the difference, when we add "this.width & this.height" into Game constructor. Because the window will be created without it also...

  • @soubarnabiswas4478
    @soubarnabiswas4478 3 роки тому

    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

  • @vortyx090
    @vortyx090 8 років тому

    Thanx a lot, you are a very good teacher :D

  • @jacobbarats1493
    @jacobbarats1493 8 років тому

    Why should you make a seperate Game class from your Launcher class?

  • @LordMoopCow
    @LordMoopCow 6 років тому

    Thanks this speed is actually perfect for me lol! =D

  • @HikikomoriDev
    @HikikomoriDev 9 років тому

    This is way too amazing!

  • @MrMaarten333
    @MrMaarten333 9 років тому

    Why do you use a canvas over a JPanel? You are using a Swing GUI so why add an AWT object?

  • @ThatEntityGirl
    @ThatEntityGirl 8 років тому +1

    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?

    • @beastgamer46
      @beastgamer46 8 років тому

      just set it to false at setResizable(False);

  • @funkeyman100
    @funkeyman100 8 років тому +1

    I have to make my display public otherwise it won't compile. Will this cause errors for me later on?

    • @CodeNMore
      @CodeNMore  8 років тому

      +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.

  • @KennethDiazperlloni
    @KennethDiazperlloni 7 років тому

    amazing teacher

  • @Lukas-dk1nx
    @Lukas-dk1nx 3 роки тому +1

    How did u import Canvas?

  • @nappingyiyi
    @nappingyiyi 5 років тому

    Why are the width and height in Game Class public?

  • @redball7164
    @redball7164 7 років тому

    I'm using this tutorial to make a game for a G+ community.

  • @cfqcmc
    @cfqcmc 9 років тому

    Love your Videos!

  • @skyz3ra
    @skyz3ra 7 років тому

    hey why do we need a game class if its the same as display ? it kinda seems like i missed an episode or smtg

  • @antoniss1997
    @antoniss1997 7 років тому

    I Have a problem Dimensional cannot be resolved to a type what should i do??

  • @sentimentaleel3578
    @sentimentaleel3578 5 років тому

    how come in the game class's constructor there is no private String title?

  • @alexandercarvunaris846
    @alexandercarvunaris846 8 років тому

    is their a video that has all of these episodes in one?

  • @Akathysia
    @Akathysia 7 років тому +3

    it says dimension isnt a type

  • @skillfr3ak652
    @skillfr3ak652 7 років тому

    y dont we need an object to call methods from static main?

  • @IanOnGames
    @IanOnGames 4 роки тому

    I am getting an error on my String title, private Display display, and Game at 4:54

  • @lumiere2598
    @lumiere2598 4 роки тому

    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)

    • @CodeNMore
      @CodeNMore  4 роки тому

      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.

  • @johnnyissuper6955
    @johnnyissuper6955 4 роки тому

    I'm really confused, what is the point of "private Display display;"? it just doesn't make any sense

  • @reekbanerjee2489
    @reekbanerjee2489 6 років тому

    sir can u help me plz because the compiler is showing error in the Dimension

  • @vianpyro
    @vianpyro 5 років тому

    Why isn't the game not running properly when started from a Runnable JAR file ?
    Can anyone help me about this ?

  • @tanvirahmedshanto3093
    @tanvirahmedshanto3093 5 років тому

    Is using JPanlel better than using Canvas?

  • @TaiTran-hu1py
    @TaiTran-hu1py 8 років тому

    thanks your videos so much!!!!
    P/s: from VietNam

  • @adampleyz4688
    @adampleyz4688 3 роки тому

    What library should i use?!

  • @jezybear9159
    @jezybear9159 7 років тому

    What did you click to get the import window at 1:03?

  • @PianoMastR64
    @PianoMastR64 7 років тому

    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?

  • @hoople212
    @hoople212 5 років тому

    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)

  • @Maltebyte2
    @Maltebyte2 8 років тому

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

  • @cayman_islands
    @cayman_islands 3 роки тому

    4:51 de aynısını yaptım.display yerleri hata veriyor.

  • @skillfr3ak652
    @skillfr3ak652 7 років тому

    what does new Display(.....) do in main?

  • @joshclugston
    @joshclugston 8 років тому

    can i have java draw imgs on this Canvas? thanks Josh

  • @HemloxGaming
    @HemloxGaming 8 років тому

    hey coden I'm getting a Syntax error on token does anyone know what this means?

  • @mousahadas8585
    @mousahadas8585 6 років тому

    getting error in Dimension part pls help.using bluej

  • @Max-ur6xk
    @Max-ur6xk 3 роки тому

    I can't create a new Dimension, it says Dimension cannot be resolved to a type

    • @andrewgilbey186
      @andrewgilbey186 3 роки тому +3

      You need to add import java.awt.Dimension to your code under import java.awt.Canvas

  • @Ilikadafire
    @Ilikadafire 9 років тому

    why wasn't "this.title = title;" needed in game constructor?

    • @OzDemos
      @OzDemos 9 років тому

      Because the game class doesn't need to know about the title of the frame.

    • @CodeNMore
      @CodeNMore  9 років тому

      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!

  • @pizzamation5380
    @pizzamation5380 7 років тому

    the game class says theirs an error

  • @ethanviolet1
    @ethanviolet1 6 років тому

    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);
    }
    }

  • @yikealotekeste1242
    @yikealotekeste1242 7 років тому

    I cant find the Canvas import

  • @jeremybaird2447
    @jeremybaird2447 7 років тому

    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!

  • @gourabgameplay3299
    @gourabgameplay3299 8 років тому

    im getting an error of setpreferredsize that dimension type component is not applicable for this argument....what does this mean ???
    thanx in advanced ....

  • @lennymcjaypop7551
    @lennymcjaypop7551 9 років тому

    i try to run mine all it says is selection does not contain a main type

  • @zoilo87
    @zoilo87 8 років тому

    the dimension class cannot find symbol

    • @TheDarkOne629
      @TheDarkOne629 8 років тому

      it would be insanely usefull if you gave us the error message and the corresponding lines or method.