简体   繁体   English

如何通过Swift和SpriteKit使视图可滚动以查看带有sprite的整个场景?

[英]How to make a view scrollable to view the full scene with sprites with Swift and SpriteKit?

I have a Scene which now fills in the view: 我有一个场景,现在会填充视图:

scene.size = skView.bounds.size scene.scaleMode = .AspectFill

I fill in the scene with sprites from bottom to top and in my up they need to go further up - outside the view. 我用从下到上的精灵填充场景,在我的场景中,它们需要进一步向上移动-在视图之外。

So my scene should have the same width as a view but height should be... around 3000 fixed. 因此,我的场景应与视图具有相同的宽度,但高度应...固定为3000。

Sprite will fill in the screen and i want to scroll up to be able to view the whole scene. Sprite将填满屏幕,我想向上滚动才能查看整个场景。

Would you please give me an advice on how to "construct" that? 您能给我建议如何“构建”它吗?

You should create a node that acts as the World for the scene in your project and simply shift the y coordinate downwards to give the illusion of being able to see the scene that is further up. 您应该创建一个节点,充当项目中场景的世界,并简单地将y坐标向下移动,以产生能够看到更远的场景的幻觉。

For some sample code, you can look here 有关一些示例代码,您可以在这里查看

Here is a quick road map: 这是一个快速的路线图:

  1. In your game scene "didMoveToView" you want to make a "world" node. 在您的游戏场景“ didMoveToView”中,您想创建一个“世界”节点。 Make sure the "world" node is a global variable by declaring it outside of the class. 通过在类外部进行声明,确保“ world”节点是全局变量。 Make that "world" node size as large as the full size needed (eg, 3000). 使该“世界”节点大小与所需的完整大小一样大(例如3000)。
  2. Also in "didMoveToView" add a pinch gesture that will eventually allow you to "zoom" that world, using UIPinchGestureRecognizer 同样在“ didMoveToView”中添加捏合手势,最终将允许您使用UIPinchGestureRecognizer“缩放”该世界
  3. Make the function to handle the pinch. 使该功能处理捏。 Ultimately, the "recognizer.scale" should influence the "world.scale" 最终,“ recognizer.scale”应该影响“ world.scale”
  4. All your sprites should be added to the "world" node 您所有的精灵都应添加到“世界”节点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM