我应该使用 UIView 和 UILabels 在 SKView 上显示游戏详细信息吗
Should I use UIView's and UILabels to display Game details on top of SKView
我是游戏开发的新手,想知道在屏幕上显示游戏数据的最佳方法是什么。
我有一个无尽的奔跑者,精灵在其中收集宝石,我希望在屏幕上显示总数。我正在考虑在 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...
}
}
我是游戏开发的新手,想知道在屏幕上显示游戏数据的最佳方法是什么。
我有一个无尽的奔跑者,精灵在其中收集宝石,我希望在屏幕上显示总数。我正在考虑在 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...
}
}