Cocos2d iphone Cocos2d Kobold2d ReordChildren不';我不能正确地点餐

Cocos2d iphone Cocos2d Kobold2d ReordChildren不';我不能正确地点餐,cocos2d-iphone,ccsprite,kobold2d,Cocos2d Iphone,Ccsprite,Kobold2d,我在Kobold2d-Cocos2d中遇到了一个关于CCSprite对象分层的问题 我所有的代码都可以正常工作,除了数组中的某个瓷砖(CCSprite)应该总是在顶部。该代码有一个对ccsprite(Tile)的引用数组,并沿着所有的Tile相互交换它们。所以元素0和1切换(在数组中和屏幕上使用moveTo),然后新元素1和2切换,然后新元素2和3切换等等 这个想法是在链的开始处的瓷砖跳到线的前面 我总是希望第一块瓷砖保持在顶部,但事实并非如此。它只是有时会这样做(当它位于屏幕上其他磁贴的上方时

我在Kobold2d-Cocos2d中遇到了一个关于CCSprite对象分层的问题

我所有的代码都可以正常工作,除了数组中的某个瓷砖(CCSprite)应该总是在顶部。该代码有一个对ccsprite(Tile)的引用数组,并沿着所有的Tile相互交换它们。所以元素0和1切换(在数组中和屏幕上使用moveTo),然后新元素1和2切换,然后新元素2和3切换等等

这个想法是在链的开始处的瓷砖跳到线的前面

我总是希望第一块瓷砖保持在顶部,但事实并非如此。它只是有时会这样做(当它位于屏幕上其他磁贴的上方时,它会在屏幕上切换位置,这意味着它是后来添加的)

下面是有问题的场景代码:

//reference first CCSprite in array -works
Tile *firstTile = [tileArray objectAtIndex:(int)[[[selTracker oldSelectionArray] objectAtIndex:0]element]];

//How much time should be spend leapfrogging each two tiles broken up over 1 second.
    float intervalTime = .75/(float)[[selTracker oldSelectionArray] count];

    //Will use this to count each tile set we leapfrog
    float currentPass = 0;

    //TODO: destroy this wrapper class that holds number, use NSNumber. Fine for now.
     SimpCoord *lastCord;


    //Make moving sprite higher than all others. DOESN'T WORK?
    [self reorderChild:firstTile z:100];

    //Loop through all the tiles that were selected
    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; 

    }
`
通过实际交换两个tile的方式调用以下代码(我排除了多个参数所需的函数包装中间人):

(为了便于理解,而不是使用2d数组来保存我的所有瓷砖,我只需每行绘制10个,因此使用TileCordsByElement方法-但这并不重要)

好的

我知道我正在做的一些事情并不是很有效率,如果它与我无关,我真的不想把重点放在它们上。这对我来说只是一个学习练习——我真的不明白为什么原始瓷砖不会保持在顶部

我已经尝试了我可能找到的所有资源或示例来寻找答案(示例包括代码、在线教程、我买的糟糕的书、随机相关的stackoverflow文章),但我什么也没有得到:\

如果有关系,这就是我最初将精灵添加到场景中的方式:

//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];
}
//设置CCSpriteBatchNode以加载图像的pList/pngs
[[CCSpriteFrameCache sharedSpriteFrameCache]
addSpriteFramesWithFile:@“zAtl_BasicImages_64.plist”];
nodeBasicImages=[CCSpriteBatchNode batchNodeWithFile:@“zAtl_BasicImages_64.png”容量:100];
//初始化用于跟踪场景中平铺的阵列
TilerRay=[[NSMutableArray alloc]init];

对于(int i=0;i我没有将精灵添加到我的图层,而是添加到图像节点,因为我使用的是精灵图集。所以我尝试访问甚至不存在的精灵。-我是一个新用户,所以必须等待8个小时才能关闭。平和。为什么它没有抛出错误,我永远不知道。

我没有将精灵添加到我的图层,而是添加到图像节点e因为我使用的是精灵地图册。所以我尝试访问甚至不存在的精灵。-我是一个新用户,所以必须等待8个小时才能关闭。和平。为什么它没有抛出一个错误,我永远也不知道。为什么你不简单地更新精灵的zOrder属性?较高的zOrder会将节点绘制在较低zOrder的其他节点之上。要e吗确保一个特定的瓷砖总是最高的,给它一个非常高的等级。我在你上面的评论中回答了这个问题。
//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];
}