问题描述:

I ask here about XNA and not on it's official forums because people from my country are not allowed to sign in to the new XNA website.

Well, these are my questions:

  1. I want to use some 2D images I create in Paint Shop Pro/Photo Shop/Paint, but for some reason I need to use web safe pallet and such settings for it to be displayed currently (I use transparency).

    could any1 please explain to me how can I use transparency & other settings (while creating & saving the image) so that the XNA (4.0) could display it correctly?

    By the way, it might be that I just need some 1 to explain to me how to set the "GraphicsDevice"-s settings to work with transparency layer/channel.

  2. I really do try to do things as I am supposed to (by Microsoft's view) & thus I use the content pipeline for ALL of my content loading (including classes initiation data files).

    I use .txt files for storing my class initiation data & I edit them with simple good old notepad (++ :P).

    Now, the problem is that all I managed to do is loading the .txt file as a really long string instead of creating a new instance of my GameDataFile class.

    because of that I was forced to do it in 2 steps:

Step 1:

string tempStrData = content.load<string>("data/filename").Replace("\r", "");

/* Loads a string from a file (the string is the whole file!) */

Step 2:

GameDataFile gameDataFile = new GameDataFile(tempStrData.Split('\n'));

/* Sends the string to my GameDataFile class constructor which knows how to handle that string and break it to it's data elements (ints, strings vectors, etc...) */

I want to upgrade it to be of the following form:

GameDataFile gameDataFile = content.load<GameDataFile>("data/fileName");

I think I should do this using a custom Content pipeline Processor, any opinions if I'm right & how should I achieve that?

P.S please don't make me to use public members as I always set that to private and I hate and strictly forbid myself from using the C#-ONLY-get-&-set methods.

Thanks In Advance, Tal A.

网友答案:

For your first question, set the blendstate to AlphaBlend when you begin your SpriteBatch:

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null);

I save my images as PNGs in PhotoShop which allows transparency.

Edit: Unless you're referring to 3D textures. If so I'll have to revise my answer

Edit: As for question 2, this example on App Hub shows how to do it.

相关阅读:
Top