Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662636
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:26:20+00:00 2026-05-19T01:26:20+00:00

I have a question regarding an iPhone game I’m developing. At the moment, below

  • 0

I have a question regarding an iPhone game I’m developing. At the moment, below is the code I’m using to currently I loop through my multidimensional array and position bricks accordingly on my scene. Instead of having multiple two dimensional arrays within my code as per the following (gameLevel1).

Ideally, I’d like to read from a text file within my project and loop through the values in that instead.

Please take into account that I’d like to have more than one level within my game (possibly 20) so my text file would have to have some sort of separator line item to determine what level I want to render.

I was then thinking of having some sort of method that I call and that method would take the level number I’m interested in rendering.

e.g. Method to call level based on separator?

-(void)renderLevel:(NSString *)levelNumber;

Method usage:

[self renderLevel:@"#LEVEL_ONE"];

e.g. Text file example?

#LEVEL_ONE#
0,0,0,0,0,0,0,0,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,0
0,0,0,0,0,0,0,0,0
#LEVEL_TWO#
1,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1
0,1,1,1,1,1,1,1,0
1,1,1,1,1,1,1,1,1
0,1,1,1,1,1,1,1,0
1,1,1,1,1,1,1,1,1
0,1,1,1,1,1,1,1,0
1,1,1,1,1,1,1,1,1
0,1,1,1,1,1,1,1,0
1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,1

Code that I’m currently using:

int gameLevel[17][9] = {
  { 0,0,0,0,0,0,0,0,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,1,1,1,1,1,1,1,0 },
  { 0,0,0,0,0,0,0,0,0 }
};

for (int row=0; row < 17; row++)
{
  for (int col=0; col < 9; col++)
  {
    thisBrickValue = gameLevel[row][col];
    xOffset = 35 * floor(col);
    yOffset = 22 * floor(row);

    switch (thisBrickValue)
    {
      case 0: brick = [[CCSprite spriteWithFile:@"block0.png"] autorelease]; break;
      case 1: brick = [[CCSprite spriteWithFile:@"block1.png"] autorelease]; break;
    }
    brick.position = ccp(xOffset, yOffset);
    [self addChild:brick];
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:26:21+00:00Added an answer on May 19, 2026 at 1:26 am

    It looks like you want to be parsing a file, which is answered for Objective-C in this question: How do I parse a text file in Objective-C?

    For your case, I think you’d want to determine whether each line is a “#Level X#” line or a row of blocks. Then you could use the same componentsSeparatedByString function (passing @”,” instead of @”\n”) to give you an array of all the blocks in a line to add to an NSMutableArray of your own creation.

    As a personal design choice, I’d rather have each level in a separate file. That allows future addition/update of levels without having to update the file containing all existing levels.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding iphone development. i am building an app for iphone
I have a question here regarding iPhone app submission. I have a free application
I have a question regarding app submission. Situation: We have an iPhone Developer account
I have a quick question regarding tracking touches on the iPhone and I seem
Background: I'm developing a game for the iPhone/iPad using cocos2d-iphone. Our engine provides the
I need some help for iphone application,i have some question regarding the new iOS
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a question regarding handling errors in a J2EE application. Our current application
I'm writing a small webapp in Grails and I have the following question regarding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.