Sprite kit and colorWithPatternImage

后端 未结 3 1744
傲寒
傲寒 2020-11-29 11:32

Do we have any way of repeating an image across an area, like a SKSpriteNode? SKColor colorWithPatternImage doesn\'t work unfortunately.

Edit:

I

3条回答
  •  甜味超标
    2020-11-29 12:24

    iOS working code:

    CGRect textureSize = CGRectMake(0, 0, 488, 650);
    CGImageRef backgroundCGImage = [UIImage imageNamed:@"background.png"].CGImage;
    
    UIGraphicsBeginImageContext(self.level.worldSize); // use WithOptions to set scale for retina display
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawTiledImage(context, textureSize, backgroundCGImage);
    UIImage *tiledBackground = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    SKTexture *backgroundTexture = [SKTexture textureWithCGImage:tiledBackground.CGImage];
    SKSpriteNode *backgroundNode = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
    [self addChild:backgroundNode];
    

提交回复
热议问题