Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualfreeworld

Posted 25 January 2013 - 05:49 PM

OK taking a better look at it im now really confused with the code you posted.

 

First of all you're double drawing everything, just doing it backwards the second time. and the way you are drawing, for every zombie your all the debris that is behind it, or so I'm assuming. Also redrawing the zombie on top of that debris everytime. Then you sortve repeat the process but this time its all the debris in front of the zombie gets draw on top of a redrawn zombie.

 

That's only if there's something in both the lists, others wise you just draw everything....?

 

1: Do you even need the checks for if there is something in any of the lists? will foreach not just immediately exit like a for loop?

 

2: Both your zombie and debris containers use the exact same code to render themselves, could both objects not be inherited from a base renderable object. That way you could have them in the same container, sort by depth and render that way?

 

using two list in complicates things more than I would bother with but I think youre trying to get somthing like this, but you're doing all your logic for each zombie regardless of anything else.

 

*Psuedo*

 

 
// sort both list by they're 'Y' value
 
// I'm not sure of the container you're using but I'll use a std::vector  (c++)
std::vector<debris>::iterator debrisIterator = debris.begin();
std::vector<zombie>::iterator zombieIterator = zombie.begin();
 
// aslong as you haven't drawn all the objects continue
while (debrisIterator != debris.end() && zombieIterator != zombie.end())
{
   float debrisY = -1;
   float zombieY = -1; // -1 means the containers was empty.
 
   // get the 'Y' values of the iterators, set -1 if empty
 
   if (debrisY >= zombieY)
   {
      draw(debris)
      debrisiterator++;
    }
   else 
   {
      draw(zombie)
      zombieIterator++;
   }
}
 

 

 

Also, sprite batch is batching by texture? if so it won't matter what order you put them in, the last texture will always be on top unless you're using a depth buffer to prevent this. Just thinking.


#2freeworld

Posted 25 January 2013 - 05:48 PM

OK taking a better look at it im now really confused with the code you posted.

 

First of all you're double drawing everything, just doing it backwards the second time. and the way you are drawing, for every zombie your all the debris that is behind it, or so I'm assuming. Also redrawing the zombie on top of that debris everytime. Then you sortve repeat the process but this time its all the debris in front of the zombie gets draw on top of a redrawn zombie.

 

That's only if there's something in both the lists, others wise you just draw everything....?

 

1: Do you even need the checks for if there is something in any of the lists? will foreach not just immediately exit like a for loop?

 

2: Both your zombie and debris containers use the exact same code to render themselves, could both objects not be inherited from a base renderable object. That way you could have them in the same container, sort by depth and render that way?

 

using two list in complicates things more than I would bother with but I think youre trying to get somthing like this, but you're doing all your logic for each zombie regardless of anything else.

 

*Psuedo*

 

 
// sort both list by they're 'Y' value
 
// get the lowest 'Y' value available.
 
// I'm not sure of the container you're using but I'll use a std::vector  (c++)
std::vector<debris>::iterator debrisIterator = debris.begin();
std::vector<zombie>::iterator zombieIterator = zombie.begin();
 
// aslong as you haven't drawn all the objects continue
while (debrisIterator != debris.end() && zombieIterator != zombie.end())
{
   float debrisY = -1;
   float zombieY = -1; // -1 means the containers was empty.
 
   // get the 'Y' values of the iterators, set -1 if empty
 
   if (debrisY >= zombieY)
   {
      draw(debris)
      debrisiterator++;
    }
   else 
   {
      draw(zombie)
      zombieIterator++;
   }
}
 

 

 

Also, sprite batch is batching by texture? if so it won't matter what order you put them in, the last texture will always be on top unless you're using a depth buffer to prevent this. Just thinking.


#1freeworld

Posted 25 January 2013 - 05:46 PM

OK taking a better look at it im now really confused with the code you posted.

 

First of all you're double drawing everything, just doing it backwards the second time. and the way you are drawing, for every zombie your all the debris that is behind it, or so I'm assuming. Also redrawing the zombie on top of that debris everytime. Then you sortve repeat the process but this time its all the debris in front of the zombie gets draw on top of a redrawn zombie.

 

That's only if there's something in both the lists, others wise you just draw everything....?

 

1: Do you even need the checks for if there is something in any of the lists? will foreach not just immediately exit like a for loop?

 

2: Both your zombie and debris containers use the exact same code to render themselves, could both objects not be inherited from a base renderable object. That way you could have them in the same container, sort by depth and render that way?

 

using two list in complicates things more than I would bother with but I think youre trying to get somthing like this, but you're doing all your logic for each zombie regardless of anything else.

 

*Psuedo*

 
// sort both list by they're 'Y' value
 
// get the lowest 'Y' value available.
 
// I'm not sure of the container you're using but I'll use a std::vector  (c++)
std::vector<debris>::iterator debrisIterator = debris.begin();
std::vector<zombie>::iterator zombieIterator = zombie.begin();
 
// aslong as you haven't drawn all the objects continue
while (debrisIterator != debris.end() && zombieIterator != zombie.end())
{
   float debrisY = -1;
   float zombieY = -1; // -1 means the containers was empty.
 
   // get the 'Y' values of the iterators, set -1 if empty
 
   if (debrisY >= )
   {
      draw(debris)
      debrisiterator++;
    }
   else if (zombieY >= debrisY)
   {
      draw(zombie)
      zombieIterator++;
   }
}
 

 

 

Also, sprite batch is batching by texture? if so it won't matter what order you put them in, the last texture will always be on top unless you're using a depth buffer to prevent this. Just thinking.


PARTNERS