Fill SKScene background with tiled image

Is it possible to draw background of SKScene with tiled pattern of texture like bricks wall?

If it should map amounts of SKTexture by myself, is there something like batchable draw method to improve stability?

I found the method to fill background with pattern image


class SceneTitle : SKScene {
     override func didMoveToView(view: SKView) {
          let Img: UIImage = UIImage(named: "brick.png")!
          self.backgroundColor = UIColor(patternImage: Img)
     }
}


It seems Loading UIImage works fine , but background color was not changed.

Hi polig,


Pattern images are not supported via UIColor in SpriteKit. You can achieve pattern color effects by using an SKShader on a sprite node. By scaling and offsetting the passed in texture coordinates you can get repeating patterns. The editor supports live editing of a shader in a .fsh file, so you can experiment right in Xcode.


Have a look at https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKShader_Ref/index.html


Cheers

Hi greven


it seems omnipotent but difficult.

I will look SKShader up.

Thks!

Hi Polig,


Shaders are initially a bit daunting but once you get used to them you'll love them. Have a look at https://www.shadertoy.com if you want to see what can be done using just a fragment shader.


Please do file an enhancement request radar if using pattern UIColors is important to you. It is a way for you to 'vote' for features you'd like to see.


Cheers

Fill SKScene background with tiled image
 
 
Q