简体   繁体   English

带Box2d的iPhone游戏:如何在玩家周围移动世界

[英]iPhone game with Box2d: How to move world around player

So I have a very basic iPhone game that I am working on, where a ball moves around the screen, with fixtures for walls that the ball can hit. 因此,我正在开发一款非常基本的iPhone游戏,其中一个球在屏幕上移动,并带有可以击中墙壁的固定装置。

I want the game to be side-scrolling from right to left, but I can't figure out how to approach this. 我希望游戏从右向左滚动,但我不知道该如何处理。

I have done a bit of research and it seems that the best approach is to move the world around the player. 我做了一些研究,似乎最好的方法是在玩家周围移动世界。 So my question is, how do I move/slide the wall fixtures consistently to the left to imitate a side-scrolling effect? 所以我的问题是,如何将墙壁固定装置始终向左移动/滑动以模仿侧滚动效果?

Don't move the world. 不要移动世界。 Move the camera. 移动相机。 Create a class (camera) that will store its position relative to the world. 创建一个类(相机),以存储其相对于世界的位置。 Using the camera position you can calculate the layer (CCLayer where everything is drawn) position. 使用相机位置,您可以计算图层(绘制所有内容的CCLayer)位置。 In the simplest case it will be -cameraPos . 在最简单的情况下,它将是-cameraPos

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

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