2

I am using spritekit with swift (ios8, xcode 6). When I use the physicsbody constructor self.physicsBody = SKPhysicsBody(texture: myTexture, size: myTexture.size()) , it fails every time, with the following error:

<Error>: CGBitmapContextCreate: unsupported parameter combination:
 8 integer bits/component; 32 bits/pixel; 
 3-component color space;
 kCGImageAlphaPremultipliedLast; 127 bytes/row.   

However, when I switch back to the physicsbody constructor like 'SKPhysicsBody(rectangleOfSize: ...)' it works fine... I want to use the texture-based physics body, however. Why is this error happening and how do I fix it?

4
  • 1
    have you tried using a different texture
    – hamobi
    Jan 26, 2015 at 8:00
  • It basically tells you that the image format of the texture is unsupported. Try using a different image or save the image in a "standard" format, for instance PNG with 24-bit colors (truecolor) and 8-bit alpha channel (RGBA). Also be sure the image is neither too small (anything below 8x8 could be problematic) nor too large (up to 2048x2048 works on all devices).
    – CodeSmile
    Jan 26, 2015 at 10:12
  • I've tried using a different image, I get the same error. Perhaps it's because I'm using Gimp to export my PNGs and this is giving the wrong format?
    – acahreonn
    Jan 26, 2015 at 23:13
  • I resigned to using a circle - based physicsbody constructor. It seems apple's auto-path maker is currently bugged.
    – acahreonn
    Mar 3, 2015 at 0:18

1 Answer 1

0

I resolved this issue by simplifiying the shape of the texture I was using to generate the physics body. I suspect there is an issue generating the physic body using shapes with certain characteristics (which I haven't spent the time to identify). Regardless, there is definitely a bug in SpriteKit, or at least the error message that comes back is not communicating the relevant information about why the error is occurring. BTW, Changing the bits per channel had no effect.

So, I would try to simplify your shape if you can. In my case this image:Sprite that generates errorgenerate the error when used to initialize a PhysicsBody, whereas this image: Sprite that does not generate an errordoes not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.