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

  • SEARCH
  • Home
  • 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 1003333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:57:52+00:00 2026-05-16T07:57:52+00:00

I’m working on a basic iPhone game that requires a single-screen tilemap. Nothing difficult

  • 0

I’m working on a basic iPhone game that requires a single-screen tilemap. Nothing difficult there. I come from a C background, so my current solution looks a bit like this:

typedef struct _Tile {
    NSString *type;
} Tile;

@interface Map {
    Tile mapData[MAP_TILE_MAX_X][MAP_TILE_MAX_Y];
}

This works fine, but I’m wondering if there’s a slightly more ‘correct’ way to handle things via Objective-C. Here’s how I see the situation going if I were to adopt an Objective-C approach: I’d create a base Tile class to hold basic tile properties, which I could then subclass for specific tile types (@interface Water : Tile {}, for example). This would allow me to also have Tile-specific logic. For instance: the Tile class could have a ‘think’ method which would execute any necessary logic. In my Water subclass, this may involve creating a ripple effect if the player were submerged.

My questions then:

  1. Is it acceptable to use C structs in this situation? If not, am I on the right track with regards to my Obj-C approach?
  2. If I were to create a base Tile class and use subclasses for specific Tile types, how would I dynamically instantiate each Tile subclass (given that I have an NSString containing the type ‘water’, I would need to instantiate the Water class).
  • 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-16T07:57:52+00:00Added an answer on May 16, 2026 at 7:57 am

    The second part of your question is easier to address, so I will approach that first.

    Dynamically instantiating an object of an arbitrary class at runtime can be done using NSClassFromString()

    Assuming your WaterTile is a subclass of UIView (which seems to make sense since it is likely to to be drawn on the screen)

    UIView *newTile = [[NSClassFromString([NSString stringWithFormat:@"%@TileView", [@"water" capitalizedString]]) alloc] init];
    

    Now for the first part.

    Given that the tile is something that you want to draw on screen you will benefit from all of the OO goodness by inheriting from UIView which will respond to touch events and have methods needed for positioning and drawing. This is the major advantage over using a struct for your tiles.

    Chances are, the abstract Tile class that you are thinking of won’t really be needed as most of the properties and methods provided by UIView which leads me to think that you may want to define a Tile @protocol instead.

    @protocol TileViewDrawing 
    - (void)drawThinking;
    @end
    
    @interface WaterTileView : UIView <TileViewDrawing>
    @end
    
    @implementation WaterTileView
    -(void)drawThinking
    {
        // Code to show rippling effect
    }
    @end
    

    To create a 2D arrays in your Map define an NSArray (columns) of NSArrays (row)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.