2
\$\begingroup\$

I've been using XNA for a while to tinker with 2D game development, but I can't help but feel constrained by the content pipeline when targeting PC only. Things like no vector fonts or direct use of graphics files make it a pain while other frameworks do these things with no problem. I like XNA because it's robust and has a lot of support, but what are the specific benefits that I'd get developing exclusively for PC, if there are any at all?

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Well content pipeline is actualy big benefit, since most of data are not in right format to put directly into your game, so you would need to write converters or exporters (which content pipeline is). And you dont need to use it. Texture2D can be loaded from stream, effect can be constructed from byte array... \$\endgroup\$
    – Kikaimaru
    Oct 12, 2012 at 14:27
  • \$\begingroup\$ You might actually be better off switching away from XNA. Read this question and its answers. Please let me know if this fully answers your question and I'll mark it as a duplicate. \$\endgroup\$
    – Ricket
    Oct 12, 2012 at 14:29
  • 6
    \$\begingroup\$ Are you asking a question or complaining? XNA is a large library that does a ton of work for you. That's the benefit. \$\endgroup\$
    – Cypher
    Oct 12, 2012 at 23:57
  • \$\begingroup\$ And the fact that you are not limited to PC , XBox or Windows Phone, Check out Monogame and run your games on Linux, iOS, MacOS, Android, WinRT and a few other systems \$\endgroup\$
    – TimothyP
    Jan 29, 2013 at 13:13

1 Answer 1

3
\$\begingroup\$

Everything you are complaining about has been solved by the XNA community or is actually supported by the library.

Vector Fonts thanks to the Nuclex Framework

Also loading Texture2Ds from a stream is built into the library. If you want to use premultiplied alpha (the default XNA blend mode) with stream loaded textures use the below function.

static public void PreMultiplyAlpha(this Texture2D texture) {            

    //Setup a render target to hold our final texture which will have premulitplied color values
    var result = new RenderTarget2D(texture.GraphicsDevice, texture.Width, texture.Height);

    texture.GraphicsDevice.SetRenderTarget(result);
    texture.GraphicsDevice.Clear(Color.Black);

    // Using default blending function
    // (source × Blend.SourceAlpha) + (destination × Blend.InvSourceAlpha)
    // Destination is zero so the reduces to
    // (source × Blend.SourceAlpha)
    // So this multiplies our color values by the alpha value and draws it to the RenderTarget
    var blendColor = new BlendState {
        ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue,
        AlphaDestinationBlend = Blend.Zero,
        ColorDestinationBlend = Blend.Zero,
        AlphaSourceBlend = Blend.SourceAlpha,
        ColorSourceBlend = Blend.SourceAlpha
    };

    var spriteBatch = new SpriteBatch(texture.GraphicsDevice);
    spriteBatch.Begin(SpriteSortMode.Immediate, blendColor);
    spriteBatch.Draw(texture, texture.Bounds, Color.White);
    spriteBatch.End();

    // Simply copy over the alpha channel
    var blendAlpha = new BlendState {
        ColorWriteChannels = ColorWriteChannels.Alpha,
        AlphaDestinationBlend = Blend.Zero,
        ColorDestinationBlend = Blend.Zero,
        AlphaSourceBlend = Blend.One,
        ColorSourceBlend = Blend.One
    };

    spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha);
    spriteBatch.Draw(texture, texture.Bounds, Color.White);
    spriteBatch.End();

    texture.GraphicsDevice.SetRenderTarget(null);

    var t = new Color[result.Width * result.Height];
    result.GetData(t);
    texture.SetData(t);
}

Are there specific benefits to using XNA for 2D development if you don't plan on releasing on xbox/windows phone?

Anyways your main question makes no sense. Why are "specific benefits" for PC developers a desired trait? The library makes 2D graphics very easy on all supported platforms. So no, there are no benefits to being a PC exclusive developer.

\$\endgroup\$
3
  • \$\begingroup\$ By 'specific benefits' I meant something that would make it preferable over other 2D libraries available. I admit I'm not the most knowledgeable about the subject but a lot of the features of XNA seemed aimed to me at making the code usable on Xbox and Windows Phone. If I am totally wrong then that's what I want to know. \$\endgroup\$
    – ssb
    Oct 13, 2012 at 2:49
  • 3
    \$\begingroup\$ This is all very subjective but personally I find the XNA library pretty intuitive. Every time I have been unable to understand something there have been plenty of people eager to help. There are also nice libraries that help with the tricky stuff persoanlly I use (Spriter, Farseer Physics, tIDE, and Krypton XNA) for the little 2D platformer I'm working on. \$\endgroup\$ Oct 13, 2012 at 18:02
  • \$\begingroup\$ Didn't realize edits bumped topics. Was replacing a link to my currently down blog with useful content. \$\endgroup\$ Jul 24, 2013 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .