有没有办法在SpriteKit中创建一个渐变填充框?我已经尝试用它填充一个形状节点,但它注意到只有纯色与skshapenode一起使用.
这是一个解决方案.(注意,我正在使用Rubymotion,一个用于Objective C/iOS的ruby绑定,但逻辑完全相同.如果有人想编辑它并将目标c等效,请继续
size = CGSizeMake(50,50)
scale = options[:scale] || UIScreen.mainScreen.scale
opaque = options.fetch(:opaque, false)
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
context = UIGraphicsGetCurrentContext()
gradient = CAGradientLayer.layer
gradient.frame = CGRectMake(0,0,50,50)
gradient.colors = [SKColor.blackColor.CGColor,SKColor.whiteColor.CGColor]
gradient.renderInContext(context)
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
texture = SKTexture.textureWithCGImage(image.CGImage)
node = SKSpriteNode.alloc.initWithTexture(texture)
Run Code Online (Sandbox Code Playgroud)
我不认为这是可能的当前SKShapeNode,它目前几乎没有处理其基本功能.如果您不想使用预先存在的精灵渐变图像,那么一种好的方法是创建一个SKTexture从CIFilter(或许CILinearGradient在这种情况下)应用到基本盒子图像,然后SKSpriteNode从中创建SKTexture.
| 归档时间: |
|
| 查看次数: |
8060 次 |
| 最近记录: |