0

How do I write NSArray values to utilize a variable similar to this NSString:

Levelname=[NSString stringWithFormat:@"Background1Level%d.png",LevelNO];
    [backgroundimagview setImage:[UIImage imageNamed:Levelname]];

Here is the code block I need to convert to use the LevelNO variable:

        [character setImage:[UIImage imageNamed:@"character1_09.png"]];
        character.animationImages=[NSArray arrayWithObjects:
                              [UIImage imageNamed:@"character1_01.png"],
                              [UIImage imageNamed:@"character1_02.png"],
                              [UIImage imageNamed:@"character1_03.png"],
                              [UIImage imageNamed:@"character1_04.png"],nil ];
1
  • If The answer is correct please accept it so that other people can use it in the future Commented Mar 6, 2013 at 23:50

1 Answer 1

4

loop through them with an integer and instead of "LevelNO" use that integer. Something like this:

for(int i = 0; i < {number of levels here}, i++)
{
  Levelname=[NSString stringWithFormat:@"Background1Level%d.png",i];
  [myArray addObject:[UIImage imageWithName:Levelname];
}

Make sure to keep an array and replace myArray

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.