Jump to content

  • Log In with Google      Sign In   
  • Create Account


MasterEvilAce

Member Since 10 Jun 2006
Offline Last Active Nov 24 2013 06:39 PM
-----

Posts I've Made

In Topic: Overlapping sprites with transparency

01 March 2012 - 02:34 PM

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.

In Topic: [XNA] Manual "Premultiply Alpha" rendering issue

24 October 2011 - 04:14 PM

Doing some more investigating.. I found this post
http://stackoverflow.com/questions/5509265/after-writing-to-a-rendertarget-how-to-efficiently-clone-the-output

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?

In Topic: XNA Custom Sprite Sorting on Z Plane

15 October 2011 - 04:09 PM

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.


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);
}
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.

In Topic: [XNA 4] Isometric block placement issue

25 September 2011 - 01:12 PM

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.

In Topic: Binary Packet Overview/Tutorial on the Wiki

16 September 2009 - 09:08 AM

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.

PARTNERS