int i, j, k, l, temp;
for (j = 0; j < nMaxCount; j++)
nObjectOrder[j] = NULL;
int n = 0;
for (k = 0; k < nMaxCount; k++)
{
if (pObjectList[k] != NULL)
{
nObjectOrder[n] = k;
n++;
}
}
for (i = 0; i < (n - 1); i++)
{
for (j = i + 1; j > 0; j--)
{
if (pObjectList[nObjectOrder[j]]->nY < pObjectList[nObjectOrder[j - 1]]->nY)
{
temp = nObjectOrder[j];
nObjectOrder[j] = nObjectOrder[j - 1];
nObjectOrder[j - 1] = temp;
}
}
}
for (l = 0; l < n; l++)
pObjectList[nObjectOrder[l]]->draw(surface);
Fa||en_Ange| Productions
Can someone please check this code/logic?
What I''m trying to do is draw all of my sprites based on their y-value, that way they all overlap each other correctly when they walk behind each other. What I''ve done so far is just place them all into an array and perform a bubble sort using the y-values. It''s currently working but I only have two sprites at the moment and I just want to be sure on this before I go any further. In the code nMaxCount is the number of game objects, pObjectList is an array of objects and nObjectOrder is an array of ints. Thanks heaps.
You mean the [nObjectOrder[j]]->nY?
That simply returns the objects y-value.
Fa||en_Ange| Productions
That simply returns the objects y-value.
Fa||en_Ange| Productions
quote:
So... what does the ny method do?
ny is a member variable, not a method. If it was a method, it would look like pObjectList[nObjectOrder[j]]->nY()
Notice the parenthesis.
Are you using C or C++?
Take care,
Bill
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement