Ios 在SpriteKit中,这种方法从何而来
我一直在学习关于SpriteKit的教程,我不知道这个方法是从哪里来的。在StartGameLayer中,我有完整的代码:Ios 在SpriteKit中,这种方法从何而来,ios,sprite-kit,skspritenode,Ios,Sprite Kit,Skspritenode,我一直在学习关于SpriteKit的教程,我不知道这个方法是从哪里来的。在StartGameLayer中,我有完整的代码: #import "StartGameLayer.h" @interface StartGameLayer() @property (nonatomic, retain) SKSpriteNode* playButton; @end @implementation StartGameLayer - (id)initWithSize:(CGSize)size {
#import "StartGameLayer.h"
@interface StartGameLayer()
@property (nonatomic, retain) SKSpriteNode* playButton;
@end
@implementation StartGameLayer
- (id)initWithSize:(CGSize)size
{
if(self = [super initWithSize:size])
{
SKSpriteNode* startGameText = [SKSpriteNode spriteNodeWithImageNamed:@"FlappyBirdText"];
startGameText.position = CGPointMake(size.width * 0.5f, size.height * 0.8f);
[self addChild:startGameText];
SKSpriteNode* playButton = [SKSpriteNode spriteNodeWithImageNamed:@"PlayButton"];
playButton.position = CGPointMake(size.width * 0.5f, size.height * 0.30f);
[self addChild:playButton];
[self setPlayButton:playButton];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
if ([_playButton containsPoint:location])
{
if([self.delegate respondsToSelector:@selector(startGameLayer:tapRecognizedOnButton:)])
{
[self.delegate startGameLayer:self tapRecognizedOnButton:StartGameLayerPlayButton];
}
}
}
@end
setPlayButton:SKSpriteNode*方法在哪里设置?在帮助文件中,它说它是在这个文件中声明的,但这是我看到的唯一一个实例,它让我对这个方法是如何创建的一点也不感兴趣。当你创建一个属性,比如playButton,你会得到一个为你创建的getter和setter方法。设置程序为setPlayButton:。如果每个属性都是读写的,那么每个属性都会有这样的效果。编写本教程的人都需要修复retain的用法,在ARC下,它应该是强大的。这不是一个问题,它们是等价的,但是如果教程作者陷入MRC的思维,逻辑结果可能是在弱更合适的地方使用赋值,它们是不等价的。我以前看过太多次了。