我正在为我的游戏使用SpriteKit框架。我正在显示菜单,现在我需要查看是否单击了SKLabelNode。我怎么能这样做?
SKLabelNode *startGameLabel = [SKLabelNode labelNodeWithFontNamed:@"Marker Felt"];
startGameLabel.text = @"Start";
startGameLabel.position = CGPointMake(0, -40);
[gameOverScreenBackground addChild:startGameLabel];
答案 0 :(得分:1)
这是一个如何做的例子......
#import "MyScene.h"
@implementation MyScene
{
SKLabelNode *startGameLabel;
}
-(id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size])
{
startGameLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
startGameLabel.fontSize = 40.0;
startGameLabel.text = @"Start";
startGameLabel.name = @"start";
startGameLabel.position = CGPointMake(200,200);
[self addChild:startGameLabel];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self.scene];
if (CGRectContainsPoint(startGameLabel.frame, touchLocation))
{
NSLog(@"stop touching me!");
}
}
-(void)update:(CFTimeInterval)currentTime
{
//
}
@end