如何让相机跟随Sprite Kit中的SKNode? [英] How to make camera follow SKNode in Sprite Kit?
本文介绍了如何让相机跟随Sprite Kit中的SKNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望背景固定不同的物体(精灵和其他物体)。
I want to have background stationary with different objects (sprites and other objects).
玩家将由将在世界各地移动的中心节点表示。我希望将相机固定到中央节点,例如世界应该移动,相机应该保持静止。
Player will be represented by center node that will move around the world. I want to have my camera pinned to central node, e.g. the world should move and the camera should stay stationary.
我如何实现这一目标?
推荐答案
这样的事情应该会有所帮助。我从didSimulatePhysics调用以下内容。
Something like this should help. I call the following from my didSimulatePhysics.
-(void)centerOnNode:(SKNode*)node {
CGPoint cameraPositionInScene = [node.scene convertPoint:node.position fromNode:node.parent];
cameraPositionInScene.x = 0;
node.parent.position = CGPointMake(node.parent.position.x - cameraPositionInScene.x, node.parent.position.y - cameraPositionInScene.y);
}
这篇关于如何让相机跟随Sprite Kit中的SKNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文