Saturday, 11 April 2009

Priority

Having a little trouble with the priority of sprites, but nothing desperate yet. I have a feeling that monkeying with vector elements is the cause of the problem. I may have to try a different approach to sorting the sprite list.

(later) Schoolboy error. I was using insertElementAt() instead of setElementAt().

Thus - the Vector of Sprites appears in slist:
//      This is a sinking sort. On first pass, the highest
// priority sprite arrives at the bottom. On second,
// the next highest arrives at second bottom, etc.
// Sprites of the same priority remain in their
// original sequence with respect to each other.
for (ii = 0; ii< slist.size()-1; ii++)
{
for (jj = 0; jj < (slist.size()-ii-1); jj++)
{
spare1 = (Sprite)slist.elementAt(jj);
spare2 = (Sprite)slist.elementAt(jj+1);
if (spare1.getPriority() > spare2.getPriority())
{
slist.setElementAt(spare1, jj+1);
slist.setElementAt(spare2, jj);
}
}
}

No comments: