使用SpriteKit和SWIFT为游戏构建网格级别 [英] Build a grid level for a game with SpriteKit and SWIFT

查看:120
本文介绍了使用SpriteKit和SWIFT为游戏构建网格级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找构建游戏关卡的最佳方法:

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

目前,我正在研究

阅读了很多教程,我的想法是使用SKSpriteNode创建x个正方形(菱形)。并用标识符标识正方形。

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?

推荐答案

我认为没有必要。您还可以使用由 CGPath 正方形填充的单个 SKSpriteNode 背景,如果您制作了一个非常快速的游戏,想要增加难度。您可以通过与每个 CGPath 一起组织游戏的功能性部分,在这种情况下必须更改正方形时,可以使用 CGPath ,使用涉及的 CGPath 为它赋予一个名称,例如基于索引以轻松了解其名称,使用此 SKSpriteNode 可以:

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..

PS:我已经看到您要创建一个scrollView,在swift中有一个不错的Spritekit库,名为 CustomScrollView 此处可能有用,只需使用:

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).

您可以使用本机:

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

或使用以下命令:

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

要使用它:

CGRectIntersectsRect(<#T##rect1: CGRect##CGRect#>, <#T##rect2: CGRect##CGRect#>)

这篇关于使用SpriteKit和SWIFT为游戏构建网格级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