Hi again!
I continued my work on the sprite priority functions and, as it may interest some people who might run into the same problems than me, I'll explain what I've done. By the way, when I'm done, maybe bluemonkmn could make my code file available ont the sgdk2 website for others to use!

I worked on another "sprite priority function" that allows the insertion of a sprite right on the of another specfied one.
Example:
My collection of sprites contains
-Sprite1
-Sprite2
-Sprite3
-Sprite4
This functions allows to insert a Sprite 4 over Sprite1 without having to make multiple uses of the SwitchSpritePriority function.
With SwitchSpritePriority, you would have to make 2 uses of the (switch Sprite4 with Sprite3, then switch Sprite4 with Sprite2).
With InsertSpriteOnSprite, you just specify which sprite must be moved (Sprite4) and which is the sprite that is supposed to be right under it (Sprite1)
Both should give a final result of:
-Sprite1
-Sprite4
-Sprite2
-Sprite3
And, I would really like to test these 2 functions, but they both get the same error that I specified before. Which is:
Library\Projects\TKDremake\SpritePriorityFunctions.cs(26,10) : error CS0200: Property or indexer 'SpriteCollection.this[int]' cannot be assigned to -- it is read only
Library\Projects\TKDremake\SpritePriorityFunctions.cs(27,10) : error CS0200: Property or indexer 'SpriteCollection.this[int]' cannot be assigned to -- it is read only
Here is the code of my custom class:
Could someone help me out?
using System.ComponentModel;
namespace CustomObjects
{
// added by Vincent
public class SpritePriorityFunctions
{
[Description("Switch the priority of sprites")]
public void SwitchSpritesPriority(SpriteBase FirstSprite, SpriteBase SecondSprite)
{
int i;
int iFirstSprite;
int iSecondSprite;
for (i = 0; i < FirstSprite.ParentLayer.m_Sprites.Count; i++)
{
if (FirstSprite.ParentLayer.m_Sprites[i] == FirstSprite)
{
iFirstSprite = i;
}
if (FirstSprite.ParentLayer.m_Sprites[i] == SecondSprite)
{
iSecondSprite = i;
}
}
SpriteBase tempSprite = FirstSprite.ParentLayer.m_Sprites[iFirstSprite];
FirstSprite.ParentLayer.m_Sprites[iFirstSprite] = FirstSprite.ParentLayer.m_Sprites[iSecondSprite];
FirstSprite.ParentLayer.m_Sprites[iSecondSprite] = tempSprite;
}
[Description("Inserts a sprite right on top of another specified one")]
public void InsertSpriteOnSprite(SpriteBase SpriteToInsert, SpriteBase SpriteRightUnder)
{
int i;
int iSpriteToInsert = -1;
int iSpriteRightUnder = -1;
//Detecting where are the sprites in the list
for (i = 0; i < SpriteRightUnder.ParentLayer.m_Sprites.Count; i++)
{
if (SpriteRightUnder.ParentLayer.m_Sprites[i] == SpriteToInsert)
{
iSpriteToInsert = i;
}
if (SpriteRightUnder.ParentLayer.m_Sprites[i] == SpriteRightUnder)
{
iSpriteRightUnder = i;
}
}
//Don'tdo anything if the values are not correct
if (iSpriteToInsert != -1 && iSpriteRightUnder != -1)
{
//Don't do anything if everything is already ok
if (iSpriteRightUnder != iSpriteToInsert - 1)
{
//We must change the list from the iSpriteToInsert index to the iSpriteRightUnder index
if (iSpriteToInsert < iSpriteRightUnder)
{
for (i = iSpriteToInsert; i < iSpriteRightUnder; i++)
{
SpriteRightUnder.ParentLayer.m_Sprites[i] = SpriteRightUnder.ParentLayer.m_Sprites[i + 1];
}
SpriteRightUnder.ParentLayer.m_Sprites[iSpriteRightUnder] = SpriteToInsert;
}
//We must change the list from the iSpriteRightUnder index to the iSpriteToInsert index
if (iSpriteToInsert < iSpriteRightUnder)
{
for (i = iSpriteToInsert; i > iSpriteRightUnder; i--)
{
SpriteRightUnder.ParentLayer.m_Sprites[i] = SpriteRightUnder.ParentLayer.m_Sprites[i - 1];
}
SpriteRightUnder.ParentLayer.m_Sprites[iSpriteRightUnder + 1] = SpriteToInsert;
}
}
}
}
}
}
To bluemonkmn:
I read the code in the SpriteCollection file, and I realized that playing with the order of the sprites in the m_Sprites collection could cause some problems with the fact that the sprites considered static and the sprites considered dynamic may get messed up. Maybe it would be interesting to alter this system in a future release. Or maybe you have a better way to handle this situation? I am all ears!

By the way, I'm having a great time using SGDK2!
