簡體   English   中英

如何比較SKSpritenodes的2個紋理

[英]How to compare 2 textures of SKSpritenodes

如果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))

所以它應該是一樣的! 但是當它比較時,我的代碼決定它不一樣,我該如何解決這個問題呢?

texture是可選的SKTexture 所以要比較你應該打開它,並根據描述檢查如下:

if bodyAA.texture!.description == testnode.texture!.description{
                  print("Yes the same")
              }
              else{
                  print(bodyAA.texture)
              }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM