是否可以使用SpriteKit生成/绘制纹理?

and*_*y.s 7 ios sprite-kit

不能谷歌任何东西.实际上,关于这个新框架的信息很少.我唯一能找到的就是将Core Image滤镜应用于纹理.但我想在图像上方绘制一个简单的矩形,我需要编写自己的CI过滤器..

有人对主题有所了解吗?

Ben*_*aum 7

如果您只需要一个矩形,请使用@Kex的解决方案.

通常,您可以从任何UIImage或CGImage创建纹理.[SKTexture textureWithImageNamed:@"Spaceship.png"]真的只是一个方便[SKTexture textureWithImage:[UIImage imageNamed:@"Spaceship.png"]]

因此,要对纹理进行一些自定义绘制,您可以使用,例如:

UIGraphicsBeginImageContext(CGSizeMake(256, 256));
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[SKColor yellowColor] setFill];
CGContextFillEllipseInRect(ctx, CGRectMake(64, 64, 128, 128));

UIImage *textureImage = UIGraphicsGetImageFromCurrentImageContext();
SKTexture *texture = [SKTexture textureWithImage:textureImage];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithTexture:texture];

[self addChild:sprite];
Run Code Online (Sandbox Code Playgroud)

  • @Jonny因为这个问题用ios标记,所以它不需要在osx中​​也有效的解决方案.也就是说,我希望看到一个跨平台的解决方案作为答案添加,因为这对于参考是有用的. (2认同)