Duality C# based game engine with Visual editor

14. January 2014

I love seeing new game engines pop up, and this one just arrived on reddit.  It’s called Duality and it sounds kinda cool.

 

In the authors own words ( pretty much verbatim from reddit ):

 

What is Duality?

  • It's a 2D game engine that comes with a visual editor.
  • Both engine and editor are Open Source (MIT license).
  • It's all based on C# and OpenTK.
  • The frameworks architecture is built around a plugin system with hotswap support.
  • It is highly extensible, even without touching the original source code.
  • Work on this project began somewhere around November 2011. It's still in active development.

Duality1

 

Why does it exist?

  • My initial goal was to stop writing a new engine for every game I made, and instead create one framework that can serve as a basis for all of my future projects, regardless of genre or gameplay elements. This would allow me to spend less time on engine coding and more time on making games. Ironically, where I ended up is doing even more engine coding for quite a while - but by now, Duality has grown to be pretty usable, and I've developed a lot of projects just using it.
  • Duality exists, because I've always wanted a C# framework like this, but there was none that "had it all": Focused on 2D games, fast iteration times and visual editing, but at the same time free, Open Source and designed to be vastly extensible. While there are a lot of products on the engine market that do a really great job, most of them are still closed systems: Something that you might buy in a shop and use regularly, but wouldn't bother modifying, because it is generally a bad idea or downright impossible. On the other hand, Duality is kind of a construction kit.
  • Also, I have always been a fan of modding, i.e. being able to take an existing game as a player, and add my own stuff. One of the core ideas behind Duality is, that you, the developer, will use it to build your game and extend it wherever necessary. It's visual editor can serve as level editor, content database, sandbox and testing environment. When releasing your game - just leave the editor in there. It doesn't cost you anything, but your players get to use the same editing system you had: Duality, tailored exactly to fit your game.

 

Duality2

What can it do?

  • Content and Resource Management: Serialization, Importing and Updating Content, Custom Resource format using Binary or XML data, Friendly to Version Control systems, Robust in case of errors and old data
  • Scene Graph and Object Management: Component based GameObjects, Parent-child relations and transformation, Shared extensible Component interfaces, Scene queries
  • Audio: Playing and configuring sound effects and music, Streaming, Randomized sounds, 3D audio
  • Rendering: Camera based, Multiple Renderpasses, Postprocessing, Automated Batching and Z Sorting, Fake perspective using parallax scaling and scrolling
  • Physics: Based on a custom OpenTK version of Farseer Physics, Collision Detection, Rigidbody Physics, Visual Shape Editing
  • User Input: Keyboard, Mouse, Joysticks, Gamepads, Open to Custom Input methods
  • Visual Editor: What-You-See-Is-What-You-Get, Resource Hotswap, Plugin Hotswap, User Advice based on XML code comments, Extensive Dragdrop support, Multiple Views, Docking based on WeifenLuo library
  • A lot of other fancy stuff: Profiling, Logging, Text Formatting, Animation, Prefabs, Cloning, etc.

 

 

Where can I find more information?

 

What I don’t currently know is what platforms it runs on!  I am personally a fan of C#, so it’s always nice to see more options out there.

 

EDIT: According to the author, Duality is currently Windows only.  Being written in C# and on top of the OpenTK ( OpenGL for .NET ) libraries should make it fairly portable.

News, Programming ,




LibGDX minimal 3D app

10. January 2014

As I mentioned yesterday when talking about how to generate character sprites supporting dynamic inventory, the very first step would be to actually figure out how to do 3D in LibGDX.

 

Well, I did, and thankfully it’s pretty simple.  This isn’t a tutorial by any stretch of the means, but what follows is basically the “minimum” 3D application you can create in LibGDX.  It simple creates a blue cube and rotates the camera around it.  While it isn’t a tutorial, it is heavily documented, so you should be able to figure things out with ease, especially if you’ve already done my LibGDX tutorial series.

 

