How to create a Gradient in Spritekit?

前端 未结 4 726
长发绾君心
长发绾君心 2021-02-08 22:35

Is there any possible way to create a gradient filled box in SpriteKit? I\'ve tried filling a shape node with that but it notes that only solid colors work with skshapenode.

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-08 23:04

    OK here is something I am using now. I based it on AwDogsGo2Heaven's solution, however adapted for Mac. Would be sweet with one fully compatible solution. I am far from sure how to create contexts. But seems to work. Also I am unsure about the scale. Running on retina mac and non retina mac and can't see any problems but the context is created using scale 2 so might be overkill for non retina macs. I put this in a category on SKTexture.

    In order use it, just call +(SKTexture*)gradientWithSize:(const CGSize)SIZE colors:(NSArray*)colors.

    Edit: Updated code and more discussion here: Gradient texture has wrong scale on retina Mac

提交回复
热议问题