2017-07-24 68 views
1
 for building in self.buildingArray { 
     if building.contains(location) { 
      upgradeArray.removeAll() 
      upgradeArray.append(building) 
      for tower in self.upgradeArray { 
       print(tower.position.x) 
       let buildingExample = SKSpriteNode() 
       buildingExample.texture = tower.texture 
       buildingExample.position.y = spikeTowerOption.position.y 
       buildingExample.position.x = 0 
       buildingExample.zPosition = 20 
       buildingExample.setScale(frame.size.height/3700) 
       self.addChild(buildingExample) 
      } 
     } 
    } 

這裏的問題是關於紋理。我無法弄清楚如何正確拍攝塔架紋理,並讓buildingExample具有相同的紋理。目前,該建築示例並沒有明顯出現在屏幕上。SpriteKit SKTextures

+0

我不明白你的問題。 'tower.texture'從哪裏來? –

+0

塔是觸摸的建築物陣列中的精靈,所以tower.texture將是該精靈的紋理。 –

+0

嘗試從任何SKSpriteNode inits中初始化SKSpriteNode:https://developer.apple.com/documentation/spritekit/skspritenode 例如:SKSpriteNode(texture:tower.texture) – Maetschl

回答

1

替換:

  let buildingExample = SKSpriteNode() 
      buildingExample.texture = tower.texture 

爲:

  let buildingExample = SKSpriteNode(texture: tower.texture)