简体   繁体   English

如何使视野跟随我的形象?

[英]How to make view follow my image?

Im making a scene for my game. 我正在为我的游戏做一个场景。 Right now i`m working on the view for IPhone 5-5c-5s the orientation is in landscape. 现在,我正在为iPhone 5-5c-5s的视图工作,方向是横向的。 But the view was not big enough for my scene, so i made the simulated size to freeform so i could choose the width for the scene. 但是视图不足以容纳我的场景,因此我将模拟尺寸设置为自由形状,以便可以为场景选择宽度。 (Im using a normal Viewcontroller). (我使用的是普通的Viewcontroller)。

In the game you are supposed to move an image to another image without colliding with obstacles. 在游戏中,您应该将图像移动到另一个图像而不会与障碍物碰撞。 The users playing the app are going to move an image from one side of the screen all the way over to the other side to the other image to win. 玩此应用程序的用户将把图像从屏幕的一侧一直移到另一侧,再移到另一侧以取胜。

But when my image moves, the view doesnt follow with my image. 但是,当我的图像移动时,视图不会跟随我的图像。 How do you do that? 你是怎样做的?

I would be so thankful for any answear! 我会很感激任何answear! Thanks. 谢谢。

I am assuming you are using SpriteKit yeah? 我假设您正在使用SpriteKit是吗? The UIView size is not related to the scene size. UIView大小与场景大小无关。 So changing those will not make your scene any different. 因此,更改这些不会使您的场景有所不同。

To do what you are describing, you need to read the Apple's Official Documentation on SpriteKit. 要执行您所描述的操作,您需要阅读SpriteKit上的Apple官方文档。

https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html

Scroll down to Example: Centering the Scene on a Node 向下滚动到示例:将场景居中放在节点上

Basically Apple tells you to add a dummy SKNode to put all your world sprites into the scene, and then add another SKNode as "camera" into the dummy node so you can move it around. 基本上,Apple告诉您添加一个虚拟SKNode以将所有世界精灵放置到场景中,然后将另一个SKNode作为“相机”添加到虚拟节点中,以便您可以将其移动。

If you are targetting only iOS9 and above, you can use SKCameraNode and set: 如果您仅定位iOS9及更高版本,则可以使用SKCameraNode并设置:

SKCameraNode *cameraNode = [SKCameraNode new];
cameraNode.name = @"camNode";
self.camera = cameraNode;

Then you add your "character" (that is to be moved together with the camera) into the cameraNode. 然后,将“字符”(将与照相机一起移动)添加到cameraNode中。 Then any movement, you need to move the cameraNode instead of the "character". 然后,任何移动都需要移动cameraNode而不是“字符”。

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

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