1

bodyAA のテクスチャの名前が「playerpc」であるかどうか、衝突時にチェックしようとしています。そうであれば、アクションを実行したいのですが、確認方法がわかりません。

私が今使っているコード:

              var testnode = SKSpriteNode(imageNamed: "playerpc")
              print(testnode.texture)
              if bodyAA.texture == testnode.texture{
                  print("Yes the same")
              }
              else{
                  print(bodyAA.texture)
              }

これは、コンソールからの結果です。

Optional(<SKTexture> 'playerpc' (153 x 274))
Optional(<SKTexture> 'playerpc' (153 x 274))

だから同じはず!しかし、比較すると、私のコードは同じではないと判断します。これを修正するにはどうすればよいですか?

4

1 に答える 1

3

textureはオプションですSKTexture。したがって、比較するには、ラップを解除して、次のような説明に従って確認する必要があります。

if bodyAA.texture!.description == testnode.texture!.description{
                  print("Yes the same")
              }
              else{
                  print(bodyAA.texture)
              }
于 2015-10-05T11:24:11.780 に答える