【问题标题】:Optimal path player movement in Sprite KitSprite Kit 中的最佳路径玩家移动
【发布时间】: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


【解决方案1】:

SKSpriteNodes的坐标是基于Sprite的中心,而不是像UIViews的左上角。考虑到这一点,尝试相同的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    相关资源
    最近更新 更多