Noob in XCode needing help: Inheritance and Polymorphism

Posts: 1
Joined: 2013.11
Post: #1
Hey! So I'm sorry to ask such a basic question (and mods, if this is in the wrong area, please move it), but I typically code in Java and am having some issues transitioning to XCode. One question I have is this:

So I'm developing a game involving sprites, but I want there to be many types of sprites that each have their own AI, private variables (porperties?), arraylists (NSMutableArrays?), etc, but don't know what class to extend or how to extend it. For instance, if I want a SKSpriteNode that is a pirate and one that is a fish, how do I set up the code such that I can initialize them as separate children?

Thanks for your help! Sorry this is so basic.
Quote this message in a reply
Posts: 387
Joined: 2002.08
Post: #2
Hi Harpoon,
I'm not the best person to answer, but maybe I can kick off a couple more responses.

In general, the proper pattern to follow here in Objective-C would be to have a class of GameObject that you can subclass to be specific types of objects, such as a fish or pirate.

You can have GameObject be a subclass of SKSpriteNode, and then add custom properties to it that work well with your game logic.

I'd recommend putting some kind of prefix before your class name, so perhaps HSGameSpriteNode, or HSSpriteNode, implying that you've taken an SKSpriteNode but added some HarpoonStudios-specific code to it, to help with whatever you need to do in the game.

Good luck!

KB Productions, Car Care for iPhone/iPod Touch
All too often, art is simply the loss of practicality.
Quote this message in a reply
Posts: 456
Joined: 2003.08
Post: #3
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Hey noob developer here TheGTS 4 4,970 May 14, 2014 05:23 PM
Last Post: TheGTS
  A total noob question..Need same answers !!! skobot22 3 6,182 May 29, 2012 09:45 PM
Last Post: Macmenace
  Many questions tonight. Tricky inheritance issue kendric 0 2,846 Mar 9, 2009 08:40 PM
Last Post: kendric