gpt4 book ai didi

swift - SpriteKit PhysicsBody 没有应用我的贝塞尔曲线

转载 作者:行者123 更新时间:2023-11-28 07:16:09 25 4
gpt4 key购买 nike

测试代码如下:

var paths = UIBezierPath()
var bottomLeft = CGPoint(x: dim.minX, y:dim.minY)
var bottomRight = CGPoint(x: dim.maxX , y: dim.minY )
var topRight = CGPoint(x: dim.maxX, y: dim.maxY )
var topLeft = CGPoint(x: dim.minX, y: dim.maxY)


paths.moveToPoint(bottomRight)
paths.addLineToPoint(topRight)

paths.moveToPoint(topRight)
paths.addLineToPoint(topLeft)

paths.moveToPoint(topLeft)
paths.addLineToPoint(bottomLeft)

paths.moveToPoint(bottomLeft)
paths.addLineToPoint(bottomRight)


var n = SKShapeNode(path: paths.CGPath)
n.strokeColor = UIColor.greenColor()
n.physicsBody = SKPhysicsBody(edgeLoopFromPath: paths.CGPath)
shapeLayer.addChild(n)

它绘制了一个标准的矩形。我将在从右上角到左上角点的中间添加一些曲线,但我想用简单的矩形来测试它。我正在测试与球的碰撞,它似乎只与从 bottomRight 到 topRight 的线发生碰撞,而忽略了其余部分。有谁知道这里发生了什么?

Physic issue: Physics is not applied fully to middle rectangle in gray

最佳答案

虽然我不确定贝塞尔路径的问题和所需的物理碰撞设置代码,但是我能够使用原始路径和添加行让它工作:

    var polygonPath = CGPathCreateMutable()
CGPathMoveToPoint(polygonPath, nil, bottomRight.x, bottomRight.y)
CGPathAddLineToPoint(polygonPath, nil, topRight.x, topRight.y)
CGPathAddLineToPoint(polygonPath, nil, topLeft.x, topLeft.y)
CGPathAddLineToPoint(polygonPath, nil, bottomLeft.x, bottomLeft.y)
CGPathCloseSubpath(polygonPath)

var n = SKShapeNode(path: polygonPath)
n.strokeColor = UIColor.grayColor()
n.physicsBody = SKPhysicsBody(edgeLoopFromPath: polygonPath)

这会设置适当的物理碰撞边界。虽然这解决了我的问题,但任何关于为什么原始代码不能使用贝塞尔曲线路径的见解都会很棒。谢谢。

关于swift - SpriteKit PhysicsBody 没有应用我的贝塞尔曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26112588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com