Snap To Grid Tool | Coding a 2D Game Engine in Java #25

Поділитися
Вставка
  • Опубліковано 30 лип 2024
  • Join the Discord: / discord
    In this episode, I explain how to create a snap to grid tool. This consists of drawing a grid that objects will be snapped to, and then snapping any object currently being held to the grid position. I explain how we can achieve this effect by using integer division to emulate the object "snapping" to a certain position. I also describe how to use our debug drawing facilities to draw a grid that is based on the cameras position in the world.
    Source Code: github.com/codingminecraft/Ma...
    ---------------------------------------------------------------------
    Website: ambrosiogabe.github.io/
    Github: github.com/ambrosiogabe
    Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)
    My Recommended Game Engine Books:
    Game Engine Architecture: www.gameenginebook.com/
    Game Physics Cookbook (Read this before the next physics book): www.amazon.com/Game-Physics-C...
    Game Physics (Ian Millington): www.amazon.com/Game-Physics-E...
    Game Programming Patterns (Free): gameprogrammingpatterns.com/
    My Recommended Beginning Game Programming Books:
    JavaScript Game Design: www.apress.com/gp/book/978143...
    My Recommended Java Books:
    Data Structures/Algorithms: www.amazon.com/Data-Structure...
    LWJGL (Free, but I haven't read this thoroughly): lwjglgamedev.gitbooks.io/3d-g...
    Outro Music: www.bensound.com/royalty-free...

КОМЕНТАРІ • 20

  • @Live4G4ming
    @Live4G4ming 3 роки тому +6

    Dude I've been following along with this series and god bless you man, this content is hands down been, the best videos I've seen on LWJGL keep going at it. This channel is gonna get big! I know it. I'm working on a top down rpg game and this game engine has made things much simpler, I'm new to java, I'm currently taking COP2800, so I'm pretty much a novice, but this has opened my eyes to how game development begins using java programming language, THANK YOU!

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +2

      No problem man! I'm glad that the series is helping you out with your game programming, and good luck with your course and game :)

  • @dinossauroproductions6271
    @dinossauroproductions6271 2 роки тому +3

    there seem to be a couple of glitches related to maximizing the screen to the monitor, it looks like the y axis is dislocated downward by like half a tile, not sure if that's because my screen is exactly the size of the window, so when it maximizes to the screen it has to reduce it to fit the windows bar on the top or something like that. i guess the correct way to fix that is to just make the game full screen so the window border doesn't mess it up

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

    This is so awesome!

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

    Hey Gabe! So i made it this far, and had a quick question: What do you suggest i do about the issue of game objects randomly being deleted? I believe you said you encountered it in your original devlog, and i dont know if you've fixed it yet.
    Is it just an issue with the serialization, or is it a different issue altogether with the game objects and how we keep track of them?
    Thank you again for the amazing tutorials, ill quickly be trying to catch up on the physics engine too. raycasting sounds so fun!

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

      just finished the video, so actually i just wanted to know if you've already figured it out and covered it?
      Sorry for the other nonsense i said.

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

      Hey The RandomGuy448, so I was just debugging for a bit, and the problem seems to be with the way we are saving/loading textures. I pushed the necessary changes to make this work, and I will also talk about the fix int the next GameEngine episode and why it was necessary :) . And raycasting is pretty fun, I hope you'll enjoy it once you get there :D

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

      @@GamesWithGabe thank you! i look forward to it!

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

    you should make it so imgui can be docked, for example if you drag it to the right it will fill the right of the screen etc, i think that would be a good addition

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

      Hey oellax! Support for docking was officially added to the Java library that I'm using in this, so I 100% agree with you. I plan on adding docking support either in the middle of the physics series, or after I finish the physics :)

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

      GamesWithGabe great

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

    I am working on a isometric renderer and I implemented these grid lines but how can I get them to rotate 45°?

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

      There are a lot of different ways you could do it. I think the easiest way would be to do something similar to what I did here, a double for-loop, and then draw angled lines instead. You would have to change the calculations for the start and endpoints, but the concept should remain the same :)
      Edit* I just realized that this was the snap-to-grid tutorial and not drawing the grid haha. I'm not sure what calculation you could use to snap a point to an isometric square, but this looks promising gamedev.stackexchange.com/questions/38320/is-it-possible-to-map-mouse-coordinates-to-isometric-tiles-with-this-coordinate :)

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

      @@GamesWithGabe Thanks! I’ll take a look at it!

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

    genius

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

    if any of you guys implemented panning and is wondering why when you pan the camera the position of the sprites when holding they are offset all you have to do is go into the getOrthoX/Y function and at this line of code when we are setting currentX/Y = tmp.x/y and add + Window.getScene().camera().position.x/y * 2 at the end.

  • @no1ofinterst
    @no1ofinterst 2 роки тому +1

    So, really weird bug. My hovering block snaps perfectly, except for in the first 8 columns. In these, it is offset to the left by one (so cursor in column 6, block in 7). I managed to solve this by adding a ```holdingObject.transform.position.x -= holdingObject.transform.position.x

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

      Same thing happening for me. No idea what could be causing it :p

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

      i have that issue too.. also the 8 first columns

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

      At the 8 column the negative numbers start; so if the mouse's x is at -10, the object's position will be at 0 according to the formula provided in the tutorial, that's why the object is shown on a different cell to the cursor's cell. A not very elegant way to solve this, could be to ask before the calculation:
      if (x < 0) { x -= 32;}