【问题标题】:Draw a frame in Spritekit在 Spritekit 中画一个框架
【发布时间】:2014-05-02 21:08:38
【问题描述】:

我想画一个如下图所示的框架,其中圆圈内的白色部分是清晰的(透明),以便我可以看到背景中的场景,而灰色部分是不透明的。 我查看了CropNodes,但没有找到答案。所有内容都应添加到最后的SKView

【问题讨论】:

  • 如果灰色部分是看不见的,你会看到它背后的东西吗?!
  • 哦我想说它是不透明的,白色的部分是透明的。
  • 您确实提到了SKCropNode,请添加您到目前为止尝试过的代码,

标签: ios7 sprite-kit crop


【解决方案1】:
this method works you can filter it more i am using shape node you can your texture shape node having some memory leaks in sprite kit

   #import "milkhuntMyScene.h"

   @implementation milkhuntMyScene

   -(id)initWithSize:(CGSize)size {
       if (self = [super initWithSize:size]) {
        /* Setup your scene here */

        [self maskMe];

      }
     return self;
   }
   -(void)maskMe
   {
       //replace tomask to 1 pixel background and 778 width or acc to ur game
       // SKSpriteNode *whiteArea = [SKSpriteNode   spriteNodeWithImageNamed:@"pixel1.png"];
    //[self addChild: whiteArea];
    //whiteArea.xScale=1024;

    SKSpriteNode *toMask = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:     CGSizeMake(2024, 778*2)];
    SKSpriteNode *mask = [SKSpriteNode spriteNodeWithImageNamed:@"maskarea.png"];
    mask.position=CGPointMake(400, 300);
    //
    CGRect circle = CGRectMake(0, 0,mask.frame.size.width,mask.frame.size.height);
    SKShapeNode *shapeNode = [[SKShapeNode alloc] init];
    shapeNode.path = [UIBezierPath bezierPathWithOvalInRect:circle].CGPath;
    shapeNode.fillColor = SKColor.yellowColor;
    shapeNode.strokeColor = [SKColor blueColor];
    shapeNode.lineWidth=20;
    shapeNode.position=CGPointMake(mask.position.x/2, 100);
    [self addChild:shapeNode];

    //
    SKCropNode *cropNode = [SKCropNode node];
    [cropNode addChild: toMask];
    [cropNode setMaskNode: mask];
    [self addChild: cropNode];


   }
   -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       /* Called when a touch begins */

   }

   -(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
   }

   @end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多