我一直在关注SpriteKit的教程,对于我的生活,我不知道这个方法来自哪里。在StartGameLayer中,我完整地使用了这段代码:
#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* )
方法在哪里设置?在帮助文件中,它表示它已在此文件中声明,但这是我看到它的唯一实例,它只是让我最简单的一点就是如何创建此方法。