用两种颜色在Spritekit中绘制矩形/圆形和三角形。 。 。 [英] Draw Rectangle/ Circle and Triangle in Spritekit with Two Colors. . .

查看:162
本文介绍了用两种颜色在Spritekit中绘制矩形/圆形和三角形。 。 。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用简单的SKSpriteNode绘制Rectangle。但我无法在其中绘制其他类型的图纸,如Triangle,Circle等,具有TWO SPLIT COLORS。有人建议和CGPath一起去。但我是新手,不知道画这种复杂的东西。任何人都可以通过SPRITEKIT中的MULTICOLOR说明这些图纸的简单方法。意思是它们的上部是一种颜色,而下部是第二种颜色。更简洁地说,Shape分为两种颜色,无论是星形,矩形,三角形还是其他颜色。
任何帮助将不胜感激。

I can draw Rectangle using simple SKSpriteNode. But i can not draw other types of drawings in it like Triangle, Circle etc with TWO SPLIT COLORS. Someone suggested to go with CGPath. But i am newbie and dont know to draw such type of complex things . Please can anyone illustrate simple way to go with these drawings with MULTICOLOR in SPRITEKIT. Mean their upper part is one color and lower part in 2nd color. More concise to say that Shape is divided into two colors whether that is star, rectangle, triangle or else. Any Help will be greatly appreciated.

谢谢。

推荐答案

您可以使用SKShapeNode绘制形状精灵套件,但每个SKShapeNode仅限于一种颜色(strokeColor)和一种填充颜色。

You can use SKShapeNode to draw shapes in sprite kit, but each SKShapeNode is limited to one line color (strokeColor) and one fill color.

但是,您可以创建一个包含两个SKShapeNodes作为子项的自定义SKNode子类,每个都有不同的strokeColors / fillColors。

However, you can create a custom SKNode subclass that contains two SKShapeNodes as children, each with different strokeColors/fillColors.

这样的东西适用于绘制方形的左边和顶部红色,右边和底部绿色的自定义SKNode:

Something like this will work for a custom SKNode that draws a square with left and top red, right and bottom green:

- (id) init {
    if (self = [super init]) {
        SKShapeNode* topLeft = [SKShapeNode node];
        UIBezierPath* topLeftBezierPath = [[UIBezierPath alloc] init];
        [topLeftBezierPath moveToPoint:CGPointMake(0.0, 0.0)];
        [topLeftBezierPath addLineToPoint:CGPointMake(0.0, 100.0)];
        [topLeftBezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
        topLeft.path = topLeftBezierPath.CGPath;
        topLeft.lineWidth = 10.0;
        topLeft.strokeColor = [UIColor redColor];
        topLeft.antialiased = NO;
        [self addChild:topLeft];

        SKShapeNode* bottomRight = [SKShapeNode node];
        UIBezierPath* bottomRightBezierPath = [[UIBezierPath alloc] init];
        [bottomRightBezierPath moveToPoint:CGPointMake(0.0, 0.0)];
        [bottomRightBezierPath addLineToPoint:CGPointMake(100.0, 0.0)];
        [bottomRightBezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
        bottomRight.path = bottomRightBezierPath.CGPath;
        bottomRight.lineWidth = 10.0;
        bottomRight.strokeColor = [UIColor greenColor];
        bottomRight.antialiased = NO;
        [self addChild:bottomRight];
    }
    return self;
}

这篇关于用两种颜色在Spritekit中绘制矩形/圆形和三角形。 。 。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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