Question

Hi can someone explain to me the use of interfaces in the sprite kit adventure game, from apple.

They have a main class called APAMultiplayerLayeredCharacterScene and another class which inherits from this called APAAdventureScene.

In the APAMultiplayerLayeredCharacterScene They have a bunch of properties in the .h that look like this:

@interface APAMultiplayerLayeredCharacterScene : SKScene

@property (nonatomic, readonly) NSArray *players;               // array of player objects or NSNull for no player
@property (nonatomic, readonly) APAPlayer *defaultPlayer;       // player '1' controlled by keyboard/touch
@property (nonatomic, readonly) SKNode *world;                  // root node to which all game renderables are attached
@property (nonatomic) CGPoint defaultSpawnPoint;                // the point at which heroes are spawned
@property (nonatomic) BOOL worldMovedForUpdate;                 // indicates the world moved before or during the current update

@property (nonatomic, readonly) NSArray *heroes;                // all heroes in the game

Now in the .m file they have this:

@interface APAMultiplayerLayeredCharacterScene ()
@property (nonatomic) NSMutableArray *players;          // array of player objects or NSNull for no player
@property (nonatomic) APAPlayer *defaultPlayer;         // player '1' controlled by keyboard/touch
@property (nonatomic) SKNode *world;                    // root node to which all game renderables are attached
@property (nonatomic) NSMutableArray *layers;           // different layer nodes within the world
@property (nonatomic, readwrite) NSMutableArray *heroes;// our fearless adventurers

@property (nonatomic) NSArray *hudAvatars;              // keep track of the various nodes for the HUD
@property (nonatomic) NSArray *hudLabels;               // - there are always 'kNumPlayers' instances in each array
@property (nonatomic) NSArray *hudScores;
@property (nonatomic) NSArray *hudLifeHeartArrays;      // an array of NSArrays of life hearts

@property (nonatomic) NSTimeInterval lastUpdateTimeInterval; // the previous update: loop time interval
@end

@implementation APAMultiplayerLayeredCharacterScene

Can someone explain to me the uses of both of these sets of properties, which properties are used by the class and which ones can be accessed from classes that inherit from it?

I'm confused as to how it works as none of these properties are synthesised so I don't understand why they are being used. I've never used them in this way before.

Thanks a lot!

Était-ce utile?

La solution

Can someone explain to me the uses of both of these sets of properties, which properties are used by the class and which ones can be accessed from classes that inherit from it?

This is called a "class extension". The properties in the interface (.h) are allowed to be modified by other classes. The properties in the implementation (.m) you should ignore - they are implementation details.

More info on class extensions here.

none of these properties are synthesised so I don't understand why they are being used

Properties don't need to be synthesized any more. If you leave out the @sythnesize statement, it's added for you at compile time. Here's a good blog post on this topic.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top