<i id='9yacL'><tr id='9yacL'><dt id='9yacL'><q id='9yacL'><span id='9yacL'><b id='9yacL'><form id='9yacL'><ins id='9yacL'></ins><ul id='9yacL'></ul><sub id='9yacL'></sub></form><legend id='9yacL'></legend><bdo id='9yacL'><pre id='9yacL'><center id='9yacL'></center></pre></bdo></b><th id='9yacL'></th></span></q></dt></tr></i><div id='9yacL'><tfoot id='9yacL'></tfoot><dl id='9yacL'><fieldset id='9yacL'></fieldset></dl></div>

      <legend id='9yacL'><style id='9yacL'><dir id='9yacL'><q id='9yacL'></q></dir></style></legend>
        <tfoot id='9yacL'></tfoot>
      1. <small id='9yacL'></small><noframes id='9yacL'>

        • <bdo id='9yacL'></bdo><ul id='9yacL'></ul>

        CCSprite 上的白色叠加

        White color overlay on CCSprite(CCSprite 上的白色叠加)

        <small id='CwicS'></small><noframes id='CwicS'>

        <tfoot id='CwicS'></tfoot>
        <i id='CwicS'><tr id='CwicS'><dt id='CwicS'><q id='CwicS'><span id='CwicS'><b id='CwicS'><form id='CwicS'><ins id='CwicS'></ins><ul id='CwicS'></ul><sub id='CwicS'></sub></form><legend id='CwicS'></legend><bdo id='CwicS'><pre id='CwicS'><center id='CwicS'></center></pre></bdo></b><th id='CwicS'></th></span></q></dt></tr></i><div id='CwicS'><tfoot id='CwicS'></tfoot><dl id='CwicS'><fieldset id='CwicS'></fieldset></dl></div>

                <legend id='CwicS'><style id='CwicS'><dir id='CwicS'><q id='CwicS'></q></dir></style></legend>

                  <bdo id='CwicS'></bdo><ul id='CwicS'></ul>
                    <tbody id='CwicS'></tbody>
                  本文介绍了CCSprite 上的白色叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在我的 CCSprite 上应用某种颜色叠加".基本上,将其完全染成白色.

                  I'd like to apply some kind of "color overlay" over a CCSprite of mine. Basically, tint it completely white.

                  我可以使用

                  mySprite.color = ccc3(0,0,0);
                  

                  我的精灵得到了黑色覆盖.然而,

                  And my sprite gets a black color overlay. However,

                  mySprite.color = ccc3(255,255,255);
                  

                  自然不会影响我的精灵.相反,我的精灵保持原来的颜色.

                  Will, naturally, not affect my sprite. Instead, my sprite keeps its original color.

                  那么,还有其他方法可以实现吗?我真的负担不起为我所有的动画/精灵等制作白色版本.

                  So, is there another method to achieve such? I really can't afford to make a white version of all my animations/sprites etc.

                  推荐答案

                  您可以将此灰度代码转换为白色或任何颜色http://www.cocos2d-iphone.org/forum/topic/10227#post-58662

                  you can convert this grayscale code to do white or any color http://www.cocos2d-iphone.org/forum/topic/10227#post-58662

                  UIImage *convertToColor(UIImage *source, ccColor3B color)
                  {
                      CGSize size = [source size];
                      int width = size.width;
                      int height = size.height;
                  
                      // the pixels will be painted to this array
                      uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
                  
                      // clear the pixels so any transparency is preserved
                      memset(pixels, 0, width * height * sizeof(uint32_t));
                  
                      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
                  
                      // create a context with RGBA pixels
                      CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
                  
                      // paint the bitmap to our context which will fill in the pixels array
                      CGContextDrawImage(context, CGRectMake(0, 0, width, height), source.CGImage);
                  
                      for(int y = 0; y < height; y++) {
                          for(int x = 0; x < width; x++) {
                              uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x];
                  
                              // convert to grayscale using recommended method: http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
                              uint32_t gray = 0.3 * rgbaPixel[rgbaRED] + 0.59 * rgbaPixel[rgbaGREEN] + 0.11 * rgbaPixel[rgbaBLUE];
                  
                              // set the pixels to white
                              if (gray > 0)
                              {
                                  rgbaPixel[rgbaRED] = color.r;
                                  rgbaPixel[rgbaGREEN] = color.g;
                                  rgbaPixel[rgbaBLUE] = color.b;
                              }
                          }
                      }
                  
                      // create a new CGImageRef from our context with the modified pixels
                      CGImageRef image = CGBitmapContextCreateImage(context);
                  
                      // we're done with the context, color space, and pixels
                      CGContextRelease(context);
                      CGColorSpaceRelease(colorSpace);
                      free(pixels);
                  
                      // make a new UIImage to return
                      UIImage *resultUIImage = [UIImage imageWithCGImage:image];
                  
                      // we're done with image now too
                      CGImageRelease(image);
                  
                      return resultUIImage;
                  }
                  CCSprite *colorSprite(CCSprite *sprite, ccColor3B color)
                  {
                      UIImage *image = convertSpriteToImage(sprite);
                      UIImage *white = convertToColor(image, color);
                      CCTexture2D *texture = [[CCTexture2D alloc] initWithImage:white];
                      CCSprite *newSprite = [CCSprite spriteWithTexture:texture];
                      return newSprite;
                  }
                  UIImage *convertSpriteToImage(CCSprite *sprite)
                  {
                      sprite.scale = 1.0f;
                      sprite.position = ccp(sprite.contentSize.width / 2, sprite.contentSize.height / 2);
                  
                      CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:sprite.contentSize.width height:sprite.contentSize.height];
                      [renderer begin];
                      [sprite visit];
                      [renderer end];
                  
                      return [UIImage imageWithData:[renderer getUIImageAsDataFromBuffer:kCCImageFormatPNG]];
                  }
                  

                  这篇关于CCSprite 上的白色叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  <i id='wMQCI'><tr id='wMQCI'><dt id='wMQCI'><q id='wMQCI'><span id='wMQCI'><b id='wMQCI'><form id='wMQCI'><ins id='wMQCI'></ins><ul id='wMQCI'></ul><sub id='wMQCI'></sub></form><legend id='wMQCI'></legend><bdo id='wMQCI'><pre id='wMQCI'><center id='wMQCI'></center></pre></bdo></b><th id='wMQCI'></th></span></q></dt></tr></i><div id='wMQCI'><tfoot id='wMQCI'></tfoot><dl id='wMQCI'><fieldset id='wMQCI'></fieldset></dl></div>

                    • <legend id='wMQCI'><style id='wMQCI'><dir id='wMQCI'><q id='wMQCI'></q></dir></style></legend>

                            <tbody id='wMQCI'></tbody>
                        • <tfoot id='wMQCI'></tfoot>

                          <small id='wMQCI'></small><noframes id='wMQCI'>

                            <bdo id='wMQCI'></bdo><ul id='wMQCI'></ul>