我正在研究Gameplaykit路徑查找概念證明,並且我無法使GKObstacleGraph正確查找路徑。GKObstacleGraph在障礙物引入時未找到路徑
在下面的代碼片段中(它應該在Xcode 7.2操作系統中工作),如果創建圖形時提供了障礙物,那麼path2始終是一個空數組。如果我使用空的障礙數組創建obGraph對象,則findPathFromNode返回正確的路徑。
創建應符合(預先抱歉OBJ-C不SWIFT)內的U.
import UIKit
import GameplayKit
let pts = [vector_float2(2,2),
vector_float2(3,2),
vector_float2(3,6),
vector_float2(7,6),
vector_float2(7,2),
vector_float2(8,3),
vector_float2(8,7),
vector_float2(2,7),
vector_float2(2,2)]
let obstacle1 = GKPolygonObstacle(points: UnsafeMutablePointer(pts) ,
count: pts.count)
let obGraph = GKObstacleGraph(obstacles: [obstacle1], bufferRadius: 0)
let startPt = GKGraphNode2D(point: vector_float2(5,9))
let endPt = GKGraphNode2D(point: vector_float2(5,5))
let pt3 = GKGraphNode2D(point: vector_float2(0,0))
let pt4 = GKGraphNode2D(point: vector_float2(0,9))
let pt5 = GKGraphNode2D(point: vector_float2(5,0))
let pt6 = GKGraphNode2D(point: vector_float2(10,0))
obGraph.connectNodeUsingObstacles(startPt)
obGraph.connectNodeUsingObstacles(endPt)
obGraph.connectNodeUsingObstacles(pt3)
obGraph.connectNodeUsingObstacles(pt4)
obGraph.connectNodeUsingObstacles(pt5)
obGraph.connectNodeUsingObstacles(pt6)
startPt.connectedNodes
endPt.connectedNodes
pt3.connectedNodes
let path2 = obGraph.findPathFromNode(startPt, toNode: endPt)
print(path2)
最好把GameplayKit當成一種意向手勢而不是一個可用的成品。 – Confused
那麼,這不是很令人鼓舞@Confused –
我還應該指出,幾乎沒有人使用GameplayKit。所以你得到一個有見識的答案的機會很渺茫。 – Confused