我是游戏开发新手,想知道在屏幕上显示游戏数据的最佳方法是什么。
我有一个无尽的运行者,其中 Sprite 收集 gem ,我希望总数显示在屏幕上。我正在考虑在 SKView 上方放置一个带有 UILabel 的 UIView ,并在每次触摸后更新标签。 我还希望在最后出现一个游戏结束屏幕,并且也在考虑使用 UIView 创建它。
这是最好的方法还是所有数据都应该保存在 SKView 本身中?
希望这是有道理的。
最佳答案
虽然我不认为在 SpriteKit 应用程序中使用 UIKit 组件有什么问题,但我建议尽可能使用 SpriteKit 自己的组件。
对于文本,我建议使用 SKLabelNode而不是 UILabel。
此外,对于按钮和其他 GUI 元素,我认为 SKSpriteNodes 就足够了。
简单的功能按钮示例:
SKSpriteNode *fireNode = [SKSpriteNode spriteNodeWithImageNamed:@"fireButton.png"];
fireNode.position = CGPointMake(fireButtonX,fireButtonY);
fireNode.name = @"fireButtonNode";//how the node is identified later
处理触摸:
//handle touch events
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
//if fire button touched, bring the rain
if ([node.name isEqualToString:@"fireButtonNode"]) {
//do whatever...
}
}
关于ios - 我应该使用 UIView 和 UILabels 在 SKView 之上显示游戏详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674284/