2

I'm creating a simple tetris game in swift to try out sprite kit/swift together. I'm creating tetris as practice using SKShapeNodes to create all the shapes and the game board. Unfortunately this is causing the iPhone's CPU to run at pretty much 100% the entire time the game is playing. In the apple docs it says that the SKShapeNode is not efficient and to use SKSpriteNode instead when possible. My game scales based on the size of the screen so I'd like to create an SKShapeNode then convert that to an SKSpriteNode. I found an example online using textures to accomplish that, but it seems like an ugly solution. Is there a simple/standard way to convert an SKShapeNode to an SKSpriteNode to avoid maxing out the CPU?

Thanks for your help!

ORL
  • 598
  • 2
  • 8
  • 22

1 Answers1

3

The best solution is to design all of your assets (for various screen sizes) in a graphics editor (such as Photoshop or Illustrator) then create SKSpriteNodes using those assets.

But if for some reason you really want to create your SKSpriteNodes using SKShapeNodes then the only way to do that is to use the textureFromNode method on the SKView.

Epic Byte
  • 33,840
  • 12
  • 45
  • 93
  • 1
    Thanks! I'll switch to the textureFromNode method for this game. – ORL Jun 22 '15 at 00:35
  • 2
    By the way, in swift, this is how you use that function: "let myTexture = self.view?.texture(from: [SKNode], crop: CGRect)". The crop argument can be omitted. – retrovius Jun 29 '17 at 20:30