简体   繁体   English

如何在iphone上用cocos2d + Box2d创建一个带曲线的关卡?

[英]How to create a level with curved lines with cocos2d + Box2d on the iphone?

I'd like to create a game that has levels such as this: http://img169.imageshack.us/img169/7294/picdq.png 我想创建一个具有以下级别的游戏: http//img169.imageshack.us/img169/7294/picdq.png

The Player moves "flies" through the level and mustn't collide with the walls. 玩家将“苍蝇”移动到水平位置,不得与墙壁碰撞。 How can I create such levels? 我怎样才能创建这样的关卡?

I found that piece of software: http://www.sapusmedia.com/levelsvg/ 我找到了那个软件: http//www.sapusmedia.com/levelsvg/

It's not that cheap, so I wonder whether there is another way to create such a level as shown in the picture above...? 它不是那么便宜,所以我想知道是否还有另一种方法可以创建如上图所示的水平......?

You can do that pretty easy by reading the color value of pixels at specific places of the level. 通过读取关卡特定位置的像素颜色值,您可以非常轻松地完成此操作。 Take for instance that your level background is white and the walls are black. 例如,您的水平背景为白色,墙壁为黑色。 In order to perform collision detection, whether your character had hit the wall, you would do the following: -take your character's position -look at the color values of the pixels of your map that overlap with character's bounding box or sphere at that position -if any of those contain black color you have yourself a collision :) 为了执行碰撞检测,无论你的角色是否撞到了墙上,你都会做以下事情: - 获取角色的位置 - 查看地图像素的颜色值,该颜色值与角色的边界框或球体在该位置重叠 - 如果其中任何一个包含黑色你自己碰撞:)

Now if your level is all colourful, you would want to build a black and white mask texture that would reflect the wall surfaces of your actual map. 现在,如果您的关卡都是彩色的,您可能需要构建一个黑色和白色的遮罩纹理,以反映实际地图的墙面。 Then use the coloured map for drawing and the bw map for collision detection. 然后使用彩色地图进行绘制,使用bw地图进行碰撞检测。

I'd spend a good solid couple weeks getting caught up on Objective-C, Xcode, Interface Builder, and Apple iOS documentation. 我花了几周的时间来了解Objective-C,Xcode,Interface Builder和Apple iOS文档。 There are many good tutorials out there and sample Xcode projects to download and run on the iPhone/iPad simulator. 有许多很好的教程,并在iPhone / iPad模拟器上下载和运行Xcode项目示例。

If just starting out, some of those quick startup libraries can rob you of the intimate knowledge you'll need to create the intricacies and nuances you'll need when your application starts to reach outside the boundaries of the code sandbox. 如果刚刚开始,那些快速启动库中的一些可能会剥夺您在应用程序开始到达代码沙箱边界之外时创建复杂性和细微差别所需的亲密知识。 Not bad to use as learning tools or to speed up development time, but I'd advise against using them as a crutch until you strengthen your developer legs. 可以用作学习工具或加快开发时间,但我建议不要使用它们作为拐杖,直到你加强你的开发人员的腿。 Crawl. 爬行。 Walk. 步行。 Run! 跑!

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

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