0

So what I am trying to do is use a holder (the SKSpriteNode *sprite) and load from a set of three sprites: coral water base.

What I intend to do is based on previously created NSMutableArrays, draw that particular texture at positions across the iPad screen so that, for instance:

at position 1,6: water at position 5,18: coral.

The problem that is happening is that it is only drawing one texture and no others. Is there any fix for this? Should I go about this a different way?

// Load the sprites
SKSpriteNode *sprite;

TerrainType ter;

for (int i = 0; i < numberOfRows; i++)
{
    innerArray = [terrainArray objectAtIndex:i];

    for (int j = 0; j < rowLength; j++)
    {
        ter = [[innerArray objectAtIndex:j] intValue];
        sprite = [[SKSpriteNode alloc] init];

        switch (ter)
        {
            case base1:
                sprite = [SKSpriteNode spriteNodeWithImageNamed:@"MidBase"];
                break;

            case base2:
                sprite = [SKSpriteNode spriteNodeWithImageNamed:@"MidBase"];
                break;

            case coral:
                sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Coral"];
                break;

            default:
                sprite = [SKSpriteNode spriteNodeWithImageNamed:@"PureWater"];
                break;

        }
        sprite.position = CGPointMake(rowLength + width30, numberOfRows + height30);
        [self addChild:sprite];
    }
}

1 Answers1

1

It looks like you are loading all the Sprites in the same position:

sprite.position = CGPointMake(rowLength + width30, numberOfRows + height30);

You are creating an identical CGPointMake for all of them (not sure what width30 and height30 are but they don't seem to change/increase anywhere in your code). If the Sprites are also of the same size they will be overlaid one up on the other. And you end up seeing only the last one loaded.

I assume you want to make this position be related to the two for loops indexes j and i in some way.

tanz
  • 2,557
  • 20
  • 31