我通过SKShapeNode的纹理初始化并显示SKSpriteNode,该纹理具有代表圆的一部分的特定路径。下面是我使用游乐场生成的形状示例:
import SpriteKit
import PlaygroundSupport
let view = SKView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
let scene = SKScene(size: view.frame.size)
view.presentScene(scene)
let radius: CGFloat = view.frame.width * 0.40
var length: CGFloat = (.pi * 2.0) / 8.0
var width: CGFloat = radius / 5.0
var path: CGPath {
let path = UIBezierPath(arcCenter: view.center, radius: radius, startAngle: 0.0, endAngle: length, clockwise: true)
path.addArc(withCenter: view.center, radius: radius - width, startAngle: length, endAngle: 0.0, clockwise: false)
path.close()
return path.cgPath
}
let shapeNode = SKShapeNode(path: path)
shapeNode.fillColor = .white
let texture = view.texture(from: shapeNode)!
let spriteNode = SKSpriteNode(texture: texture, color: .white, size: texture.size())
spriteNode.position = CGPoint(x: shapeNode.frame.midX, y: shapeNode.frame.midY)
scene.addChild(spriteNode)
PlaygroundPage.current.liveView = view
这会产生这种形状:
我想添加一个小孩子SKSpriteNode,它位于弯曲节点的宽度和中间弧点的中心,如下所示:
我最接近的是使用spriteNode的位置:
let childNode = SKSpriteNode(color: .red, size: CGSize(width: 5, height: 5))
childNode.position = spriteNode.position
scene.addChild(childNode)
这会产生一些接近的东西,但它使用的是框架,这是完全错误的:
我假设我需要对弧线的路径做些什么,但我不确定如何做。有人能指出我正确的方向吗?
答案 0 :(得分:0)
感谢评论,我避免使用路径并刷新一些基本的触发来解决:
/****** Object: UserDefinedFunction [dbo].[BUSINESS_DURATION_MINTS_FN] Script Date: 10/17/2017 12:22:12 PM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[BUSINESS_DURATION_MINTS_FN]
(@string varchar(100) )
RETURNS INT
AS
BEGIN
DECLARE @total_mints INT
DECLARE @hours INT
DECLARE @Mints INT
IF @string IS NOT NULL
BEGIN
SET @string = REPLACE(UPPER(@string),'HOURS','HOUR')
SET @string = REPLACE(UPPER(@string),'MINUTES','MINUTE')
IF ((CHARINDEX(UPPER('HOUR'),UPPER(@string))!=0) AND (CHARINDEX(UPPER('MINUTE'),UPPER(@string))!= 0))
BEGIN
SET @hours = CONVERT(INT,SUBSTRING(@string,1, (CHARINDEX(UPPER('HOUR'), UPPER(@string))-2)))
SET @Mints = CONVERT(INT,SUBSTRING(@string,(CHARINDEX(UPPER('HOUR'),UPPER(@string))+4),(CHARINDEX(UPPER('MINUTE'),UPPER(@string))-(CHARINDEX(UPPER('HOUR'), UPPER(@string))+5))))
END
IF ((CHARINDEX(UPPER('HOUR'),UPPER(@string))=0) AND (CHARINDEX(UPPER('MINUTE'),UPPER(@string))!= 0))
BEGIN
SET @hours = 0
SET @Mints = CONVERT(INT,SUBSTRING(@string,1, (CHARINDEX(UPPER('MINUTE'), UPPER(@string))-2)))
END
IF ((CHARINDEX(UPPER('HOUR'),UPPER(@string))!=0) AND (CHARINDEX(UPPER('MINUTE'),UPPER(@string))=0))
BEGIN
SET @hours = CONVERT(INT,SUBSTRING(@string,1, (CHARINDEX(UPPER('HOUR'), UPPER(@string))-2)))
SET @Mints = 0
END
IF ((CHARINDEX(UPPER('HOUR'),UPPER(@string))= 0) AND (CHARINDEX(UPPER('MINUTE'),UPPER(@string))=0))
BEGIN
SET @hours = 0
SET @Mints = 0
END
SET @total_mints = @hours*60 + @Mints
END
IF @string IS NULL
BEGIN
SET @total_mints = NULL
END
RETURN @total_mints
END
GO