3. Setting Up Our Class Hierarchy | Making a 2D Game Engine with FNA

preview_player
Показать описание
Do you want the ability to create any 2D game your heart desires? In this series we'll create a 2D game engine from the ground up. The code we use is taken from the same engine I use for my games The Path of Motus and Pillar. At the end of this series you'll be able to create almost any 2D game, and thanks to the power of FNA and MonoGame it can run on almost any platform! The code we write can easily work on PlayStation 4, Xbox One, Nintendo Switch, iOS, Android, Mac, Linux and more. Feel free to expand upon this engine once the series is over; the sky is the limit!

Рекомендации по теме
Комментарии
Автор

I recommend making an ECS (entity-component system) where every GameObject has a list of GameComponents and can be updated and drawn separately. Hell, you can make the SpriteRenderer one of them.

CoolModderJaydonX
Автор

Whew! What a long video :D After going through the debugging, I had to back track because apparently I had another error that was causing my character to not show up. When setting up layerDepth I set it to 5f instead of .5f. woopsie :D great video. Thank you.

andrewmartin
Автор

Wow, I had no idea you could set breakpoints in VS while the application was running. Hovering over the variables to see their values is such a nice feature that I'm gonna use the heck out of. Thanks for including that debugging exercise and not editing it out. :)

calebcornett
Автор

Hey, Michael! After writing the code for keyboard readings on the player class, it doesn't work anymore for me. Do you have any idea why? The code is literally the same as yours and there's no error when I'm compilling the code, the character just doesn't react to the commands. Do you think it's something with the FNA latest releases?

eindrius
Автор

regarding @10:46
I would suggest altering how you handle required properties
if (Image != null)
{
Origin = new Vector2(Image.Width / 2, Image.Height / 2);
return;
}
throw new Exception();

to draw this object you will require the origin so there should never be a silent return on a requirement. At the very least set it to 0, 0. I know you see tons of videos where folks do this but it isn't a good idea and could save you some debugging time... always fail loudly.

If this logic should be moved to a full property is a religious debate but "gracefully handling exceptions" ie not handling exceptions is a crazy train of pain and suffering. That no one debates.

GarrethandPipa