2014-10-28 7 views
1

나는 SpriteKit을 사용하여 간단한 게임을하고 있습니다. 드로잉 프로세스에서 획 색상과 관련된 한 가지 문제가 있습니다.iOS SpriteKit 획 색상을 투명하게 만드는 방법은 무엇입니까?

색이 뚜렷한 모양의 노드를 투명하게 처리해야하지만 내 획 색상은 항상 동일하게 유지됩니다. 나는 노드를 완전히 투명하게하기 위해 여러 가지 기술을 시도했다. 1) 획 색상에 알파 컴포넌트 설정 2) 알파 노드를 전체 노드에 설정. 도움이되지 않았다. 이 문제를 해결할 수있는 방법이 있습니까? 내 노드

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; 
+0

: 여기

는 함께 플레이하는 몇 가지 코드입니다. 이것이 실제로 문제가되는지 확인하기 위해 장치를 테스트하십시오. – meisenman

+0

@ meisenman 저에게 대답 해 주셔서 감사합니다. 나는 이미 끝났어. 내 iPhone에서 화면이 있지만 여기에 내 평판에 따라 화면을 추가 할 수 없습니다. – user2903218

+0

블렌드 모드는 무엇입니까? SKBlendModeAlpha 여야합니다. 모양 노드와 관련된 코드를 게시하십시오. –

답변

2

을 변경하려고합니다. 채우기 색상이 스토크를 덮고 있으므로 스트로크 색상이 변경되지 않습니다. 그러나 테스트를 통해 node.alpha 구성 요소가 작동해야합니다. 아마도 iOS 버전의 유형 일 수 있습니다. Apple은 일부 기능이 함께 작동하는 방식을 바꿀 수 있습니다. 단지 시뮬레이터와 테스트, ShapeNodes 뇌졸중 알려진 문제가있는 경우

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]];