• Content count

  • Joined

  • Last visited

Community Reputation

124 Neutral

About MasterEvilAce

  • Rank
  1. Overlapping sprites with transparency

    I need to be able to do this all within one sprite batch, due to render order and performance issues. I've been looking into BlendStates trying to figure this out, but there is a severe lack of tutorials / understanding on my part. I have to use the XNA "Reach" profile which seems to have some limitations on BlendState settings (unsure if this should affect what i'm trying to achieve.) Basically, the objective (I believe) is basically to only draw the latest partially-transparent, if there are multiple transparent pixels at the same location. But figuring this out is tough without a good understanding.
  2. [img][/img] Using XNA 4. I'm rendering a bunch of overlapping sprites to the screen based on a calculated layerDepth. Any sprites that might conceal the player I draw with a transparent color in the draw function. Is there a way to prevent visible overlapping edges in this scenario? (See corner block sides "doubling up" against the other transparent pieces) Basically, I'd like the three partially-transparent walls to look like one object, without seeing the sides of the walls that you wouldn't normally see, if they were fully opaque.
  3. [XNA] Manual "Premultiply Alpha" rendering issue

    Doing some more investigating.. I found this post It looks like RenderTarget2D is volatile and can lose its contents when the backbuffer resizes. This makes sense. I've noticed there is a RenderTargetUsage.PreserveContents that can be passed in via constructor.. I've tried this and it makes no difference at all. (This doesn't make sense.) I see there was no "real solution" to the guy's problem... For now I'm going to use his solution and copy the texture data from the RenderTarget2D into a new Texture2D. I'm still wondering if anybody has any better ideas?
  4. I'm using XNA4, and I was rendering everything perfectly to screen using spritebatches on premultiplied alpha PNG's. Decided to forego the Content.Load that XNA provides and use Texture2D.FromStream in order to dynamically load PNGs, in order for the artist to test graphical changes quicker without recompiling. In doing so I had to find some code in order to convert the Texture2D to a "premultiplied alpha" format, which is what XNA4 defaults to normally. This is the code I found from: [code] // Blah blah Texture2D t = Texture2D.FromStream(graphicsDevice, titleStream); // Blah blah blendColor = new BlendState(); blendColor.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue; blendColor.AlphaDestinationBlend = Blend.Zero; blendColor.ColorDestinationBlend = Blend.Zero; blendColor.AlphaSourceBlend = Blend.SourceAlpha; blendColor.ColorSourceBlend = Blend.SourceAlpha; blendAlpha = new BlendState(); blendAlpha.ColorWriteChannels = ColorWriteChannels.Alpha; blendAlpha.AlphaDestinationBlend = Blend.Zero; blendAlpha.ColorDestinationBlend = Blend.Zero; blendAlpha.AlphaSourceBlend = Blend.One; blendAlpha.ColorSourceBlend = Blend.One; RenderTarget2D target = new RenderTarget2D(graphicsDevice, t.Width, t.Height); graphicsDevice.SetRenderTarget(target); { graphicsDevice.Clear(Color.Black); SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); // Multiply each color by the source alpha, and write in just the color values into the final texture spriteBatch.Begin(SpriteSortMode.Immediate, blendColor); spriteBatch.Draw(t, t.Bounds, Color.White); spriteBatch.End(); // Now copy over the alpha values from the PNG source texture to the final one, without multiplying them spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha); spriteBatch.Draw(t, t.Bounds, Color.White); spriteBatch.End(); } graphicsDevice.SetRenderTarget(null); t = target as Texture2D;[/code] Using this code, everything renders correctly just as it did before the switch-over. However, now when I resize the game window (or maximize/restore the window) the rendering breaks, and all textures end up black. The only thing that still renders is the HUD, where I used DrawString(). This did not happen previously. Infact, I can comment out all of the Premultiply Alpha code from above, and the issue goes away, except now that I'm not using a "premultiplied alpha" texture, the rendering is funky. What is the issue that is going on, here? I have a feeling it has to do with changing the RenderTarget, but I'm not entirely sure.
  5. XNA Custom Sprite Sorting on Z Plane

    Never seen that error before, but it sounds like the method is screwing up because your objects are not returning a consistent sort value, which means they can't be sorted. See: A = 1 and B = 2. But when Compare(A, B) gets run, A = 1, and B = 7. If another object gets compared, it will look like Compare(B, C).. but this time B = 2, and C = 8. But B can't equal 2 *AND* 7. So the sort fails and an exception is raised. The way the compare function is called, you can never be sure which elements get passed in in any particular order.. that's dependent on the sort algorithm. All you're modifying is how the objects compare to each other. The easiest way would be to sort at the end by something unique to the entity. For instance, if you already have an Entity.ID, just sort by that. [code] public int Compare(Entity e1, Entity e2) { float z1 = e1.GetZ(); float z2 = e2.GetZ(); if (z1.Equals(z2)) if (e1.ID.Equals(e2.ID)) return 0; else return e1.ID.CompareTo(e2.ID); else return z1.CompareTo(z2); }[/code] Note: Return 0 means the objects are identical.. since you're already using the CompareTo function, you probably know that. The "return 0" should never get hit during the sort, because the same entity.ID should never exist twice in your entity list. But it's best to leave it in there, because you can use the Compare function in other ways. In this way, a lower ID will always be ordered first, then a higher ID. This will give you the consistency you need for overlapping objects.The flickering is caused because two objects COMPARE equally to each other. In the first sort, entity1 may end up before entity2... but in the second sort, because they're equal, there's a chance that entity2 ends up before entity1. Doing this 60 times a second means the objects change places very rapidly, producing a noticeable flicker.
  6. [XNA 4] Isometric block placement issue

    Look at how you're actually drawing the tiles. Just looking at the top row you can see what's going on. (Ignoring the Y for now) you're rendering 0,0 then 1,0 then 2,0. If you look at the arrangements of those tiles you SHOULD be rendering 0,0 then 2,0 then 4,0 (etc) THEN render 1,0 and 3,0, etc. 2,0 is physically setup to be behind 1,0, so it needs to render first. As far as the solution goes, I'm not sure the best course of action. But that's what your problem is. I think the best solution might be to setup your grid to where the first actual row is 0,0 then 1,0 then 2,0 then 3,0. The next row (shifted over) is 0,1 then 1,1 then 2,1 then 3,1. However, the rest of your math for click tiles, etc. would have to be modified as well.
  7. I'm not entirely sure if there is a fast, simple way to do this... I'm thinking regex is probably the simplest way of doing this. What I need to do is be able to compare strings that may or may not have wildcard characters in them. For instance I may have a list of >strings< like this: 11225 1123? 48622 55* 785?? 99745 And I will be trying to match other strings to this list. I will loop through the list looking for a match. There will only be one possible match in the list, and I will be comparing one at a time until I find a match. * is a wildcard that any number of any characters can match ? is a wildcard that matches any single character in its place anyone good with regular expressions? Thanks
  8. Binary Packet Overview/Tutorial on the Wiki

    Sirisian, Thanks for the response. Looks great. I've implemented it and it looks like it should work well. Haven't had time to actually test it out, busy with other things. Your BinaryPacket solution looks to be the easiest method i've found for doing this kind of thing.
  9. Binary Packet Overview/Tutorial on the Wiki

    Quote:Original post by Sirisian Quote:Original post by Drew_Benton Couple of questions: 1. Wouldn't the bitIndex and maxBitIndex fields need to be set here to avoid overwrites on sequential Write calls?public BinaryPacket(byte[] buffer) { this.buffer = new List<byte>(buffer); } I'm not even sure why I have that constructor. I should probably just remove it. I had this idea that someone might try to write corrupt packets to an error log and read them later. Isn't that constructor required.. or else you can never actually load a byte array from a packet that was generated from a separate BinaryPacket class... Anyways.. My question is in regards to the implementation of your BinaryPacket and sending this over a NetworkStream. Specifically I am using a TCPClient and ASync read/write (client.GetStream().EndRead(ar)) I understand I can create a binary packet and then call bp.Buffer which creates a byte array and send that. However I need help on implementing a good OnReceive function. I have a byte[] readBuffer that contains the data received from a NetworkStream. What exactly do I need to do at this point? The BinaryPacket has the length of the packet as the first few bytes, however given that we can't be sure that the packet was split up (and thus not received fully), or that we may have received TWO packets in readBuffer... how do I handle this? I need a good solution to separate whole packets out of the readBuffer so I can create separate BinaryPackets to send to other functions to process, leaving any 'half packets' in the readBuffer to get appended to Your class is brilliant Thanks.
  10. [.net] C#, HSL and PNGs

    I've done some browsing and testing.. I can use float[][] ptsArray = {new float[] {1, 0, 0, 0, 0}, new float[] {0, 1, 0, 0, 0}, new float[] {0, 0, 1, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {sr, sg, sb, 0, 1}}; ImageAttributes ia = new ImageAttributes(); ColorMatrix cm = new ColorMatrix(ptsArray); ia.SetColorMatrix(cm); to adjust red/green/blue. when sr, sg, and sb (red green blue values) are 0,0,0, the picture is untouched. valid numbers are between -1 and 1. So 255 is 1, and -255 is -1. if the numbers are higher, that color is applied to the image. If they're negative, it makes the image darker with that color. So it's basically a color offset.. manipulate the colors that are already there. I need some way to incorporate Hue/Saturation/Luminance into this. It's complicated because i see no way to really convert HSL into RGB, unless you have a color to start with. And secondly, the values also need to be negative. So HSL and RGB don't help me entirely. anyone have any ideas?
  11. I'm using C#, .NET 2.0, I'm using GDI+ for my image stuff I'm needing to adjust the hue saturation and luminance of a PNG that's loaded into memory. I'm also needing to keep transparency information intact. Anyone have any good methods of doing this?
  12. A Game for a New input Device

    I don't think this has been said.. but what does this object LOOK like? In my mind I picture a sort of sphere-controller where your fingers fall into grooves, and the top of it is a bit more flat, for your thumbs and with a few other buttons maybe.. However it could rather be some sort of flat keyboard thing, or maybe something that works with something attached to your fingertips? Essentially basics such as are your fingers always NEAR the "hot areas" like the sphere idea, or is it more like a keyboard where you can move your fingers about and just hit the specific area for a certain finger whenever you feel like it? Or is this like those touchscreens except you can fully utilize many many fingers? In that case what you touch would easily match up to whatever is on the screen, on the other scenarios, it wouldn't be so easy to have some sort of correlation like that.. the sphere idea you could use the thumbs to move around (normal everyday two-stick controllers) and the 8 remaining fingers access various commands. Depending on how it's setup, that could shape the game itself.
  13. Entity collisions in a 2D world

    Wow, working on a very similar project (even had it setup the same way!) However the scale of the game I'm working on is massive, and yours seems like it's a small single-player type game. Anyways, what you should do is check whether or not the object will collide BEFORE it moves. What it seems like you're doing right now is checking collision everytime you render? Or just whenever the collision check gets called? Either way, it's highly more efficient to simply check where an object is moving before it moves. That way you can simply ignore the request if the object would collide with something. You don't check items that don't need checked, as well. So it's an added benefit. Oh, if you have multiple objects in one cell.. I suppose you would essentially loop through them all in that one cell. If player is at 5,5 and moves to 5,6, the player will be checked for collisions against object 1 through 3 (if there are 3 objects in that cell).. if there is a collision at ANYTIME then get out of the loop (so you don't loop any extra unneccessary items), and either tell them they can't move, or just don't move them at all. That's up to you.
  14. Project Basics

    Me and some friends are wanting to start a project together and I'm trying to get some basic guidelines drawn up so we all have a place to start. What we're thinking about is an isometric multiplayer RPG game using DirectX, programmed in C#. It would be nice if it ran on Linux and Windows, and essentially free of any royalty stuff with formats. (Ignore that we're using DirectX for now.. I hear it's just easier to work with for now.. if we ever want to port to linux we could always include an opengl option) With that in mind, what formats should we use for images, sounds, music, etc. I'm thinking music could be OGG, but what about images and small sounds? Should all sounds use OGG, or is something like wav better suited? For images we need something that is high quality, and will be good with directx. Also something decent in size (obviously nothing like BMPs). I think PNG? Would that be the best to use? Programming-wise.. what sort of database should we use? It should be able to handle a large amount of data accessing quick and easily. I have experience with MySQL, but i'm not sure if that's the best suited for this project Are there also any sites that provide free pre-made graphics and sounds we could use until we made our own? also any tutorials on making this sort of thing would be great