What Should Be in a 2D Game Engine? [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Ok, so I ended up writing my own game engine based on top of XNA, and I am just wondering what else I need to make a complete engine.
This is what's in the engine:
Physics (Farseer Physics)
Particle Engine (Mercury Project)
2D Cameras
Input Handling
Screen Management (Menus, Pause Screen, etc.)
Sprite ( Animation, Sprite Sheets)
And XNA stuff like Sound.
Am I missing anything that might be crucial to a game engine?

You're approaching it in an upside-down manner.
What should be in your engine is the following:
All the code that turned out to be common between your first and your second game.
First, write a game. Don't write an engine, because, as you have found out, you don't know what it should contain, or how it should be designed. Write a game instead.
Once you have that game, write another game. Then, when you have done that, examine the second game's code. How much of it was reused from the first game?
Anything that was reused should then be refactored out into a separate project. That project is now your game engine.
This doesn't mean that you shouldn't plan, or shouldn't try to write nice code. But make sure you're working towards something concrete, something where you can tell a good implementation from a bad one. A good implementation of a game, is one that works, is fun, and doesn't crash. Write your code to achieve those things first.
A good implementation of an engine? That's trickier. What's a good implementation of a renderer? Of an AI framework? Of a particle system? Ultimately, the only way to determine whether you have a good engine is by seeing how well it works in an actual game. So if you don't have a game, you have no way to evaluate your engine. And if you have no way to evaluate your engine, you have no way of judging whether any of the code you're writing is actually useful.

A theme or market for your engine. If you're doing anything beyond basic your basic graphics engine, you'll want to concentrate on a market for your engine, like RPG, strategy, puzzle, platformer, action, or FPS (ok, not FPS).
This will help you point yourself in the direction you need to go in order to make further enhancements to the engine without asking us. An engine like say, the Unreal Engine, can do multiple things, but what it tends to do best is what it's made for, FPS games. Likewise, you should tailor your engine so that it suits a particular field of interest, and therefore is picked up for that type of gameplay.
You can make it general to a point, but realize the more generalized your engine is, the harder it is to program, both time wise and skill wise. Other programmers are also less likely to pick up a general engine (unless that's all there is) if a more specific platform is available. Or to just write their own since modifying a generalized engine is about as hard as creating your own.

A few more things:
Path finding - very useful for AI
AI - possibly - depends on how generic you want the engine to be.
High scores
Replays - makes high scores much more interesting, as you can actually watch them.

A couple ideas:
Artificial intelligence (perhaps just simple AI utilities, like pathfinding algorithms)
Saving all or part of the game state (for suspending and restarting at a later time or saving high scores).

I think that you covered the general requirements of a 2D engine. The only thing I would miss in that list would be:
GUI Library
Also to make development processes easier:
Script Engine (LUA, C#Script, ...)
Dynamically Refreshed Assets (see Nick Gravelyn's Blog Entry)
You might also add another layer on top of XNA's existing stuff:
A quite bareboned Network/Lobby implementation
More abstract handling of multiple controllers (DropIn/DropOut during gaming sessions, like see Resident Evil 5 Coop) - maybe event-based
Finally you might add some "ready2use" shaders. Maybe get some inspiration from the discontinued FaceWound (from the "Garry's Mod" developer).

It depends on the game, but another thing often needed is a good networking framework.
Many modern games, including 2D games, seem to have some form of networking in place.

Animation framework so that you can say: take this sprite, move it in this direction, folowing this path using this speed, acceleration and such
Basic GUI system. Don't implement a whole Windows, but basic things like a pointer and a button, and such - keep it basic
Debugging component for displaying FPS, numbers of sprites and such
Also a good thing is to make some games, and then you will quicky see what things you repeat doing for each game, and then look into how to can get that into the engine.

2d lighting system is a good advanced feature. You can use Krypton for that.
Map editor. Or even better support any tile-map format, compatible with "Tiled Map Editor". So you can just use Tiled.
Scheduler/Timer for game actions.
Screen wipe effects such as page turn, fade out, etc. to make nice transitions between screens.
Game layers with build in parallax would be usefull too.
In game console to process commands or scripts without restart.
Easy load for texture atlas as sprites or animation.

Nice Work,
We (me and some of my friends) are working on a game engine too actually,
We've already got all what you mentioned but moreover we've got the following.
audio manager : a simple class to handle background music and sounds
effects in XNA.
video manager : it's not complicated, a simple class to handle video
playing in XNA.
effects manager : is responsible for stuff like bloom, blur,
black/white colors .. etc.
Good Luck :)

3d Acceleration should be in a 2D engine.
Using the 3d hardware that most people have these days is the best way to get amazing performance for your 2D games...

Good collision detection is very helpful. If you implement it efficiently, it really reduces the time required for every frame. Besides that, in my engine (for Pygame) I have a method of separating the main screen into a number of subscreens, which I find useful.

Depending on the target game type, include Navigation Graph(s) with node and edge annotations. (Good for many games, but not so much for the token side scrollers that are made with 2D graphics engines)
A component to generate them (via a flood fill algorithm).
Be sure to include all of the major path finding/planning algorithms (A*/Dijkstra/etc.) to traverse those graphs.
The pitfall of this is that you will have to define what a 'map' is for the engine, which might limit users of the engine.
Related things:
Location based triggers (player enters an invisible circle and something happens - queue cutscene, start ambush, etc.). I would say provide a base class for the trigger and implement some basic ones to show how it's done (ie. weapon pickups etc.)
Some game engines implement networking (though this is kind of part of the 'xna stuff')

The most useful thing to include above all else would be tools to easily use your engine. Maybe use your engine to create the tools. I'm sure you would find a lot of flaws that way.

Simple pixelperfect collision detection. NOT Farseer Physics. Simple drawing routines like drawline, drawcircle etc.

A tile repeat tool. Something that allows the user to add/create a tile, and manipulate the edges for a smooth repeath pattern.

Um. This list is an "internals" list. To make great engine is to make great "external" list.
Look at UE3 for example -- it is here because of great tools. You need tools for world creation, to create optimal packages of resources (it should be in internal list too ;-)), for collision object specification etc.
Plus, to add to Organiccat answer you should decide on tech level. You can go for simple sprites or you can want fancy effects (so shaders are needed, and with this you need infrastructure)

Related

How to create a hole on a ground in Unity?

I am trying to make a game like Color Hole. I've created a ground and a 3d cylinder. I want this cylinder act like a hole instead of a solid cylinder. Is there any opinion how can I do this without using Blender or etc?
For modeling and mesh prototyping within unity there are very cool assets, such as this, or this.
The most affordable of the solutions of course is to import the model you want as wanted from your modeling program.
It would expected to be possible with pro-builder (modeling tool integrated in unity). However its not.
Window->PackageManager->Probuilder
Then you need to enable the experimental features:
Edit->Preferences->ProBuilder
Then there is a tool that its supposed to make union, instersection and substraction of meshes:
However it does not work and at least for what I tried, I obtain this error always:
StackOverflowException: The requested operation caused a stack overflow.
UnityEngine.ProBuilder.Csg.Plane.SplitPolygon
(Unity version 2018.4.12). Maybe it can be checked if there is an issue with the unity version and if the pro-builder approach migh work in others.
If you attach a script to the "hole" object, you could detect other objects entering in OnColliderEnter(). Then, using the OnColliderStay() method, you could move them downwards "through" the hole, then destroy them (or whatever you want to happen when they pass through the hole).
It's kind of a hacky solution, but it would work if you're unable make a custom asset. It's not going to give you physics engine interaction though, so making the object tumble realistically through the hole will be more effort than it's worth.

Unity Project Architecture?

I am developing a 2D Platformer RPG Game. The game will have many characters in it, each having different abilities (or powers). My question is that how can I maintain my project structure so that I can add as many charcters or abilities I want to add in the future without making a complete mess of my code.
For example:
I have a charcter lets say Iron-Man so I want him to use thrusters but let say there is another player using Captain America as his character who cant use thrusters.
Now how to make a system so that I can add characters and abilities or have characters exchange any ability with another at runtime?
I've heard about using interfaces to make code cleaner and also about using scriptable objects but I haven't quite worked with them.
I would like to know a concrete method of making this type of system (If there is any).
Any links to tutorials would be appreciated.
PS- My game has just 1 character in it and everyday I open my project hoping that I will add a new character but I am always afraid that I will break my code and I think that if I surf a little more on the internet I will get a proper sturcture to start with so I dont take any risk and I just end up changing some things here and there and close it.
A few things to check out (Mainly related to OOP):
SOLID design and Design Patterns Videos
https://unity3d.college/2017/11/24/solid-unity3d-code-architecture-open-closed-principal/
https://www.youtube.com/watch?v=FGVkio4bnPQ
https://www.youtube.com/watch?v=UoNumkMTx-U
Lots more in his channel, those were just a few
Design Patterns Code to study
https://github.com/Naphier/unity-design-patterns
https://github.com/QianMo/Unity-Design-Pattern
Lastly:
Unity's Free (For next month or so) learning: https://learn.unity.com/

Are there best practices for "Singletons" (persistent GameObjects) in Unity?

I'm rather new to Unity, and C# too as a matter of fact!
What I am doing right now is:
I have a "Singleton" (it's not really a Singleton but that's not the point) GameObject called GameManager, to which is attached my GameManager.cs script containing most of the game info (which tutorial text has been already displayed, functions to load localized text, last scene loaded...)
As children of this GameManager object, I have different kinds of GameObjects I do not want to destroy on load either, such as PostProcessing Profiles, Global Lights, Audio Manager, UI Canvasses (canvi?) and other things...
There are plenty of great tutorials on Unity, and it's an awesome community, but I could not really find any info on Unity's "best practice" regarding GameObjects management.
Is this a correct way to proceed? Will I have issues in the future with this method? Should I make a generic class that implements Unity's DontDestroyOnLoad() and have the Object I want to keep inherit from that class? Is there a better way?
It works fine for now, but I want to be sure I am not doing this the wrong way and potentially messing up with my game's performance or stability.
Many thanks in advance.
There are two best-practices here.
Build lots of singletons, and replace Unity's built-in initialization system
Build very few singletons, and work within Unity's initialization system, and make heavy use of the new Multi-Scene Editing system.
Option 1 is very popular with game-studios and professional gamedevs, who are skilled at doign this and have done it many times before. The main problem is that once you start down this route you are comitting to maintaining your own parallel init system. The main advantage is that your system is probably better, definitely more powerful, and usually faster (!) than Unity's internal one.
Option 2 is more popular with people new to game programming, who want to lean on as much of Unity's built-in features as possible.
That said, there are some strange things in your question.
For instance ... Canvas? Why on earth would you be trying to make Canvas into a singleton? This suggests you're misusing Canvas in a big way (and probably some of the other classes).
The standard approach (and the only one that Unity supports) is for every Scene to have its own unique Canvas. To do something different ... is very odd.
I suspect you've misunderstood what "DontDestoryOnLoad" does. It does not prevent things being destroyed on load!
Instead, it prevents being destroyed when a NEW scene is being loaded, and they only lived in the OLD scene. A much better name would have been: "DontDestroyWhenLoadingANewScene"
There are a lot of bugs (going back many years) in Unity with DontDestroyOnLoad, so in general its best to avoid it as much as possible. For simple cases it works fine, but if you use it too much you run into complex edge cases and interactions with Unity's own internal classes.
Obligatory utopic programmer answer: Try to avoid using singletons as much as possible.
That being said, feel free to use my singleton implementation, been using it for years in production and it works fine.
https://gist.github.com/ronrejwan/7a4f0037effec3c9e8943542cf9cfbc9

Cutting mesh in realtime

I want to slice a mesh object into at least five parts. I've done some research and some people on here have cloned objects when sliced and just instantiate two objects from a single slice?
I'm pretty new to Unity and C#. So any beginner tutorials on where to start or where I can read for learning how to cut mesh would be nice. Like what functions/methods should I be looking into? What methodology is behind cutting mesh?
From my understanding, I haven't seen any tutorial or asset that actually cuts triangular mesh? If there is, how is it done? What is the logic behind it? I guess I need help understanding the logic behind it and how to get started or what I should look into?
Cut mesh in realtime I mean.
EDIT:
Attempt at understanding and playing around with code:
I used the fake slicer 3.0 (http://unitycoder.com/blog/2011/08/09/fake-mesh-slicer-v3-0/) and included in the sample, they have a capsule that the slicer works on.
If I added a cube or another capsule with rigidbodies properties and collider property, the slicer (aka plane) only clones the object and doesn't slice it off. Why is that? How can I manipulate the code above to work for all kinds of objects?
I get this console error and I don't know what it means:
UnasssignedReferenceException: The variable cutplane of 'Slice_mesh3_js' has not been assigned. You probably need to assign the cutplane variable of the Slice_mesh3_js script in the inspector.
Have you tried the turbo slicer asset?
https://www.assetstore.unity3d.com/#/content/4169
There is a demo in their website.
There are ways to achieve what you want, however the noted asset could be the easiest one.
Worth looking assets for slicing, breaking apart:
Fracturing & Destruction https://www.assetstore.unity3d.com/#/content/9411
Shatter Toolkit https://www.assetstore.unity3d.com/#/content/1017
Also you can:
Use your preferred modeling program and model the object in parts
and with an animation slice the object as a result of certain
action.
Programmatically disappear the complete object and appear
the slices using maybe a particle system to improve the effect.
You can see new one here http://u3d.as/qSN
This asset has very fast algorithms for 3D models and in comparison to its alternatives, it have much more clean code.
It supports asynchronous slice if you are not happy with speed. But my tests shows that it is not necessary, it is fast enough to do it in main loop.
It slices colliders converting them to MeshCollider-s.
And it is easy to customize.

easiest way to make a live 3d scene, a bit like a simple game (for simulator visualisation purposes)

I am building a ship simulator that will produce accurate position and orientation values for a prototype hull design in some defined sea-state.
In terms of programming, I have 2 arrays (vectors) in MATLAB containing the position and acceleration values for x, y, z, yaw, pitch and roll. Because the visualisations in MATLAB are a bit crude, I am planning to write a simple server within MATLAB to send these values (at 200Hz) using sockets to another program. The sea is modelled as an array of vertices (think of amplitude snapshots at different timesteps on a sine wave).
So my question is, what's the easiest way to animate a 3D boat and some textured water on screen?
I am only interested in the graphics engine. I have no need for sound, physics, collisions, interface (keyboard, joystick, etc). It should be able to run primarily on Windows, but it would be nice if it could run on Linux and Mac OS too (depending on the additional complexity involved).
Not an expert, but few leads are
vtk, portable and integrates, regarding complexity look at sample code
comparison of engines in a related so question (and online database it links to)
The above might be called complex and bloated if compared to low level API such as OpenGL, but you have to define what kind of simplicity are you looking for.
For example, "easiest way to animate a 3D boat and some textured water" could mean that you write a clean low level interface directly on top OpenGL API; but as with anything graphics, and especially 3D, I do think that it will not be long before you will start thinking about lights, camera movement, interface, etc... and then you will probably wish for a richer environment.
So, the question is also if you want something really slim and then handle all sort of low level tasks or something that might include much more then you will ever need, but have lot of resources and shortcuts available.
Now, that my rant is finished - I am sure that you'll be able to find an exact example of animation that would take two mesh objects (sea and ship) in OpenGL and display them on screen in any decent OpenGL tutorial.
The easiest way would be to use PANDA3D. it uses python and is quite complete.
I've found OpenGL pretty easy to use in the past, or if you're on a Windows environment there's Direct3D too.

Categories

Resources