简体   繁体   English

简单的颜色图问题

[英]simple color map question

I have a UIImage. 我有一个UIImage。 There are 3 colors, white (=sky), black (=player) and green (=floor). 有3种颜色,白色(=天空),黑色(= player)和绿色(= floor)。 When the black player collides with the white sky only, i make him fall down. 当黑人球员仅与白色天空碰撞时,我让他摔倒。 When he collides with the white sky AND with the green floor, i stop him. 当他与白色的天空和绿色的地板碰撞时,我阻止了他。

The Image: http://img39.imageshack.us/img39/4290/colormapb.jpg 图片: http//img39.imageshack.us/img39/4290/colormapb.jpg

Now my question: How can i read the colours and make the player colliding with it? 现在我的问题是:我该如何读取颜色并使播放器与之碰撞?

The programmers of 30 day game made the color map collision too. 30天游戏的程序员也使颜色图发生冲突。

thanks, domp 谢谢你

Is the layout random? 布局是随机的吗? If not, just make a list of the bounding boxes of the "fall" areas, and check the black "player" box against that list of "fall" boxes. 如果不是,则仅列出“ fall”区域的边界框,然后对照该“ fall”框列表选中黑色的“ player”框。

Let's say you are storing your full list of "fall" boxes in a C array "fallBoxes" with size fallBoxCount. 假设您将“ fall”框的完整列表存储在大小为fallBoxCount的C数组“ fallBoxes”中。 // You could use an NSArray but the code is easier this way. //您可以使用NSArray,但是这种方式使代码更容易。

// playerBox is the rect for the current position of the black "player" box.

for (int i = 0; i < fallBoxCount; ++i)
{
    CGRect testBox = fallBox[i];
    if (CGRectContainsRect(textBox, playerBox)
    {
        // Fall!
        break;
    }
}

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

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