package com.gamefromscratch;

 

import com.badlogic.gdx.ApplicationListener;

import com.badlogic.gdx.Gdx;

import com.badlogic.gdx.graphics.Color;

import com.badlogic.gdx.graphics.GL10;

import com.badlogic.gdx.graphics.PerspectiveCamera;

import com.badlogic.gdx.graphics.VertexAttributes.Usage;

import com.badlogic.gdx.graphics.g3d.Environment;

import com.badlogic.gdx.graphics.g3d.Material;

import com.badlogic.gdx.graphics.g3d.Model;

import com.badlogic.gdx.graphics.g3d.ModelBatch;

import com.badlogic.gdx.graphics.g3d.ModelInstance;

import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;

import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;

import com.badlogic.gdx.math.Vector3;

 

public class TestApp implements ApplicationListener {

   private PerspectiveCamera camera;

   private ModelBatch modelBatch;

   private Model box;

   private ModelInstance boxInstance;

   private Environment environment;

 

   @Override

   public void create() {

   // Create camera sized to screens width/height with Field of View of 75 degrees

      camera = new PerspectiveCamera(

      75,

      Gdx.graphics.getWidth(),

      Gdx.graphics.getHeight());

 

      // Move the camera 3 units back along the z-axis and look at the origin

      camera.position.set(0f,0f,3f);

      camera.lookAt(0f,0f,0f);

 

      // Near and Far (plane) repesent the minimum and maximum ranges of the camera in, um, units

      camera.near = 0.1f; 

      camera.far = 300.0f;

 

      // A ModelBatch is like a SpriteBatch, just for models.  Use it to batch up geometry for OpenGL

      modelBatch = new ModelBatch();

 

      // A ModelBuilder can be used to build meshes by hand

      ModelBuilder modelBuilder = new ModelBuilder();

 

      // It also has the handy ability to make certain premade shapes, like a Cube

      // We pass in a ColorAttribute, making our cubes diffuse ( aka, color ) red.

      // And let openGL know we are interested in the Position and Normal channels

      box = modelBuilder.createBox(2f, 2f, 2f, 

      new Material(ColorAttribute.createDiffuse(Color.BLUE)),

      Usage.Position | Usage.Normal

      );

 

      // A model holds all of the information about an, um, model, such as vertex data and texture info

      // However, you need an instance to actually render it.  The instance contains all the 

      // positioning information ( and more ).  Remember Model==heavy ModelInstance==Light

      boxInstance = new ModelInstance(box,0,0,0);

 

      // Finally we want some light, or we wont see our color.  The environment gets passed in during

      // the rendering process.  Create one, then create an Ambient ( non-positioned, non-directional ) light.

      environment = new Environment();

      environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));

   }

 

   @Override

   public void dispose() {

      modelBatch.dispose();

      box.dispose();

   }

 

   @Override

   public void render() {

      // You've seen all this before, just be sure to clear the GL_DEPTH_BUFFER_BIT when working in 3D

      Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

      Gdx.gl.glClearColor(1, 1, 1, 1);

      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

 

      // For some flavor, lets spin our camera around the Y axis by 1 degree each time render is called

      camera.rotateAround(Vector3.Zero, new Vector3(0,1,0),1f);

      // When you change the camera details, you need to call update();

      // Also note, you need to call update() at least once.

      camera.update();

 

      // Like spriteBatch, just with models!  pass in the box Instance and the environment

      modelBatch.begin(camera);

      modelBatch.render(boxInstance, environment);

      modelBatch.end();

   }

 

   @Override

   public void resize(int width, int height) {

   }

 

   @Override

   public void pause() {

   }

 

   @Override

   public void resume() {

   }

}

 

And when you run it you should see:

RotatingCube

 

Next up, loading a 3D model from Blender and playing the animations.

 

By the way, although this isn’t a tutorial, if you have a question about something I did feel free to use the comments and I will do my best to answer!

Programming , ,




