SKCameraNode有两种方法来检查其视口(viewport)内的节点可见性。(.containsNode()和.containedNodeSet())第一个返回一个bool,这正是我要找的。检查一个节点对象工作正常。ifmyCamera.containsNode(mySpriteNode)==false{}但我想检查它是否包含一个类的节点。ifmyCamera.containsNode(MyClass())==false{}因为它不起作用,我想知道如何做到这一点。谢谢。 最佳答案 你需要看看你提到的另一种方法contained
我有一个SKCameraNode的简单子(monad)类,我称之为InteractiveCameraNode。现在它非常简单:我需要在我的相机位置改变时发生一些事情。这是我所做的:classInteractiveCameraNode:SKCameraNode{//MARK:-PropertiesvarenableInteraction=truevarpositionResponders=[(CGPoint,CGPoint)->Void]()///Callseveryclosureinthe`positionResponders`arrayoverridevarposition:CGPo
我在iOS应用程序中使用SpriteKit,并尝试在覆盖的didMoveToView方法中初始化我的SKScene的camera属性。如果我像这样初始化它:overridefuncdidMoveToView(view:SKView){...self.camera=SKCameraNode()self.addChild(self.camera!)}...它在self.addChild行抛出异常unexpectedlyfoundnilwhileunwrappinganOptionalvalue,但如果我这样做:overridefuncdidMoveToView(view:SKView){.
我一直在试验SKCameraNode,但我找不到任何关于用它创建视差效果的信息。假设我在上面的代码中添加了一个behindNode在我的baseNode下面。然后我为相机设置动画。letbehindNode=SKNode()addChild(behindNode)letblueSquare=SKSpriteNode(color:SKColor.blueColor(),size:CGSize(width:80,height:80))blueSquare.position=CGPoint(x:size.width/2+40,y:size.height/2+40)behindNode.add
我有一个SpriteKit场景,其中背景(SKSpriteNode)的大小是场景帧的2倍。我添加了一个摄像头,当用户用手指平移和捏合时,它会四处移动。我实现了缩放和平移,但是,我需要相机不移动超过背景节点的边缘。我尝试过使用物理体和边缘循环,但是没有用(除非我设置错误)。这是我目前拥有的代码和一些有助于传达信息的图像。我应该移动背景节点而不是相机吗?self.physicsBody=SKPhysicsBody(edgeLoopFrom:self.frame)self.physicsBody!.categoryBitMask=SCENE_EDGE_CATself.physicsWorld
如果这里有人以前玩过Agar.io,您可能会熟悉镜头移动的方式。它会根据鼠标距屏幕中心的距离向鼠标滑动。我正在尝试使用SKCameraNode和touchesMoved重新创建此移动:overridefunctouchesMoved(_touches:Set,withevent:UIEvent?){letpos=touches.first!.location(in:view)letcenter=view!.centerletxDist=pos.x-center.xletyDist=pos.y-center.yletdistance=sqrt((xDist*xDist)+(yDist*y