0

I'm using an array to keep track of all the tiles in my game and on a touch call this function -(void)moveTilesDown which is supposed to loop through all the tiles and find where there is an empty space, then move the tile above it down one spot. On the first touch everything works fine and it moves the appropriate tiles down, but on consecutive touches it moves the Entire screen down including 2 SKLabelNodes which have nothing to do with the array and should not be affected in any way. I don't know if I am somehow moving the entire screen down or moving each node individually. I apologize if the question is somewhat unclear, but I have absolutely no idea what is going on and therefore really don't know how to pose the question. Any help would be Greatly appreciated.

Here is my code for the moveTilesDown:

-(void)moveTilesDown {

int i = 0;
for (i = 0; i < 162; i++) {
    if (i % 9 == 0) {
        NSLog(@"skipping tile %d b/c it's on bottom", i);
    }else {

        if ([[idArray objectAtIndex:(i - 1)] isEqualToString:@"none"] && ![[idArray objectAtIndex:i] isEqualToString:@"none"]) {

            [idArray replaceObjectAtIndex:(i - 1) withObject:[idArray objectAtIndex:i]];
            [idArray replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"none"]];
            tileWasMoved = YES;

            CGPoint locationOfIndex = CGPointMake((i % 9) * 30, (i / 9) * 30);
            SKNode *movingNode = [self nodeAtPoint:locationOfIndex];
            SKAction *moveNodeDown = [SKAction moveByX:-kTileSize.width y:0.0 duration:1.0];
            [movingNode runAction: moveNodeDown];
        }
    }
}
}
user2975241
  • 73
  • 2
  • 7
  • Put all the tiles in the same node and move that node with one action if you want all child nodes to follow uniformly. That approach is far better (and faster, more efficient) than running an action on each tile. – CodeSmile Feb 24 '14 at 23:01
  • I don't really want every node to move. I only want nodes with an empty space below them to "fall" down and leave the rest alone. Unfortunately my function is somehow affecting every nodes instead of just the ones I want – user2975241 Feb 25 '14 at 06:08

0 Answers0