#### Archived

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

# 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.

## 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 on other sites
So... what does the ny method do?

##### Share on other sites
You mean the [nObjectOrder[j]]->nY?
That simply returns the objects y-value.

Fa||en_Ange| Productions

It SHOULD work.

##### Share on other sites
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

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 32
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631742
• Total Posts
3001986
×