CCNode-visit-function 复制了 CCSprite 有暗边

发布于 2024-12-10 00:19:58 字数 978 浏览 0 评论 0原文

我有一个关于CCNode的[访问]功能的问题

原图很好,轮廓清晰,没什么特别的,里面是由5个叶子精灵组成。

屏幕截图:

http://farm7.static.flickr.com/6107/6248992365_eab5346264_o.png

然后我想使用 [访问CCNode]复制它。

这是代码

-(CCSprite *)flattenSprite:(CCSprite*)sprite textureSize:(float)textureSize {

    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
    [rt begin];

    // store the original sprite position
    CGPoint p=sprite.position;
    //set original sprite to a target point for open GL to "visit"
    sprite.position=ccp(textureSize/2,textureSize/2);
    // open GL visit
    [sprite visit];
    //original sprite return to original point
    sprite.position=p;

    [rt end];
    return [CCSprite spriteWithTexture:rt.sprite.texture];
}

通过这个函数,我可以通过限制舞台上存在的精灵数量来优化应用程序的性能,但“复制的精灵”周围有一个黑暗的边缘。它看起来很奇怪 - 特别是当精灵彼此重叠时。

请告诉我您是否有任何线索/在任何地方获得有关此黑暗边缘问题的有用信息

I've got a question about the [visit] function of CCNode

The original image is good with clear outline, nothing special, it composes of 5 leaves sprites inside.

SCREEN CAPTURE :

http://farm7.static.flickr.com/6107/6248992365_eab5346264_o.png

Then I want to use [CCNode visit] to copy it.

And here's the code

-(CCSprite *)flattenSprite:(CCSprite*)sprite textureSize:(float)textureSize {

    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
    [rt begin];

    // store the original sprite position
    CGPoint p=sprite.position;
    //set original sprite to a target point for open GL to "visit"
    sprite.position=ccp(textureSize/2,textureSize/2);
    // open GL visit
    [sprite visit];
    //original sprite return to original point
    sprite.position=p;

    [rt end];
    return [CCSprite spriteWithTexture:rt.sprite.texture];
}

By this function I can optimize the performance of the application by limiting the amount of the sprites existing on stage but the "copied sprites" got a dark edge around it. It looks weird - especially when the sprites are overlapping each others.

Please tell me if you have any clues / anywhere got useful information about this dark edge issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2024-12-17 00:19:58
-(CCSprite *)flattenSprite:(CCSprite*)sprite textureSize:(float)textureSize {

    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
    [rt begin];

    // store the original sprite position
    CGPoint p=sprite.position;
    //set original sprite to a target point for open GL to "visit"
    sprite.position=ccp(textureSize/2,textureSize/2);
    // open GL visit
    [sprite visit];
    //original sprite return to original point
    sprite.position=p;

    [rt end];

    CCSprite *renderSprite = [CCSprite spriteWithTexture:rt.sprite.texture];
    //this will solve the dark edge problem
    [sprite setBlendFunc: (ccBlendFunc) { GL_ONE, GL_ONE_MINUS_SRC_ALPHA }];

    return renderSprite;
}
-(CCSprite *)flattenSprite:(CCSprite*)sprite textureSize:(float)textureSize {

    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
    [rt begin];

    // store the original sprite position
    CGPoint p=sprite.position;
    //set original sprite to a target point for open GL to "visit"
    sprite.position=ccp(textureSize/2,textureSize/2);
    // open GL visit
    [sprite visit];
    //original sprite return to original point
    sprite.position=p;

    [rt end];

    CCSprite *renderSprite = [CCSprite spriteWithTexture:rt.sprite.texture];
    //this will solve the dark edge problem
    [sprite setBlendFunc: (ccBlendFunc) { GL_ONE, GL_ONE_MINUS_SRC_ALPHA }];

    return renderSprite;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文