Futile.AddStageAtIndex C# (CSharp) Method

AddStageAtIndex() public static method

public static AddStageAtIndex ( FStage, stageToAdd, int newIndex ) : void
stageToAdd FStage,
newIndex int
return void
    public static void AddStageAtIndex(FStage stageToAdd, int newIndex)
    {
        int stageIndex = _stages.IndexOf(stageToAdd);

        if(newIndex > _stages.Count) //if it's past the end, make it at the end
        {
            newIndex = _stages.Count;
        }

        if(stageIndex == newIndex) return; //if it's already at the right index, just leave it there

        if(stageIndex == -1) //add it if it's not in the stages already
        {
            stageToAdd.HandleAddedToFutile();

            _stages.Insert(newIndex, stageToAdd);
        }
        else //if stage is already in the stages, move it to the desired index
        {
            _stages.RemoveAt(stageIndex);

            if(stageIndex < newIndex)
            {
                _stages.Insert(newIndex-1, stageToAdd); //gotta subtract 1 to account for it moving in the order
            }
            else
            {
                _stages.Insert(newIndex, stageToAdd);
            }
        }

        UpdateStageIndices();
    }

Usage Example

Beispiel #1
0
 private static void AddBackground()
 {
     if (Futile.instance != null && Futile.instance.enabled == true)
     {
         if (tBackground == null)
         {
             tBackground        = new FSprite("blank");
             tBackground.color  = Color.grey;
             tBackground.width  = Futile.screen.width;
             tBackground.height = Futile.screen.height;
             tBackgroundStage.AddChild(tBackground);
             Futile.AddStageAtIndex(tBackgroundStage, 0);
         }
     }
 }