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

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

问题描述

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

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

  • 游戏将由多个关卡组成,每个关卡都将是独一无二.
  • 您将演奏一个正在运动的物体(这里是星星)在网格上.
  • 物体只能向下移动,不能返回.
  • 一个关卡由很多案例组成,每个案例都会有不同的行为.
  • 我的关卡会有背景、屏幕宽度,但是高度将取决于水平,我想很多倍的高度的屏幕.
  • 背景随着物体的移动而移动

目前,我正在制作一个小原型,只是为了学习.

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

阅读了很多教程后,我的想法是使用 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:

  • 覆盖方形背景
  • 制作爆炸效果
  • 改变正方形的颜色而不是一般的正方形颜色
  • 等等.

PS:我看到你想创建一个滚动视图,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天全站免登陆