Creating dynamically equipped characters in 2D and 3D games

9. January 2014

 

Right off the hop for my new game I have to deal with a problem that many games have to deal with but one that could have a huge impact on how my game is structured, so I am going to address it with a proof of concept right up front.   That thing, as the title probably spoils, is character customization.

 

As I said earlier, this is a pretty common problem in games and something you see questions about quite often if you hang around game development forums for any period of time.  So what do I mean with character customization?  Ever played Diablo or a similar title?  When you change your gear in Diablo, your character is updated on screen.  This behaviour is pretty much expected in this day and age… personally I really hate when I am playing an RPG and the weapon I equip has no affect on my avatar.  That said, it is certainly a non-trivial problem and one that could have a pretty big impact on your game.

 

Let’s start by taking a look at the various options… at least the ones I can think of.

 

2D - Pre-render all possible configurations

Of course, brute forcing it is always a possibility and in a few cases may actually be ideal.  Basically for a 2D game, you simply create every combination of sprite for every combination of equipment.  So if you have an animation sequence for “walk_left” and “walk_right”, you would have to create a version for each possible equipable item.  So you might have “walk_left_with_axe” and “walk_left_with_sword” sprite sheets for the different weapon combinations.  If you are rendering your spritesheets automatically from a 3D application, this could actually be the easiest approach.  Of course there are some seriously massive downsides to this approach.  Memory usage quickly becomes outrageous.  For each piece of equipment you double the size of your original sprite sheet for example.  Once you start adding more and more options, this approach quickly becomes unfeasible.  If you only have a very small amount of customization ( two or three weapon options ), this approach may appeal due to it’s simplicity.  With anything more than a couple combinations though, this approach is pretty much useless.

 

2D – Pre-rendered spritesheet + pre-rendered weapon animation frames.

You can use a regular sprite sheet and simply keep the weapons separate.  So basically you have two separate sprite sheets, one of the character without weapons, one with just the weapons.  Then at run-time you combine them.   Consider these two sprite sheets ( taken from a StackOverflow question ).

Animated Character:

Player SpriteSheet

Weapon:

Weapon SpriteSheet

Then at run-time you combine the two sprites together depending on what is equipped.

In fact, if your weapon isn’t animated ( as in, it doesn’t move, like a sword, as opposed to a weapon like a whip or nunchucks ) you can get by using a hard point system, where you define the mount position of the weapon ( for example, the players right hand ) and orientation.  Basically for each frame of animation, you provide an x and y coordinate as well as rotation amount that represents where and how the weapon should be mounted.  Then at runtime you combine the two sprites, positioning and rotating the weapon sprite relative to the mount/hardpoint. This way, you only need a single image per equipable weapon.

This approach has a couple downsides.  First, you need a separate data file to hold mount point data and possibly a tool to generate it.  Second, it makes bounding/hit detection more difficult as the mounted weapon may exceed the dimensions of the originating sprite.  Third, you need to deal with z-depth issues, you cant simply paste the weapon on top of the sprite, as what happens when the character is walking right but carrying the weapon in the left hand?  To handle this your workflow needs to basically be: render obscured weapons, render character sprite, render foreground weapons.  Finally, weapons with their own animation, like a whip snapping, would require even more effort.

All told, this is probably the easiest while still flexible system for 2D animation.  It requires a bit more work than simply brute forcing your sprite sheets, but the payoffs in reduced size and complexity are well worth it, especially if you have more than a couple items.  One other big win about this approach is then weapons can be re-used across different sprites, a huge win!  Then you can model a single sword and it will be available to all sprite sheets with hard/mount point information available.

 

3D - Bone/hardpoint system

If your game is pure 3D this is often the way you want to go.  If you character is a knight for example, in your 3D modelling application you create named hard points in your model, either as bones or as an object of some form such as a null object, point or invisible box.  Then at runtime you bind other models to those locations.  So for example, if you equip a long sword and shield, your code searches for the “right_arm_shield” bone and uses it as the parent object for a shield 3D model.  Then you bind a sword to say… the “left_arm_hand” bone.  You can see an example of this behaviour in this UDK example.

