Note that there are some explanatory texts on larger screens.

plurals
  1. POJagged Edges in Cocos2D - Antialiasing Issue?
    primarykey
    data
    text
    <p>We're currently developing a game involving graphs (nodes connected by edges), and we want to be able to move the nodes around. We have the nodes moving (responding to touch), but when the edges (initialized with .png images) are re-rendered as a result of the nodes moving, they look jagged. We've tried playing around with Aliasing and Anti-Aliasing, but the edges are jagged regardless of what we do. </p> <p>Here's where we initialize the edge images (with image file):</p> <pre><code>-(id) initWithSet:(int)setNum Level:(int) levelNum { if( (self=[super init]) ) { &lt;code omitted&gt; for (NSArray *e in self.level.targetGraph) { &lt;code omitted&gt; 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; } </code></pre> <p>And here's where we update the edge drawings (using the second half of the nextFrame method):</p> <pre><code>- (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]; } } </code></pre> <p>We're using Cocos2D v2.0 and XCode v4.5.</p> <p>Any help would be greatly appreciated. Thank you!</p> <p>UPDATE: A picture showing the issue:</p> <p><img src="https://i.stack.imgur.com/6Zk9w.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload