- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有一个关于 Sprite Kit
中 universal game assets 和 absolute positioning 的问题(iOS 8 岁以上)。
我将尝试通过以下示例来展示我的问题:
想象一个 2D top down 游戏,其中有一个代表房子的 SKSpriteNode
。一个房子有多个子 SKSpriteNode
,代表椅子、书 table 、沙发等。
我有 3 个版本的房屋 Assets :
1x - 200 x 200px
(非视网膜 iPad),2x - 400 x 400px
(视网膜 iPhone 和 iPad),3x - 600 x 600px
(iPhone 6 Plus)。重要:子节点(椅子、 table 等)的位置在 .plist 文件 中定义。像这样(JSON 表示):
children: [
{
position = {20,20};
},
...
]
由于位置是以点而非像素为单位定义的,因此所有内容都会根据设备屏幕比例按预期定位。对于 1x
设备,位置保持在 {20,20}
,对于 2x
,位置是 {40,40}
并且对于 3x
,位置是 {60,60}
。
问题:
问题是 200x200px
和 400x400px
Assets 对于 iPad 设备来说太小了,以便在所有设备上实现相似的外观.
问题:
How to successfully present/import assets in a way that would enable me to achieve similar (if not the same) look and feel on all devices/screen sizes without breaking child nodes positioning?
我的看法:
采取 1:
我可以简单地使用非视网膜 iPad 设备上的现有 400x400px
Assets 和视网膜 iPad 设备上的 600x600px
Assets 作为房屋节点,但子节点的定位会变得 splinter 。这是因为子位置值不会改变,对于 iPad 设备仍将分别为 {20,20}
和 {40,40}
,而 Assets 将是大。这会产生相对于房屋节点的不准确的子位置。
拍摄 2:
我还可以缩放 SKScene
大小(缩放效果),同时分别为 iPad 设备使用正常的 200x200px
和 400x400px
大小的资源。这有效并且它使子节点定位工作,但场景/ Assets 的渲染质量不如应有的好。此外,这感觉像是一种黑客攻击,我们不希望这样。
第 3 次:
我还可以为 iPad 设备使用两倍大的 Assets ,并在运行时将子节点位置加倍。在这种情况下,我将为非视网膜 iPad 设备使用 400x400px
Assets ,为视网膜 iPad 设备使用新的 800x800px
Assets 。虽然这看起来很棒并且可以保持子节点定位正常工作,但它似乎是一个非常大的 hack 在运行时修复子节点位置:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
position.x *= 2.0f;
position.y *= 2.0f;
}
感谢您花时间阅读问题!
最佳答案
I could simply use the existing 400x400px assets on Non-retina iPad devices and 600x600px assets on Retina iPad devices for the house node but the positioning of a child nodes would become broken. This is because the child position value wouldn't change and would still be {20,20} and {40,40} for iPad devices respectively, while the assets would be bigger. This would yield inaccurate child positions relative to the house node.
您可以简单地将房屋节点(而不是场景)缩放到更大的尺寸。您需要做的就是将您房子的比例设置为在更大的设备上看起来不错的值。事实上,我们可以想出一个根据屏幕大小设置比例的公式,而不是检查 iPad。类似下面的代码应该可以工作。请注意,它假设您的房子在 iPhone 4 上完美定位,并且它会始终缩放到所有更大的屏幕。请注意,您确实可以选择任意尺寸作为基本情况,但选择最小的屏幕并按比例放大是最简单的。请务必提供更大的纹理,以便纹理在缩放时不会变得模糊。
[house setScale:self.scene.size.width/320.0];
或
您可以使用两个节点。用于保存“实际”位置的根节点,然后是用于显示图像的图像节点子节点。这将允许您将位置数据与显示的内容分开。您可以根据需要调整子图像节点的大小和位置,而不会弄乱根节点的实际位置。您甚至可以在 JSON 中包含这个额外的图像节点数据。
I could also scale the SKScene size (zoom effect) while using the normal 200x200px and 400x400px sized assets for iPad devices respectively. This works and it keeps the child nodes positioning working but the rendered quality of the scene/assets is not good as it should be. Also, this feels like a hack and we don't want that.
如果您的应用程序能够以某种方式处理不同的宽高比,那么此选项绝对有效。例如,如果场景的缩放比例大于设备屏幕,您可以允许滚动场景。发生质量损失是因为您将纹理缩放到大于其预期大小。您需要提供更大的纹理以在缩放时保持高质量。在这种情况下,您可能只使用 600x600 图像(或更大)并让它缩放。例如,在我的 OS X 版 RTS Sprite-Kit 游戏中,我缩放了整个场景,以便在所有设备上获得相同的外观。而且我不会损失任何质量,因为我确保提供非常大的纹理,因此在缩放时不会损失质量。
I could also use twice as big assets for iPad devices and double the child nodes position at the runtime. In this case I would use a 400x400px asset for non-retina iPad devices and a new 800x800px asset for retina iPad devices. While this looks great and keeps the child nodes positioning working, it seems like a really big hack fixing child node position during runtime with this:
这也可行,尤其是当您的 iPad 需要自定义布局时。但是,如果可能,请避免专门针对 iPad 检查,而是使用屏幕尺寸来创建布局规则,以便您的节点在所有屏幕尺寸上一致地动态调整(参见上面的代码行)。如果您的 iPad 布局与 iPhone 非常不同,有时这是不可能的,在这种情况下,您别无选择,只能检查 iPad。
这三个解决方案都很好。我不会认为其中任何一个是“hacky”。他们都为不同的目的而工作。您需要找到最适合您的游戏的解决方案。
我还建议您在下面查看我的两个答案。不确定,但它们可以帮助您理解 Sprite Kit 中的通用定位和缩放。
https://stackoverflow.com/a/25256339/2158465
https://stackoverflow.com/a/29171224/2158465
祝你游戏顺利,如果你有任何问题,请告诉我。
关于ios - 通用 2D 游戏 Assets 和绝对节点定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29741710/
我正在使用 JavaFX 8 创建一个应用程序。我使用拖/放动态更改网格 Pane 的内容。我希望每行或每行/列迭代 GridPane 内容。JavaFX 允许通过指定行和列在 GridPane 中添
我正在尝试将图像拖放到div上。图像没有被拖到div上并给出以下错误 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': pa
我正在 android studio 中创建内部构建 AR 导航。我正在寻找一种方法将 anchor 与其他 anchor 或 anchor 节点/节点“连接”起来。我不确定使用哪一个。基于我将强制用
我在 Hive 上运行一些作业:首先是 4 节点,然后是 2 节点。令我惊讶的是,我的 2 节点性能比我的 4 节点更好。 首先,我在一个 4 节点(4 个事件节点)上运行查询,然后关闭 2 个节点(
我有 Node* current ,我在其中存储指向列表“顶部”当前节点的指针。当我将一个新节点设置为当前节点时,出现错误: '=' : cannot convert from 'CircularDo
我是 dcos Mesos 的新手,在本地 Ubuntu 机器上安装了 dc os。 我可以查看 dcos 仪表板。 但我无法使用 dcos node ssh --master-proxy --lea
在 JavaFX 中,是否有类似 setLayout(); 的东西?或 setBounds(); ? 例如,我想将按钮定位到我想要的位置。 最佳答案 JavaFX 场景图上的所有内容都是 Node .
我正在开发一个 JavaFX 应用程序,其中我开发的类(从 javafx.scene.Parent 扩展)是根据用户在 ListView 控件中单击的条目动态创建的。 只是要清楚这个节点,它不是使用像
我正在尝试为节点-边缘关系创建一个类图,因为它可以在有向图中找到。我想传达的是,Nodes 引用了 Edges,Edges 也引用了 Nodes。每个 Edge 都恰好需要两个 Node(源和目标)。
在mapreduce作业期间,单个任务将在随机节点上运行,是否有任何方法限制应在其中运行任务的节点? 最佳答案 Hadoop不会选择节点来随机运行任务。考虑到数据局部性,否则将有很多网络开销。 任务与
有什么区别: a) nodetool 重建 b) nodetool 修复 [-pr] 换句话来说,各个命令到底是做什么的? 最佳答案 nodetool重建:类似于引导过程(当您向集群添加新节点时),但
我已将第一个 OneToMany 关系添加到我的 hibernate 3.6.10 项目中。这是一个类: /** * */ package com.heavyweightsoftware.leal
是否有可能找到正在监听触发当前函数的事件的元素? 在下面的代码中,event.target 返回 #xScrollPane 和 event.currentTarget 和 event 的最低子节点.f
我正在尝试覆盖我数据库中的一些数据。结构很简单,就是: recipes { user_1{ recipe_1{data} recipe_2{data} } user_2{
我使用 setInterval 来运行该函数,但它会多次执行函数 2... 如何在输入中插入一个值后执行函数 第一个输入与其余输入的距离不同 如何在插入 val(tab 选项)后将插入从 1 个输入移
我不知道代码有什么问题,但在 visual studio 中不断收到这些错误消息。 Error 18 error C1903: unable to recover from previous e
我正在尝试从其类中获取 SharePoint 搜索导航节点的对象。 var nodes = $("div.ms-qSuggest-listItem"); 我正在获取节点对象,现在想要获取“_promp
D:\nodeP>node main.js module.js:327 抛出错误; ^ 错误:在 Function.Module 的 Function.Module._resolveFilename
struct node{ int key, prior, cnt, val; node *l, *r; node(){} node(int nkey) : key(nkey),
我有以下代码使用迭代器将项目插入双链表。这就是我们被要求这样做的方式。代码有效,但问题是我有 24 字节的绝对内存泄漏。 NodeIterator insert(NodeIterator & itrP
我是一名优秀的程序员,十分优秀!