0

嗨,有人可以向我解释一下苹果的精灵套件冒险游戏中接口的使用。

他们有一个名为的主类APAMultiplayerLayeredCharacterScene和另一个从该类继承的类APAAdventureScene

他们在APAMultiplayerLayeredCharacterScene.h 中有一堆属性,如下所示:

@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

现在在 .m 文件中,他们有这个:

@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

有人可以向我解释这两组属性的用途,类使用哪些属性以及可以从继承自它的类中访问哪些属性?

我对它的工作原理感到困惑,因为这些属性都没有被合成,所以我不明白为什么要使用它们。我以前从未以这种方式使用过它们。

非常感谢!

4

1 回答 1

1

有人可以向我解释这两组属性的用途,类使用哪些属性以及可以从继承自它的类中访问哪些属性?

这称为“类扩展”。接口(.h)中的属性允许被其他类修改。您应该忽略的实现(.m)中的属性- 它们是实现细节。

更多关于类扩展的信息在这里

这些属性都不是合成的,所以我不明白为什么要使用它们

属性不再需要合成。如果您省略了@sythnesize 语句,它会在编译时为您添加。 这是关于这个主题的一篇很好的博客文章。

于 2013-11-28T00:37:22.513 回答