0

We have different images for iPhones and iPads, but the Particle Emitter Editor in Xcode only seems to use the iPhone images -- even on iPad devices.

We also tried changing the texture in code like this:

emitterNode.particleTexture = SKTexture(imageNamed: "Test.png")

We have an image named "Test@2x~ipad.png". This is the iPad version of the image.

The iPhone version is named "Test@2x.png".

Is automatically using different images for different devices not possible with SKEmitterNodes, or are we doing something wrong?

Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • @matt yup, that is a possibility. just trying to see if there's a less hacky way of doing it, meaning all from the particle editor (since everything else is controlled by the particle editor). – Crashalot Mar 24 '17 at 03:17

2 Answers2

1

Instead of calling SKTexture(imageNamed: "Test.png"), call SKTexture(image: UIImage(named: "Test")). The call to UIImage(named:) will obey the bundle resource naming conventions.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • so SKTexture(ImageNamed: "Test.png") isn't supposed to obey bundle resource naming conventions? thanks for sharing! – Crashalot Mar 24 '17 at 03:19
  • I don't know whether it does or not. But I do know that `UIImage(named:)` does! – matt Mar 24 '17 at 03:20
  • fair enough, will try this approach and see if it works! thanks again. – Crashalot Mar 24 '17 at 04:29
  • unfortunately this didn't work ... any other suggestions? the texture size of the new image prints out correctly, but it seems like the particle's texture size is stuck with the size of the particle's original image/texture. in other words, the image itself changes, but the size doesn't. – Crashalot Mar 24 '17 at 04:35
  • Ah yes, the size. As I recall, you don't use 2x images for emitters. Is that the problem? – matt Mar 24 '17 at 04:39
  • actually i think the problem is you must explicitly change the particle size after changing the texture/image. will try that and grant you credit if it works. – Crashalot Mar 24 '17 at 04:41
  • I don't see why I get any credit, but do keep me posted on what happens. :) – matt Mar 24 '17 at 04:50
  • yup updating the emitter's `particleSize` property was the problem. see answer below. can even use `SKTexture(imageNamed: "Test.png")` as well. you get credit for helping out! :) – Crashalot Mar 24 '17 at 04:51
0

This is the answer but gave @matt the points since he helped out.

Unfortunately it seems like the Xcode Particle Editor won't automatically recognize the iPad image via the ~ipad naming convention.

The solution is to specify the texture in code, but you must also update the particle size like this:

            let texture = SKTexture(imageNamed: "Test.png")
            emitterNode.particleTexture = texture
            emitterNode.particleSize = texture.size()
Crashalot
  • 33,605
  • 61
  • 269
  • 439