This approach is basically identical to the last 2D method mentioned except in 3D and that you dont generally need to define your own hardpoint system, as most 3D packages and engines already support it out of the box, either by binding to a bone or by accessing and parenting 3D objects to named locations.  Like working in 2D, then your weapon and character are two separate entities, like so:

3P_Weapon_Attach.JPG

One of the major advantages of 3D over 2D is flexibility.  Most animations in 2D need to be pre-calculated, while in 3D you have a great deal more flexibility with the computer filling in the blanks for you.  Unlike in 2D, additional 3D animations add very little to the data file sizes.

 

2D Bone based animation

One of the major downsides to 2D animation is, as you add more animations, it takes up more space.  People have been working on solutions, one of the most common of which is 2D bone animation.  How exactly can you use bones on a 2D image file you ask?  That’s a good question!  In 3D, its pretty simple… the motion/influence of the bone transforms the attached geometry.  In 2D, there is no geometry, so how can you do this?

Well, the simple version is, you cut your bitmap or vector image up into body parts.  So instead of a single image of an animated character, you instead of an image for the foot, lower leg, upper leg, torso, waist, shoulder, left upper arm, etc…  Then you can draw 2D bones that control the animation of this hierarchy of images.  There are applications/libraries that support this, making it mostly transparent for you.  Here is one such example from Spine from Esoteric Software.

 

The character:

Creating Bones

 

It looks like a single image ( and you can see a couple bones being drawn in the foot/leg area ), but it is actually composed of a few dozen source images:

Set Parent

 

Basically the workflow goes, you create your traditional image in your regular art program, except instead of creating a single image, you create dozens of hopefully seamless ones representing each body part.  You stitch them together, setting the drawing order ( what’s covering what ), then define bones to create animations.  This has the double advantage of massively decreasing space requirements while simplifying the animation process.  The downsides are creating your initial image are a great deal more difficult and of course, you need to buy ( or roll your own ) bone system, such as Spine. 

 

Spine is not the only option, there is also Spriter from BrashSoftware and probably others I am unaware of.  Both of these are commercial packages, but then, both are dirt cheap ( IMHO ) with price tags between $25 and $250 dollars, with $60 and $25 dollars being the norm with each package respectively.

The nice thing about taking this segmented bone approach… you basically get the ability to swap components or bind weapons for free.

 

2.5D hybrid approach

2 1/2D is becoming more and more popular these days.  Essentially a 2.5D game is a 3D game with 2D assets ( such as 2D sprites over a 3D background ), but more commonly its 3D sprites over a 2D background.  How does this work?

Well there are two basic approaches.  You model, texture, animate your 3D model as per normal.  Any character customization you perform you would do as if you were working in full 3D.  Now is where the two different approaches vary, depending on performance, the hardware you are running on, etc…  You can either generate a sprite sheet dynamically.  Essentially when your character is loaded or you change equipment, in the background your game renders a sprite sheet of your updated character containing every animation frame, then you use this sheet as if it was a normal 2D sprite sheet.  The other option is, you render your character each time it moves.  Creating a spritesheet consumes more memory, but very little GPU or CPU demand.  Generating your characters current animation frame dynamically on the other hand, takes almost no memory, but at a much higher CPU/GPU burden.  Which is right for your game is obviously up to you.

Of course the 2.5D approach certainly has it’s share of problems too.  First off, it is the most complicated of the bunch.  Second, you cant do any “by hand” calculations on your generated sprite/spritesheets, as they are now being rendered dynamically.  This means no ability to create pre-calculated bounding volumes for example.  On the other hand, the 2.5D approach gives you most of the advantages of 3D ( compact animation data structure, easy programmable modification, ability to alter texture mapping, lighting effects, etc… ) that 3D does, but with the simplicity of dealing with a traditional 2D world.

