2

我们目前正在开发一个涉及图形(由边连接的节点)的游戏,我们希望能够移动节点。我们让节点移动(响应触摸),但是当边缘(用 .png 图像初始化)由于节点移动而重新渲染时,它们看起来是锯齿状的。我们尝试过使用 Aliasing 和 Anti-Aliasing,但无论我们做什么,边缘都是锯齿状的。

这是我们初始化边缘图像的地方(带有图像文件):

-(id) initWithSet:(int)setNum Level:(int) levelNum
{
    if( (self=[super init]) ) {

           <code omitted>

           for (NSArray *e in self.level.targetGraph) {

               <code omitted>

               CCSprite *edgeOutline = [CCSprite spriteWithFile:@"EdgeOutline.png"];
               [edgeOutline setPosition:ccp((ax+bx)/2, (ay+by)/2)];
               edgeOutline.scaleX = (dist * edgeOutline.scaleX)/edgeOutline.contentSize.width;
               edgeOutline.scaleY = (self.nodeSize * 0.5 * edgeOutline.scaleY)/edgeOutline.contentSize.height;
               edgeOutline.rotation = -angle;
               [outlines addChild:edgeOutline];

               CCSprite *edgeFill = [CCSprite spriteWithFile:@"EdgeFill.png"];
               [edgeFill setPosition:ccp((ax+bx)/2, (ay+by)/2)];
               edgeFill.scaleX = (dist * edgeFill.scaleX)/edgeFill.contentSize.width;
               edgeFill.scaleY = (self.nodeSize * 0.4 * edgeFill.scaleY)/edgeFill.contentSize.height;
               edgeFill.rotation = -angle;
               [fills addChild:edgeFill];

         }

  return self;
}

这里是我们更新边缘图的地方(使用 nextFrame 方法的后半部分):

- (void) nextFrame:(ccTime)dt {

    for (NSArray *e in self.level.graph) {
        CCSprite *a = [self.graphNodeOutlines objectForKey:[e objectAtIndex:0]];
        double ax = a.position.x;
        double ay = a.position.y;
        CCSprite *b = [self.graphNodeOutlines objectForKey:[e objectAtIndex:1]];
        double bx = b.position.x;
        double by = b.position.y;

        double dx = ax-bx;
        double dy = ay-by;
        double angle = 90;
        if (dx != 0) {
            angle = atan2(ay-by, ax-bx)*180/M_PI;
        }
        double dist = sqrt(dx*dx+dy*dy);

        //TODO: get anti-aliasing to work in this next part!

        CCSprite *edgeOutline = [self.graphEdgeOutlines objectForKey:e];
        [edgeOutline setPosition:ccp((ax+bx)/2, (ay+by)/2)];
        edgeOutline.scaleX = (dist)/edgeOutline.contentSize.width;
        edgeOutline.scaleY = (self.nodeSize * 0.25)/edgeOutline.contentSize.height;
        edgeOutline.rotation = -angle;

        //The line we hoped would fix the jagged edge problem.
        [[edgeOutline texture] setAntiAliasTexParameters];

        CCSprite *edgeFill = [self.graphEdgeFills objectForKey:e];
        [edgeFill setPosition:ccp((ax+bx)/2, (ay+by)/2)];
        edgeFill.scaleX = (dist)/edgeFill.contentSize.width;
        edgeFill.scaleY = (self.nodeSize * 0.2)/edgeFill.contentSize.height;
        edgeFill.rotation = -angle;

        //The (same) line we hoped would fix the jagged edge problem.
        [[edgeFill texture] setAntiAliasTexParameters];

    }
}

我们使用的是 Cocos2D v2.0 和 XCode v4.5。

任何帮助将不胜感激。谢谢!

更新:显示问题的图片:

在此处输入图像描述

4

1 回答 1

0

我有办法!按照本教程的“添加 MainWindow.xib”部分:http ://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit

不知何故,将一些图形职责交给 UIKit 解决了这个问题。雷是我的救星。

编辑:这似乎只能解决 ipad 上的问题。不知道为什么。

编辑2:忽略所有这些;所有抗锯齿都与模拟器缩放有关。相反,请帮我弄清楚这篇文章的含义: http: //www.cocos2d-iphone.org/forum/topic/4773

于 2013-01-21T01:26:22.060 回答