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

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

问题描述

我可以使用简单的 SKSpriteNode 绘制矩形.但我无法在其中绘制其他类型的图纸,例如具有两种分色的三角形、圆形等.有人建议使用 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 在 sprite kit 中绘制形状,但每个 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.

但是,您可以创建一个自定义 SKNode 子类,其中包含两个 SKShapeNode 作为子节点,每个子节点具有不同的 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天全站免登陆