1

I’m searching the best way to build the levels for a game :

  • The game will be composed with many levels, each levels will be unique.
  • You’ll play an object (here the star), which is in movement on a grid.
  • The object can move only to the bottom, it cannot go back.
  • A level is composed with many cases, each cases will have a different behavior.
  • My level will have a background, width of the screen, but the height will depend on the level, I suppose many times the height of the screen.
  • The background moves depending on the object movements

For now, I’m working on a little prototype, just to learn.

proto

After reading many tutorials, my idea is to create x squares (diamond-shape) using SKSpriteNode. And to identify the squares with identifiers.

I don’t know if it’s a good solution in terms of performance? They will be a lot of squares in one level. I don’t realize :)

Are we limited with the numbers of node in one scene?

cmii
  • 3,556
  • 8
  • 38
  • 69
  • You're probably safe until you get to 100 or more nodes in the scene, but it all depends upon how much 'work' those nodes need to do in terms of how much physics each requires or if you are doing a lot of computation in the update() method. – Steve Ives Jun 16 '16 at 14:23
  • @SteveIves no physics, just need to detect if the object is on the square node – cmii Jun 16 '16 at 14:55
  • @SteveIves In Sprite Kit, you are safe _way_ beyond 100 nodes. 1,000 or 10,000 is no problem **if** you keep the number of draw calls low. – CloakedEddy Jun 17 '16 at 07:31
  • If you have access to the latest Xcode 8 (beta) you'll find a "Tile Map" feature, which will probably help you a lot. Check this session : https://developer.apple.com/videos/play/wwdc2016/610/ at 8:27 . PS : Feature is a little instable at the moment, beta... – lchamp Jun 18 '16 at 18:02

1 Answers1

1

I think it's not necessary. You can also use a single SKSpriteNode background populated by squares CGPath's and you can make a very fast game if you want to increase difficult levels. You can organize your "functional" part of game by working with each CGPath and when you must change a square in this case you can create a square using the CGPath that represent that square, give to it a name based for example to an index to easily understand who it is, using the CGPath involved and use this SKSpriteNode to:

  • cover the square background
  • make an effect like explosion
  • change color of a square instead of general square colors
  • etc..

P.S.: I've seen you want to create a scrollView, there is a nice Spritekit library in swift called CustomScrollView here that can be useful , it's simply to use:

scrollView = CustomScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height), scene: self, moveableNode: moveableNode, scrollDirection: .Vertical)
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height * 3) // makes it 3 times the height
view?.addSubview(scrollView)

Update: about your comment, the answer is yes: when you work with a path you work with a group of elements organized in points (take a look at this post to understand how).

You can use the native:

CGPathContainsPoint(<#T##path: CGPath?##CGPath?#>, <#T##m: UnsafePointer<CGAffineTransform>##UnsafePointer<CGAffineTransform>#>, <#T##point: CGPoint##CGPoint#>, <#T##eoFill: Bool##Bool#>)

or use this:

CGPathGetPathBoundingBox(<#T##path: CGPath?##CGPath?#>)

to use it:

CGRectIntersectsRect(<#T##rect1: CGRect##CGRect#>, <#T##rect2: CGRect##CGRect#>)
Community
  • 1
  • 1
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
  • Thanks for your idea! Is it possible to detect intersections between my object (SKSpriteNode) and the CGPath (square)? – cmii Jun 16 '16 at 15:19
  • 1
    dont use UIScrollView, it is not a good idea to mix UIKit and SpriteKit, there are huge performance issues, Just create a large node, and use the scene camera to scroll the large node – Knight0fDragon Jun 16 '16 at 16:32
  • @KnightOfDragon depend by how many nodes you handle in your scroll. In my games it work well, even using emitters (and you know how many resources they required..) so I cannot found these problems. However thank you for your comment. – Alessandro Ornano Jun 16 '16 at 16:35
  • Thanks guys! I think I'm going to try the CGPath solution :) – cmii Jun 17 '16 at 20:56
  • Well, if you meet any problem link to me your next question so i will try to help you, good luck – Alessandro Ornano Jun 18 '16 at 09:23
  • 1
    @AlessandroOrnano first problem :( I created another stack http://stackoverflow.com/questions/37897837/how-to-create-cgpath-from-a-skspritenode-in-swift – cmii Jun 18 '16 at 14:05
  • 1
    @AlessandroOrnano, I have taken the time before answering, I tried many ways to do what I need, essentially with SKSpriteNode first. But with all the solutions tried, use SKShapeNode created via UIBezierPath seems the best solution in my case! Thanks! – cmii Aug 24 '16 at 19:30
  • @cmi Excellent news, I'm glad to have helped. Good luck. – Alessandro Ornano Aug 24 '16 at 19:31