且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift 2.0,SpriteKit - 滚动视图不使用页面.

更新时间:2023-11-17 17:02:22

我不明白你在这里问什么.我刚刚检查了 RayWenderlich 教程,它与我的 GitHub 示例项目完全相同.他们只是让精灵更靠近在一起,在我的项目中为了演示目的,我将每个精灵放在一个新页面上.

I dont understand what you are asking here. I just checked the RayWenderlich tutorial and its exactly the same as my GitHub sample project. They just keep the sprites closer together where as in my project for demonstration purposes I put each sprite on a new page.

如果您只想让精灵滚动,只需将精灵添加到可移动节点,其余的照常直接添加到场景中.

If you just want sprites to scroll that just add the sprites to the moveableNode and the rest as usual to the scene directly.

addChild(background)
moveableNode.addChild(sprite1)

改变精灵的位置,使它们更靠近.您基本上将第一个精灵添加到滚动视图中的第一页,然后根据先前的精灵 x 位置定位其他精灵.您也可以将这些精灵添加到 sprite1.

Than change the sprite positions so they are closer together. You basically add the 1st sprite to the 1st page in the scrollView and than position the other sprites based on the previous sprites x position. You add these sprites to sprite1 as well.

let sprite1 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite1.position = CGPointMake(0, 0)
page1ScrollView.addChild(sprite1)

let sprite2 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite2.position = CGPointMake(sprite1.position.x + (sprite2.size.width * 1.5), sprite1.position.y)
sprite1.addChild(sprite2)

let sprite3 = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 50))
sprite3.position = CGPointMake(sprite2.position.x + (sprite3.size.width * 1.5), sprite1.position.y)
sprite1.addChild(sprite3)

我更新了我的 gitHub 项目以实际展示这一点https://github.com/crashoverride777/Swift2-SpriteKit-UIScrollView-Helper

I updated my gitHub project to show this in action https://github.com/crashoverride777/Swift2-SpriteKit-UIScrollView-Helper