Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何禁用精灵套件中的穿墙功能?_Ios_Sprite Kit - Fatal编程技术网

Ios 如何禁用精灵套件中的穿墙功能?

Ios 如何禁用精灵套件中的穿墙功能?,ios,sprite-kit,Ios,Sprite Kit,这是我的播放器: self.player = [SKSpriteNode spriteNodeWithTexture:[self.spriteAtlas textureNamed:@"idle_0"]]; self.player.texture.filteringMode = SKTextureFilteringNearest; self.player.position = self.map.spawnPoint; self.player.name = @"Character"; self.pl

这是我的播放器:

self.player = [SKSpriteNode spriteNodeWithTexture:[self.spriteAtlas textureNamed:@"idle_0"]];
self.player.texture.filteringMode = SKTextureFilteringNearest;
self.player.position = self.map.spawnPoint;
self.player.name = @"Character";
self.player.physicsBody.allowsRotation = NO;
self.player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.player.texture.size];
self.player.physicsBody.categoryBitMask = CollisionTypePlayer;
self.player.physicsBody.contactTestBitMask = CollisionTypeExit;
self.player.physicsBody.collisionBitMask = CollisionTypeWall;
self.player.zPosition = 100;
这是我的墙:

SKNode *wall = [SKNode node];
wall.name = @"wall";
wall.position = CGPointMake(position.x + size.width * 0.5f - 0.5f * self.tileSize,
                          position.y - size.height * 0.5f + 0.5f * self.tileSize);
wall.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
wall.physicsBody.dynamic = NO;
wall.physicsBody.categoryBitMask = CollisionTypeWall;
wall.physicsBody.contactTestBitMask = CollisionTypePlayer;
wall.physicsBody.collisionBitMask = CollisionTypePlayer;
我要做的就是搬到一个被攻丝的地方。在touchesBegind方法中,我使用点击位置的坐标运行moveToAction。如果在被点击的位置和角色之间有一堵墙,它就会直接穿过


我试着在接触墙壁开始时停止移动,但这似乎不是正确的解决方案,因为例如,如果路径和玩家自己一样宽,并且路径被墙壁包围,它无法通过,因为与墙壁碰撞

您需要停止使用SKAction移动角色。大多数人尝试使用动作来实现他们的整个游戏机制,而动作实际上是用于一次性动画。行动不灵活。一旦你告诉你的角色移动,他就会移动,不管路上有什么阻碍

尝试在场景中使用更新方法,并将角色速度设置为触摸方向。这里有一些伪代码。。我现在没有运行xcode,但你会明白要点的。我们只考虑左右运动

var touch: CGPoint?

func touchesBegan(thisTouch){
    touch = thisTouch.location
}

func update(currentTime) {
    if let moveToTouch = touch {
        if moveToTouch.x > player.position.x {
            player.position.x += 1
        }

        else if moveToTouch.x < player.position.x {
            player.position.y -= 1
        }

        // check how far we are from our destination.  if we reached our destination then we stop
        let distance = sqrt(player.position.x * moveToTouch.x + player.position.y * moveToTouch.y)
        if distance < 1.0 {
            moveToTouch = nil
        }
    }
}

谢谢你的回答。我试着实现了它,所有的东西看起来都很好,除了当玩家在狭窄的路径上移动时,当玩家在墙之间时,玩家的纹理会变得像一个摇摇晃晃的效果。也许这与碰撞和物理有关。idk.当玩家靠近墙时阻止他