Swift SKSpriteNode with UIImage

I have a problem creating SKSpriteNode with UIImage. I create assets that I use for my application with PaintCode (PaintCode creates a Swift file with drawing methods and image methods that allow me to display the created images).

Now my problem is that I want to create a simple SKSpriteNode using my PaintCode images, but I don't know how to add them to SpriteNode.

I tried something like this (line 18):

let Bottom = SKSpriteNode(texture: SKTexture(image: StyleKitName.drawBottom(frame: CGRect(x: 50, y: 50, width: 50, height: 50), isWinter: false))) 

But it returns the following error:

 /Users/myMacName/Documents/App Development/AppName/AppName/GlobalFunctions.swift:18:44: Cannot find an initializer for type 'SKTexture' that accepts an argument list of type '(image: ())' 

The StyleKitName.drawBottom function returns a UIImage. It would be nice if someone could tell me how to create an SKSpriteNode with UIImage.

I appreciate any help. Thanks.

+4
source share
2 answers

If you have UIImage, you can make a node sprite with it:

 let Image = //do your setup here to make a UIImage let Texture = SKTexture(image: Image) let Sprite = SKSpriteNode(texture:Texture) 

I'm not sure where and how you called the methods, but I can assure you that these are the correct initializers.

+9
source

if you want to link it to the scene editor

  let movieImage = self.childNode(withName: "MovieImage") as! SKSpriteNode? let Image = UIImage(named: "imageName") let Texture = SKTexture(image: Image!) movieImage?.texture = Texture 
0
source

All Articles