Ask Twitter: Placeholder art, scoring my own games, XNA, the leap to procedural

With today’s work on Soulcaster mostly being behind-the-scenes stuff involving the new slotting equipment/inventory system, I figured I didn’t have much to say on that topic today. I decided to poll my Twitter list for topic ideas, and got several I could answer lightning-round style. Here goes.

blog topic idea - vgm

On my own games, I get to pick whatever style I want, and have final approval. This does not necessarily make things any easier. Lack of constraints can be paralyzing for me, so I usually set up some artificial constraints before starting the score. On all four of my games so far, I’ve gone for something of a 90’s era redbook audio vibe. Soulcaster used Lagoon (SNES) as its main inspiration, Soulcaster II used Labyrinth (the movie), Escape Goat used Castlevania: Curse of Darkness, and Escape Goat 2 drew a bit from Bayonetta. All of the instrument sets were restricted to software versions of hardware that was available in the 80’s and 90’s.

Getting DPad Input from Thumbsticks in XNA – The Right Way

If you want to simulate 4-way DPad movement with the left or right analog thumbstick in XNA, my advice is to never use Buttons.LeftThumbStickUp, etc. This is because the default behavior doesn’t take into account the dead zone for the stick, which varies from controller to controller.  (The dead zone is the location near the center of the stick position, where it won’t send any movement value to the Xbox.)

You might test on a controller with a large dead zone and have no problem, then someone else will play your game with a very small dead zone, and they will find the control “sticking” in that direction.  I’ve had some controllers where the dead zone was so precise, I could have my thumb off the joystick and it would still be transmitting a tiny movement value.

I suggest adding a large dead zone, to make sure you only get simulated DPad input for large, deliberate movements of the analog stick.  Here’s some code that works for me, adjust as necessary to fit your control scheme:

static Buttons GetThumbstickDirection(PlayerIndex player, bool leftStick)
{
    float thumbstickTolerance = 0.35f;

    GamePadState gs = GamePad.GetState(player);
    Vector2 direction = (leftStick) ? 
        gs.ThumbSticks.Left : gs.ThumbSticks.Right;

    float absX = Math.Abs(direction.X);
    float absY = Math.Abs(direction.Y);

    if (absX > absY && absX > thumbstickTolerance)
    {
        return (direction.X > 0) ? Buttons.DPadRight : Buttons.DPadLeft;
    }
    else if (absX < absY && absY > thumbstickTolerance)
    {
        return (direction.Y > 0) ? Buttons.DPadUp : Buttons.DPadDown;
    }
    return (Buttons)0;
}

Unity and MonoGame

There are plans to port my games to other platforms.  Windows is easy because my games already run on Windows.  XNA works great, you just have to remove the Xbox-specific stuff (related to the Guide and Gamer Services) and you’re good to go.  Unfortunately there’s no turnkey solution for the other platforms, so the porting process is going to be… more of a real port.

Today I investigated two options for this task.  First was MonoGame, basically a substitute for the XNA libraries that supposedly runs on Linux, OSX and iOS.  Sounds too good to be true, and unfortunately at this stage, it just doesn’t look ready.  To get a game to compile with it, I had to remove tons of code due to compatibility errors and missing API calls.  Even once I got through the compile errors and runtime errors, the game never managed to draw anything (though it could clear the screen to a specific color).  Plus the startup time for the application was about 5x compared to native XNA… so maybe there are workarounds, but so far it just doesn’t seem viable.

Unity is the other option.  Now a port from XNA to Unity is a major undertaking.  I got some serious protips from Brad who helped me through all those tiny things that trip up newcomers, and probably saved me a day’s worth of Googling.  The good news is I have a friend who knows Unity whom I can harass with my questions.  The bad news is that there will be some serious translation work to get my code from XNA to Unity.  I was hoping to put everything (my whole game) in one game object and let it draw itself, since I don’t need any of the high level features of Unity.  Just give me a surface to draw to.  Unfortunately it’s not so simple… exactly what this will take is something I’ll be discovering over the next few days.