One animation to rule them all!

You may be thinking WAHOO… I can cut my work way down now!  All I need to do is animate an attack sequence and then I can simply substitute the different weapon images.  Not so fast I am sorry to say.  Think about it this way…  are the images for swinging an AXE and a Sword the same?  What about a pole arm?  You are still going to have several different animations to support different classes of weapons, but these techniques will still vastly reduce the amount of data and work required while allowing a ton of customization.

 

 

So then, what am I going to do?

So, which approach am I taking?  Ultimately I am going to require a great deal of customization, going far beyond the examples described above.  One such example scenario is a Mech with a customizable left weapon… this weapon could be an arm holding a gun, a turret containing one or more guns, or possibly even a large pack of rockets.  Each “weapon” could have it’s own animation set.  Oh, and I am much more proficient in 3D than 2D.  On the other hand, the game itself is a 2D game and I would prefer to keep it that way for the simplicity that brings in a number of areas ( level creation tools, path-finding and other AI tasks, physics, cheating at art, etc… ).  As a result, I am going to try the 2.5D approach, where the mech is created and animated in 3D, dynamically equipped, then rendered to 2D.  I am going to try both pre-rendering sprite sheets and dynamically rendering a single frame and see what the overhead of each is.  I actually have the compounded issue of dealing with enemy characters that are also dynamically generated, so any impact will be magnified many time over!

If I can’t get adequate performance from each approach, I may be forced to go full 3D and emulating a 2D look.  As I said, it’s one of those things that can have a major impact on your game!  That said, I am pretty confident performance wont be too much of a factor.  My immediate take away task list is:

  • get a LibGDX project set up that can load and render an textured, animated 3D model exported from Blender. I am pretty new to 3D in LibGDX ( okay… completely new to it )
  • bind another model to a bone on this model ( aka, a sword to a hand bone )
  • try to dynamically generate a sprite sheet of the character’s complete animation.  Measure resulting memory usage and time required to generate sheet
  • re-architect the code to instead generate each frame of animation per frame on demand.
  • scale both scenarios up to include multiple instances and see results on performance
  • measure performance impact of each approach on both desktop and mobile.

 

The outcome of this experiment will ultimately decide what approach I take.  Stay tuned if that process sounds interesting!

 

Oh, and of course, these are only the scenarios I could come up with for dealing with dynamically equipped characters, if you have another idea, please share it!

Design, Programming , , ,




Leadwerks “indie edition” Game Engine added to steam for $99

6. January 2014

 

It started with GameMaker, now it seems more and more game development packages are being added to Steam, generally at vastly discounted prices.  Today we see Leadwerks Game Engine: Indie Edition has been added for $99.  On the website, Leadwerks is $199.  The question is, what is the limitiation of “indie edition”?  That’s the million dollar question.  It’s not a distribution thing, as they say in the Steam entry:

Your games you make are yours. Yours to play, yours to sell, yours to give away, and do as you please. You will never be charged royalties for any game you make in Leadwerks.

 

Anyways… about Leadwerks

Image Source

 

Leadwerks is a powerful and easy-to-use game engine for building any kind of 3D game. With a rapid development pipeline, Lua script integration, and plenty of learning materials, Leadwerks is the perfect way to make 3D games that look and feel amazing. Get started today making your own 3D games for Steam.

Key Features

Learn to Make Your Own 3D Games
We provide tons of documentation and video tutorials walking you through the steps to build your own 3D games. Leadwerks is the perfect pathway to go from total noob to pro game developer.


Advanced Graphics
Leadwerks brings AAA graphics to the masses, with hardware tessellation, geometry shaders, and a deferred renderer with up to 32x MSAA. Our renderer redefines realtime with image quality more like a cg render than real-time games of the past. The use of OpenGL 4.0 provides equivalent graphics to DirectX 11, with cross-platform support across operating systems, for future expansion.


