本文介绍了如何在 Sprite-kit 中画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Sprite-kit 中画一条线?例如,如果我想在 cocos2d 中画一条线,我可以很容易地使用 ccDrawLine();
How can one draw a line in Sprite-kit? For example if I want to draw a line in cocos2d, I could easily using ccDrawLine();
在 sprite-kit 中是否有等价物?
Is there an equivalent in sprite-kit?
推荐答案
Using SKShapeNode 你可以画线或任何形状.
Using SKShapeNode you can draw line or any shape.
SKShapeNode *yourline = [SKShapeNode node];
CGMutablePathRef pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, 100.0, 100.0);
CGPathAddLineToPoint(pathToDraw, NULL, 50.0, 50.0);
yourline.path = pathToDraw;
[yourline setStrokeColor:[SKColor redColor]];
[self addChild:yourline];
相当于 Swift 4:
var yourline = SKShapeNode()
var pathToDraw = CGMutablePath()
pathToDraw.move(to: CGPoint(x: 100.0, y: 100.0))
pathToDraw.addLine(to: CGPoint(x: 50.0, y: 50.0))
yourline.path = pathToDraw
yourline.strokeColor = SKColor.red
addChild(yourline)
这篇关于如何在 Sprite-kit 中画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!