Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fallen_Angel

Can someone please check this code/logic?

This topic is 6005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
  

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!