- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,纹理 是通过 PaintCode ( paint-code ) 提供的方法按程序生成的。
然后我创建一个 SKTextureAtlas
来自字典 UIImage
通过这些方法生成:
myAtlas = SKTextureAtlas(dictionary: myTextures)
最后,使用 textureNamed
从 atlas 检索纹理 :
var sprite1 = SKSpriteNode(texture:myAtlas.textureNamed("texture1"))
但显示的节点在 iPhone4S 模拟器上是双倍大小。在 iPhone 6 Plus 模拟器上大小为三倍。
似乎在初始化时,atlas 以设备分辨率计算图像。但是生成的图像已经具有正确的大小,不需要更改。请参阅下面的绘图方法。
这里是生成图片的描述:
<UIImage: 0x7f86cae56cd0>, {52, 52}
以及图集中对应纹理的描述:
<SKTexture> 'image1' (156 x 156)
这适用于 iPhone 6 Plus,使用 @3x 图像,这就是尺寸为 x3 的原因。
对于 iPhone 4S,使用 @2x 图像,如预期的那样:
<UIImage: 0x7d55dde0>, {52, 52}
<SKTexture> 'image1' (156 x 156)
最后,scale
生成的属性 UIImage
设置为正确的设备分辨率:@2x (iPhone 4S) 为 2.0,@3x (iPhone 6 Plus) 为 3.0。
那么如何避免图集调整图片大小呢?
PaintCode 生成绘图方法如下:
public class func imageOfCell(#frame: CGRect) -> UIImage {
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
StyleKit.drawCell(frame: frame)
let imageOfCell = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return imageOfCell
}
比较两种生成 SKTextureAtlas
的方法
// Some test image
let testImage:UIImage...
// Atlas creation
var myTextures = [String:UIImage]()
myTextures["texture1"] = testImage
myAtlas = SKTextureAtlas(dictionary: myTextures)
// Create two textures from the same image
let texture1 = myAtlas.textureNamed("texture1")
let texture2 = SKTexture(image:testImage)
// Wrong display : node is oversized
var sprite1 = SKSpriteNode(texture:texture1)
// Correct display
var sprite2 = SKSpriteNode(texture:texture2)
看来问题出在SKTextureAtlas
上来自字典,如SKSpriteNode
初始化不使用 UIImage
中的 scale 属性正确调整节点大小。
这里是控制台的描述:- 纹理 1:''(84 x 84)- 纹理 2:“纹理 1”(84 x 84)
texture2
想念一些data
!这可以解释为什么缺少缩放信息来正确调整节点大小:
节点的大小 = 纹理的大小除以纹理的比例。
问题发生在 UIImage
的缩放属性时不同于一个。
所以可以使用下面的方法来生成图片:
func imageOfCell(frame: CGRect, color:SKColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
var bezierPath = UIBezierPath(rect: frame)
color.setFill()
bezierPath.fill()
let imageOfCell = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return imageOfCell
}
最佳答案
问题来自于使用 SKTextureAtlas(dictionary:)
来初始化图集。
使用此方法创建的 SKTexture 不会嵌入与图像的 scale 属性相关的数据。因此,在 init(texture:)
创建 SKSpriteNode
期间,纹理中缺少比例信息导致选择纹理大小而不是图像大小。
纠正它的一种方法是在 SKSpriteNode
创建期间提供节点的大小:init(texture:size:)
关于swift - 如何强制从字典创建的 SKTextureAtlas 不修改纹理大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31557305/
每当我创建两个变量并将其定义为 SKTextureAtlas 类型时,它们都会互相重写。这是我最初创建的两个 SKTextureAtlas class GameScene: SKScene {
我做了一个快速项目来了解 SpriteKit 如何从内存中释放 map 集。每次点击屏幕时,都会创建一个图集并将其加载到内存中。对图集的唯一引用是您在下面的代码中看到的内容,我认为由于 var 位于非
我在使用多个 map 集时遇到问题。 例如,我有 main_menu.atlas 和 game.atlas 以及这些场景的图像。在主菜单场景出现之前,我为它准备了图集([SKTextureAtlas
我正在研究处理角色动画的类(class)。动画将具有用户在创建角色时选择的不同肤色。每个肤色的图集具有相同的名称,但存储在不同名称的文件夹中,如下所示: 这是在 xcassets 文件夹中 这应该让我
如果一个 iOS 项目有一个 UIImages 字典,如何在运行时从字典图像正确创建 SKTextureAtlas?我无法实现这个目标,尽管 Apple 的 SKTextureAtlas 类引用在声明
我将一个名为“movementAnim”的文件夹拖到 Image assets 文件夹中,该文件夹用于创建纹理图集(来 self 从 WWDC 2015 What's New in SpriteKit
我在获取免费的纹理图集时遇到问题。目前我有一个 SpriteKit 游戏,玩家可以在其中改变他的角色。现在我在这样的全局共享实例中拥有 map 集。 let char0Atlas: SKTexture
我在 SpriteKit 上开发了一个游戏,每个场景都有多个场景 最少来自 3 个 TextureAtlas 每个 TextureAtlas 中图像的最大大小为 60K 我的游戏因内存问题而崩溃 我在
类似于 WWDC 的 SpriteKit 特色游戏“冒险”,我尝试通过图 block 加载我的背景图像。我创建了一个纹理图集,其中包含 6,300 个“图 block ”,每个“图 block ”大小
在我的项目中,纹理 是通过 PaintCode ( paint-code ) 提供的方法按程序生成的。 然后我创建一个 SKTextureAtlas来自字典 UIImage通过这些方法生成: myAt
我已经阅读了此处关于此主题的所有帖子,但似乎都没有回答我的问题。 我的问题是 SKTexture/SKTextureAtlas 何时加载到内存中? 从我读到的内容来看,您需要对使用 [SKTextur
我正在努力通过 Apportable 将我的 SpriteKit 制作的 Objective-C 应用程序转换为 Android 应用程序。在“可分配负载”方面,我遇到了 SKTextureAtlas
我不确定我是否做错了,或者“atlasWithDictionary ”方法是否有问题。 我是这样用的: NSArray* imageNames = @[ @"image1", @"image2", @
我制作了一个使用许多纹理图集的游戏。我目前在 asset.xcassets 文件夹中使用 SpriteAtlases,在测试低于 iOS 10 的设备之前该效果非常好。 在 iOS 9 的任何设备上运
有没有人能够让 xcode 6 中的模拟器使用 atlas 中的 3x 图像?每当我将它们加载到 SKTextureAtlas 中时,它都会使用 2x 图像。 如果我将 test@2x.png 和 t
我似乎在使用 SKTextureAtlas 和纹理的最近邻过滤时遇到问题。当我在没有 SKTextureAtlas 的情况下使用最近邻过滤时它工作正常,但是当我使用 SKTextureAtlas 时一
我正在开发 SWIFT3/SpriteKit 屏幕保护程序,我的屏幕保护程序可以正常工作,但我无法加载我的纹理,因为当我执行以下操作时: // load texture atlas let textu
我需要带有“trueName”的纹理来加载到我的 myImageViewOutlet.image 中。我得到的结果是将整个图集渲染到其中。我的代码如下 let myTextureAtlas = SKT
我有一个 SKTextureAtlas,其中包含 7 帧具有透明背景的动画 Sprite 。 我已经能够使用 map 集中的单个帧作为物理体的边界,但我想知道如果可能的话,如何让物理体更新 map 集
通过为我所有的游戏动画预先设置强大的 SKAction 是 Sprite Kit 缓存的实际图像数据以供将来使用。我想了解的是,如果我将所有动画设置为保留的 SKAction 是否还有必要预加载它们最
我是一名优秀的程序员,十分优秀!