iPhone:cocos2d中的相机下面的播放器 [英] iPhone: Camera following player in cocos2d

查看:150
本文介绍了iPhone:cocos2d中的相机下面的播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cocos2d上制作了一个iPhone游戏。

I'm making an iPhone game in cocos2d.

我想知道如何让相机/视图遵循特定的精灵?

I was wondering how I would make the camera / the view follow a specific sprite?

我会使用CCCamera类吗?

would I use the CCCamera class?

推荐答案

然而,它具有使其对于一些用途不期望的一些缺点。相对于该子画面分别移动所有其他对象可以是更好的解决方案。这取决于游戏。

Yes, CCCamera would work. However, it has some drawbacks that make it undesirable for some uses. Moving the layers respectively all other objects relative to that sprite may be a better solution. It depends on the game.

首先,了解不同的方法和他们的缺点,你可以从这个cocos2d论坛主题中得到很多东西:
http://www.cocos2d-iphone.org/forum/topic/5363

First, read up what the different approaches and their drawbacks are, you can get a lot out of this cocos2d forum thread: http://www.cocos2d-iphone.org/forum/topic/5363

如果你能描述你的游戏是什么,以及为什么你需要相机附加到那个sprite,这将是有帮助的。

It would be helpful if you could describe what your game is about and why you need the camera attached to that sprite.

例如,如果你正在考虑一个像Canabalt这样的运行游戏,我不会使用相机来滚动世界,而是滚动一切相对于播放器(向他),玩家在跑步时在大约相同的x坐标处停留。完美的游戏的例子,你不会移动相机是iCopter游戏,他们基本上是简化版的Canabalt。注意玩家精灵总是停留在完全相同的x坐标,游戏世界只是滚动

For example, if you're thinking of a running game like Canabalt, i would not use the camera to scroll over the world, but instead scroll everything relative to the player (towards him) with the player sticking at about the same x coordinate while running. Perfect examples of games where you would not move the camera at all are the iCopter games, they are basically simplified versions of Canabalt. Notice that the player sprite always stays at the exact same x coordinate, and the game world just scrolls

在我看来,滚动相机本身是最有意义的,如果你有一个大游戏世界,玩家可以在所有方向上遍历,并且对象的数量太多,并且还在各个方向移动,因此,每个帧更新它们的位置将是过度的并且容易出错。而且由于游戏世界是如此巨大,你会想使用相机的位置来限制屏幕上绘制的内容。

Scrolling the camera itself in my opinion makes the most sense if you have a large game world that the player can traverse in all directions, and the number of objects are simply too numerous and also moving about in various directions, so updating their positions individually each frame would be both overkill and prone to errors. And since the game world is so huge, you would want to use the camera's position to limit what is drawn on screen.

这篇关于iPhone:cocos2d中的相机下面的播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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