Built-in Level Design Tools
Build game levels from scratch right in our editor with constructive solid geometry. Our tools make it easy to sketch out your design and bring your ideas to life. Anyone can build their own game worlds in Leadwerks, without having to be an expert artist.


Integrated Lua Script Editor
We integrated Lua right into Leadwerks because of its proven track records in hundreds of commercial games including Crysis, World of Warcraft, and Garry's Mod. Lua integrates seamlessly with native code for rapid prototyping and instant control. The built-in debugger lets you pause your game, step through code, and inspect every variable in the program in real-time. Lua is perfect for beginners, and the integrated Just-In-Time (JIT) compiler ensures your games will keep running fast as they grow.


Visual Flowgraph for Advanced Game Mechanics
Our unique visual flowgraph enables designers to set up game mechanics, build interactions, and design advanced scripted sequences, without touching a line of code. The flowgraph system integrates seamlessly with Lua script, allowing script programmers to expose their own functions and add new possibilities for gameplay.

 

Personally, I’ve no experience with Leadwerks, so I can’t comment on what the engine is like.

 

editFound this post, with a bit more details on the limitations of Steam, sorta…

"Leadwerks: Indie Edition" will be launched on Steam January 6th.  This will be on Windows only, with support for Lua scripting.  The following groups will receive a free Steam key to add this product to their Steam account:

  • Leadwerks 3.0 customers who pre-order the upgrade to version 3.1.
  • New customers who pre-order Leadwerks 3.1.
  • All Kickstarter backers who backed Leadwerks for Linux for $49 or more.  (Even if you don't run Windows, hold onto this as the Linux version on Steam will have special features.)

Leadwerks 3.1 for Linux and Windows will be released together next, with the exact release date to be determined.  Leadwerks 3.1 for Mac will follow this, with mobile add-ons for iOS and Android coming last.  (There is no purchase necessary to upgrade the mobile add-ons from Leadwerks 3.0 to Leadwerks 3.1.)

 

Still not completely sure what that means in terms of limitations… does that mean the Indie edition is Lua only and targets only WIndows?  Or just that the Windows version is available?

 

edit2: Found this comment on the difference:

The standard edition is more expensive but includes C++ programming capability. That's important to some people, and for others it's not a big deal. Since we use a just-in-time compiler to make Lua execution fast, Lua alone is perfectly capable of making full games.

So, indie edition has no C++ support…  that’s a bit of a big difference to many people I should imagine.

News, Programming




Godot Unity like game engine going open source

5. January 2014

 

There is a new entrant in the game engine space, the Godot game engine from Okam Studio.  The engine was apparently used for in-house projects and is over a decade in the making.  The editor runs on Linux, Windows and OSX and can target desktop, mobile, consoles as well as HTML.

godot1

godotss2.png

godotss1.png

 

From observation, the engine appears to be similar to Unity, but powered by C++.  It uses a custom scripting language that appears LUA like.

 

In the developers own words:

We’ll be opening a game engine that has more than a decade of work (and several iterations) as MIT license soon.

It’s not an engine made by hobbyists, this is a production tool used to develop and publish plenty of games for PC, Consoles and Mobile. It’s currently in beta stage, meaning it’s feature complete and fully usable, but lacks very little fine tuning and testing. It has a similar feature set to Unity (little less stuff on 3D front, much more stuff on the 2D front, debugging). and runs on all the popular desktop and mobile platforms, as well as on the web (through asm.js).

Unlike almost any other game engine with this level of features, the editor runs fine in Linux, as well as Windows and OSX, and supports one click deploy.

 

Apparently the engine is being released under the MIT open source license ( a very generous license ) and is undergoing polish before complete release.  If you are interested in early access, contact juan@okamstudio.com.

 

I’ll be keep an eye on this one… a C++ powered Unity like engine is sure to be interesting to many.  Not sure exactly when it will drop but for now we are … Waiting for Godot.

 

Ok… that was bad.   More details as I get them.

News, Programming