如何绘制两种不同颜色的空心圆? [英] How to draw a hollow circle with two different colors?

查看:201
本文介绍了如何绘制两种不同颜色的空心圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对绘制一个填充的createEllipseInRect形状节点非常熟悉,但是我想知道是否存在以编程方式进行此操作的方法.我想要一个通过多数民众赞成在中间有两个单独的颜色的圆圈.我没有代码,因为我不知道从哪里开始.

Im very familiar with drawing a filled createEllipseInRect shape node, but I was wondering if there's a way to do this programmatically. I want a circle thats split through the center with two separate colors on either side. I don't have code since I have no idea where to start with this.

类似的东西

非常感谢您的帮助.

推荐答案

您可以尝试使用SKCropNode,这仅可以显示每个圆圈的一半.有关示例,请参见下面的代码.

You can try using SKCropNode, this allows you to show only half of each circle. See below code for example of this.

class GameScene: SKScene {
override func didMoveToView(view: SKView) {

    anchorPoint = CGPointMake(0.5, 0.5)

    // Half Circle #1

    let myCrop1 = SKCropNode()

    let myMask1 = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
    myMask1.position.y = -50

    let circle1 = SKShapeNode(circleOfRadius: 50)
    circle1.lineWidth = 0
    circle1.fillColor = UIColor.blueColor()

    myCrop1.addChild(circle1)
    myCrop1.maskNode = myMask1
    addChild(myCrop1)

    // Half Circle #2

    let myCrop2 = SKCropNode()

    let myMask2 = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
    myMask2.position.y = 50

    let circle2 = SKShapeNode(circleOfRadius: 50)
    circle2.lineWidth = 0
    circle2.fillColor = UIColor.redColor()

    myCrop2.addChild(circle2)
    myCrop2.maskNode = myMask2
    addChild(myCrop2)


    }

}

我之前还没有真正使用过SKCropNode,所以我不确定我的代码有多好,但是下面是我在iPhone上得到的结果.

I haven't really used SKCropNode that much before, so I'm not sure how good my code is, but below is the result I got on my iPhone.

如果需要,您应该能够添加第三个SKCropNode以使圆心透明.

You should be able to add a 3rd SKCropNode to make the centre of the circle transparent if required.

下面是透明的中心

class GameScene: SKScene {
override func didMoveToView(view: SKView) {

    anchorPoint = CGPointMake(0.5, 0.5)

    let transparentCenterMask = SKShapeNode(circleOfRadius: 50)
    transparentCenterMask.lineWidth = 20
    let transparentCenterCrop = SKCropNode()
    transparentCenterCrop.maskNode = transparentCenterMask

    // Half Circle #1

    let myCrop1 = SKCropNode()

    let myMask1 = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
    myMask1.position.y = -50

    let circle1 = SKShapeNode(circleOfRadius: 50)
    circle1.lineWidth = 0
    circle1.fillColor = UIColor.blueColor()

    myCrop1.addChild(circle1)
    myCrop1.maskNode = myMask1
    transparentCenterCrop.addChild(myCrop1)

    // Half Circle #2

    let myCrop2 = SKCropNode()

    let myMask2 = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
    myMask2.position.y = 50

    let circle2 = SKShapeNode(circleOfRadius: 50)
    circle2.lineWidth = 0
    circle2.fillColor = UIColor.redColor()

    myCrop2.addChild(circle2)
    myCrop2.maskNode = myMask2
    transparentCenterCrop.addChild(myCrop2)

    addChild(transparentCenterCrop)


    }

}

这篇关于如何绘制两种不同颜色的空心圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