【发布时间】:2015-10-26 19:13:52
【问题描述】:
我在这里尝试做的是让角色移动到一个位置,同时避开他路径上的障碍物。我尝试使用这样的东西:
// node = character
// position = position of touch
[self.map enumerateChildNodesWithName:@"tile" usingBlock:^(SKNode * _Nonnull tileNode, BOOL * _Nonnull stop) {
if( round((SDistanceBetweenPoints(node.position, tileNode.position)) < 33) ) {
if((SDistanceBetweenPoints(tileNode.position, position) < newDistance)&&((tileNode.position.x == position.x) || (tileNode.position.y == position.y))) {
newDistance = SDistanceBetweenPoints(tileNode.position, position);
moveToTouch = tileNode.position;
}
}
}];
我的主要问题是角色从半路就开始走:
【问题讨论】:
-
SKSpriteNodes的坐标是基于Sprite的中心,而不是像UIViews的左上角。考虑到这一点,您可以尝试相同的代码吗?
-
好吧...这确实解决了我的问题!谢谢! (作为答案发布)。
标签: ios swift sprite-kit