Cocos2d Kobold2d reorderChildren doesn't order CCSprites properly
===

I am having an issue in Kobold2d-Cocos2d regarding the layering of CCSprite objects.

All of my code works fine, except that a certain tile (a CCSprite), held in an array, is supposed to always be on top. The code has an array of references to CCSprites (Tile) and goes along all the tiles swapping them with each other. So element 0 and 1 switch (in the array and on screen using a moveTo), then the new element 1 and 2 switch, then the new element 2 and 3 switch etc...

The idea is the Tile at the start of the chain leapfrogs to the front of the line!

I always want that first tile to stay on top, but it isn't. It only does sometimes (when it's above the other Tile it's switching places with on the screen, implying it was added later)

Here's the CCScene code in question:

`
Tile *firstTile = [tileArray objectAtIndex:(int)[[[selTracker oldSelectionArray] objectAtIndex:0]element]];
    
    //How much time should be spend moving over each tile broken up over 1 second.
    float intervalTime = .75/(float)[[selTracker oldSelectionArray] count];
    
    //Will use this to determine how long to wait for each tile to refresh that is destroyed.
    float currentPass = 0;
    
    SimpCoord *lastCord;
    
    
    //Make moving sprite higher than all others.
    [self reorderChild:firstTile z:100];
    
    for (SimpCoord *coord in [selTracker oldSelectionArray])
    {                   
        if (lastCord)
        {
            //Queue each tile to leapfrog with our moving tile 
            if ([self respondsToSelector:@selector(switchTilesFuncWrapper:)])
            {
                NSArray *argArray = [NSArray arrayWithObjects:
                                     [NSNumber numberWithInt:[lastCord element]],
                                     [NSNumber numberWithInt:[coord element]], 
                                     [NSNumber numberWithFloat:(intervalTime)], nil];
                [self performSelector:@selector(switchTilesFuncWrapper:) withObject:argArray afterDelay:((currentPass) * intervalTime)];
            }
            currentPass++; 
        }
        lastCord = coord; 

    }
`

That calls the following code by the way that actually swaps the two Tiles (I excluded the function wrapper middleman I needed for multiple arguments):

(In case it makes it easier to understand, rather than use a 2d array to hold all my tiles I just only draw 10 per line, hence the tileCoordsByElement method - but that shouldn't be important)

    //
    // Switch two tiles on the screen and in the holder array
    // onlySwitchArray pass in true to only swap tiles in organization array
    // but provide no animation.
    - (void) switchTiles:(NSNumber*)elePosVal secPos:(NSNumber*)elePos2Val timeToSwitch:(NSNumber*)time
    {
        float switchTime = [time floatValue];
        int elePos = [elePosVal intValue];
        int elePos2 = [elePos2Val intValue];
        
        Tile *tmpTile = [tileArray objectAtIndex:elePos];
        Tile *tmpTile2 = [tileArray objectAtIndex:elePos2];
        
        //Move actual tiles on screen
        //Move Tile is elePos (1) to elePos2
        int curCol = 0;
        int curRow = 0;
        
        [self tileCoordsByElement:elePos2 x:&curRow y:&curCol];
        CCSequence *tmpTile1_Seq = [CCSequence actions:
                                    [CCMoveTo actionWithDuration:switchTime position:ccp((curRow-1)*tmpTile.width + tmpTile.width/2,
                                                                                         (curCol-1)*tmpTile.height + tmpTile.height/2)], nil];
        [tmpTile runAction:[CCRepeat actionWithAction:tmpTile1_Seq times:1]];  
        
        //Move Tile that is elePos2 to elePos(1)
        [self tileCoordsByElement:elePos x:&curRow y:&curCol];
        CCSequence *tmpTile1_Seq2 = [CCSequence actions:
                                     [CCMoveTo actionWithDuration:switchTime position:ccp((curRow-1)*tmpTile.width + tmpTile.width/2,
                                                                                          (curCol-1)*tmpTile.height + tmpTile.height/2)], nil];
        [tmpTile2 runAction:[CCRepeat actionWithAction:tmpTile1_Seq2 times:1]];
        
        //Swap tiles in array second
        [tileArray replaceObjectAtIndex:elePos withObject:tmpTile2];
        [tileArray replaceObjectAtIndex:elePos2 withObject:tmpTile];
    
    }




Alright.

I'm aware some things I'm doing aren't exactly efficient and if it's not relevant I don't really want to focus to heavily on them. This is just a learning exercise for me - I just honestly don't understand why the origional Tile won't stay on top. 


I've tried every resource or example I possibly can find for answers (sample included code, tutorials online, terrible book I bought, random somewhat related stackoverflow articles) and I'm getting nothing :\

In case it matters this is how I origionally added my sprites to the scene:

    //Set up A CCSpriteBatchNode to load in pList/pngs of images
    [[CCSpriteFrameCache sharedSpriteFrameCache]
     addSpriteFramesWithFile:@"zAtl_BasicImages_64.plist"];
    nodeBasicImages = [CCSpriteBatchNode batchNodeWithFile:@"zAtl_BasicImages_64.png" capacity:100];
    
    //Initialize array used to track tiles in scene
    tileArray = [[NSMutableArray alloc] init];
    for (int i = 0; i<100; i++)
    {
        Tile *tmpTile = [[Tile alloc] init];
        [tileArray addObject:tmpTile];
        [self reorderChild:tmpTile z:-1];
    }