ios - How can I find out if an SKTexture is the placeholder image -
in spritekit, if load image [sktexture texturewithimagenamed:] method, first search bundles, atlases, if fails find texture, create placeholder image , load it.
is there way find out (without visually checking) if loaded image placeholder?
this doesn't seem "cocoa" way handle type of error.
developer.apple.com down now, figured pose question so.
sktexture has private properties helpful (see e.g. https://github.com/luisobo/xcode-runtimeheaders/blob/master/spritekit/sktexture.h), in swift , during development i'm using this:
extension sktexture { public var isplaceholdertexture:bool { if size() != cgsize(width: 128, height: 128) { return false } return string(describing: self).contains("'missingresource.png'") } }
attention!:
this works, if using sktextureatlas
:
let t1 = sktextureatlas(named: "mysprites").texturenamed("nonexistingfoo") // t1.isplaceholdertexture == true let t2 = sktexture(imagenamed: "nonexistingbar") // t2.isplaceholdertexture == false
Comments
Post a Comment