iOS SpriteKit如何使笔画颜色透明?

我现在使用SpriteKit做一些简单的游戏。 绘画过程中有笔画颜色的问题。

我必须做我的彩色shapeNode透明,但我的笔触颜色保持不变每次。 我已经尝试了不同的技术来完成我的节点是完全透明的:1)将alpha组件设置为笔触颜色2)将alpha组件设置为整个节点。 它没有帮助。 有什么方法可以实现或解决这个问题吗?

创build我的节点

CGMutablePathRef arc = CGPathCreateMutable(); cardWidth = cardWidth + cardAlpha; CGPathAddRoundedRect(arc, NULL, CGRectMake(-cardWidth/2, -cardHeight/2, cardWidth, cardHeight), roundRadius, roundRadius); roundRect = [SKShapeNode node]; roundRect.name = self.name; CGFloat lineWidth = 2.0; CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, // the default 10); // 10 is default miter limit roundRect.path = strokedArc; [self addChild:roundRect]; 

然后我尝试改变颜色和不透明度

 roundRect.fillColor = rightColor; roundRect.strokeColor = rightColor; roundRect.strokeColor = rightColor; termLabel.fontColor = rightColor; roundRect.alpha = 0.5; 

我认为问题在于你的道路。 填充颜​​色覆盖你的行程,所以你看不到任何笔触颜色的变化。 但是用我的testing,node.alpha组件应该可以工作。 这可能是iOS版本的types,苹果可能会改变一些事情一起工作。

这里有一些代码可以玩:

  CGMutablePathRef arc = CGPathCreateMutable(); CGFloat cardWidth = 100; CGFloat cardHeight = 170; CGFloat roundRadius = 10; CGFloat r,g,b = 1; // color components CGRect rect = CGRectMake(-cardWidth/2, -cardHeight/2, cardWidth, cardHeight); CGPathAddRoundedRect(arc, NULL, rect, roundRadius, roundRadius); __block SKShapeNode *roundRect = [SKShapeNode node]; roundRect.name = @"card"; CGFloat lineWidth = 20.0; CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, // the default 10); // 10 is default miter limit roundRect.path = strokedArc; // roundRect.alpha = 0.3; // uncomment if want to use. [scene addChild:roundRect]; // delay SKAction *waitAction = [SKAction waitForDuration:1/15.0f]; // variables static CGFloat direction = 1; static CGFloat speed = .1f; static CGFloat alpha = 0; // action to aniamte shape SKAction *changeColorAction = [SKAction runBlock:^{ CGFloat vel = direction * speed; CGFloat newValue = alpha + vel; if(newValue < 0 || newValue > 1){ direction *= -1; } else { alpha = newValue; } UIColor *newColor = [UIColor colorWithRed:r green:g blue:b alpha:alpha]; // animate shape [roundRect setStrokeColor:newColor]; // [roundRect setFillColor:newColor]; // uncoment to animate. }]; // Did SKAction because its under the scene run loop. SKAction *seq = [SKAction sequence:@[ waitAction, changeColorAction ]]; [scene runAction:[SKAction repeatActionForever:seq]]; 
Interesting Posts