ios - 我应该使用 UIView 和 UILabels 在 SKView 之上显示游戏详细信息

标签 ios objective-c skview

我是游戏开发新手,想知道在屏幕上显示游戏数据的最佳方法是什么。

我有一个无尽的运行者,其中 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/

相关文章:

android - Webkit 在 ASP.NET 3.5 页面中点击突出显示颜色,包括 ScriptManager

objective-c - 从 Objective-C 到 Swift 4 的一行代码

objective-c - 为什么我们应该分开 alloc 和 init 调用来避免 Objective-C 中的死锁?

iphone - 如何测试 IOS 设备是否具有电话功能?

ios - 来自 Swift Range 的 NSRange?

iphone - 获取整个 UITableViewCell 的宽度/框架

IOS:在 ios 中将 abs() 转换为 fabs() 时是否有机会生效

ios - UIVisualEffectView 不会模糊它是 SKView superview

ios - 如何从另一个 .swift 文件添加 Sprite ?

Swift SpriteKit 获取可见帧大小