如何让 Sprite Kit 中的相机跟随 SKNode? [英] How to make camera follow SKNode in Sprite Kit?

查看:23
本文介绍了如何让 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