UIBezierPath Arc边缘的物理

时间:2018-06-07 21:30:41

标签: swift sprite-kit skphysicsbody

我正在努力为弧创造物理。绘制此弧我只需要将物理应用于所示的白线。用这段代码绘制。

my arc

let position = CGPoint(x: 0, y: 0)
let width = CGFloat(5)
let inner = 300/2-width
let outer = 300/2+width
let start = 3*CGFloat.pi/2-offset
let end = 3*CGFloat.pi/2+offset

let arc = UIBezierPath(arcCenter: position, radius: inner, startAngle: start, endAngle: end, clockwise: true)

let shape = SKShapeNode(path: arc.cgPath)
shape.strokeColor = SKColor.white
shape.lineWidth = 2
shape.fillColor = SKColor.blue
shape.physicsBody = SKPhysicsBody(polygonFrom: arc.cgPath)
shape.physicsBody?.isDynamic = false

self.addChild(shape)

自然物理学适用于整个形状。添加此代码可以让我更漂亮

fancier arc

arc.addLine(to: CGPoint(x: outer * cos(end), y: outer * sin(end)))
arc.addArc(withCenter: position, radius: outer, startAngle: end, endAngle: start, clockwise: false)

但是同样的物理学仍然适用于他们在第一个中所做的。

如何为第二个圆弧创建具有适当物理效果的圆弧?

修改

显示物理并使用清晰的颜色,包括浮球。

enter image description here

1 个答案:

答案 0 :(得分:0)

弄清楚我的问题。这是物理生成器本身的问题。它只会产生不凹的凸多边形。所以我利用了Is there a way to create a concave physicsBody in SpriteKit?中的内容。

在我的代码中添加一个循环来创建弧的矩形,这让我可以使用

enter image description here

<?php
include 'includes/db.php';
$ins_sql = "UPDATE appointment
            SET first_name = ?, last_name = ?
            WHERE appoint_id = ?";
$stmt = $conn->prepare($ins_sql);
$stmt->bind_param("ssi", $_POST['first_name'], $_POST['last_name'], $_POST['appoint_id']);
if ($stmt->execute()) {
    echo "updated";
} else {
    echo "not updated";
}