首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >幕布透视图

幕布透视图
EN

Stack Overflow用户
提问于 2015-03-04 22:33:53
回答 1查看 169关注 0票数 0

我试图达到以下挑战性的效果:我想移动白色的“窗帘”下来,以揭示红色的盒子。(注意:幕布下面的屏幕截图是白色,背景是灰色的)

问题在于视图层次结构。

为了使盒子隐藏在最初的位置,它必须放在窗帘的后面,但是为了在最后的位置显示,它必须在窗帘的顶部。

我怎么能“欺骗”,使它看起来像窗帘真正揭示了一个流畅的动画盒子?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-04 23:15:17

你需要两个图像和一个面具。完全模糊的灰色区域和白色背景的盒子。你的窗帘的形象只是底边的面具。这样就可以画出窗帘的底边,而不会抹掉灰色的重叠区域。

在顶部设置一个起始位置,每个框架:只绘制/复制窗帘掩模的大小,通过窗帘掩模复制相应的红色框区域。将起始位置移到一条扫描线上,等待下一帧。重复直到完成。

本质上,没有白色窗帘,只有什么是揭示的“隐藏”图像,其中包含白色背景的盒子。根据您的绘制方式,您的掩码图像可能是另一个带有alpha通道的图像。

编辑:根据要求,一些示例代码。然而,很有可能的是,无论你用什么来获取屏幕上的图形,都已经有了带有掩蔽的绘图例程,你最好使用它。这个片段是未经测试的,但是应该提供逻辑,并且可以在任何地方工作。我不熟悉iOS,也不知道你的图像像素是什么格式,24位,32位等等,并使用"PixelType“作为替代。

这也假设白色窗帘边缘的黑色背景是作为一个8位图像在油漆程序,而黑色是零和白色任何其他东西。它应该是相同的宽度与其他两幅图像,只有高度需要的幕墙边缘。

代码语言:javascript
复制
 `struct  Mask     {         char *mData;    // set this to the image data of your 8 bit mask         int  mWidth;    // width in pixels, should be the same as your 2 images         int  mHeight;   // height in pixels of the mask     };     int iRevealPos = 0; // increment each frame value until box is revealed.     // Hopefully, your pixel type is a basic type like byte, short or int.     void Reveal(PixelType *foreground, PixelType *background, Mask *mask)     {         int height  = (iRevealPos < mask->mHeight) ? iRevealPos : mask->mHeight; // account for initial slide in         PixelType   *src    = background + (iRevealPos * mask->mWidth); // background box at current reveal position         PixelType   *dst    = foreground + (iRevealPos * mask->mWidth); // matching foreground screen position         int         count   = mask->mWidth * height;         char        *filter = mask->mData;         if ((iRevealPos < mask->mHeight))   // adjust for initial slide in             filter  +=  (mask->mHeight - iRevealPos) * mask->mWidth;         while (count--)         {             if (*filter++)  // not black?                 *dst++  = *src++;   // copy the box image             else        // skip this pixel             {                 src++;                 dst++;             }         }         // if you create your mask with a solid white line at the top, you don't need this         if (iRevealPos > mask->mHeight) // fixup, so the mask doesn't leave a trail         {             src     = background + ((iRevealPos-1) * mask->mWidth);             dst     = foreground + ((iRevealPos-1) * mask->mWidth);             count   = mask->mWidth;             while (count--)                 *dst++  = *src++;         }         iRevealPos++;   // bump position for next time     }`  If you create your mask with a solid white line or 2 at the top you don't need the second loop which fixes up any trail the mask leaves behind. I also allowed for the curtain to slide in rather than fully pop in at the start. This is untested so I may have got the adjustments for this wrong.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28866441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档