2017-05-31 62 views
0

我問這個問題,因爲我沒有找到這種問題的任何解決方案。事實上,十六進制地圖支持並不是很受歡迎。Spritekit六角形貼圖:結束SKAction中的貼圖檢測。

我正在用SpriteKit框架進行遊戲。我使用具有六角形貼圖的SktileMapNode,其中有一組4個貼圖。

playernode在每個瓷磚上移動,當他在特定瓷磚上移動時,我無法觸發某些事件(打印,功能,Sktransition),但目前我只能檢測到這些瓷磚。

我設置了用戶數據(作爲bool)並將它們應用到代碼中,但是沒有發生任何事情,即使在平鋪上有觸摸事件。

extension GameScene { 



func move(theXAmount:CGFloat , theYAmount:CGFloat, theAnimation:String) { 


    let wait:SKAction = SKAction.wait(forDuration: 0.05) 

    let walkAnimation:SKAction = SKAction(named: theAnimation, duration: moveSpeed)! 

    let moveAction:SKAction = SKAction.moveBy(x: theXAmount, y: theYAmount, duration: moveSpeed) 

    let group:SKAction = SKAction.group([ walkAnimation, moveAction ]) 

    let finish:SKAction = SKAction.run { 



     let position = self.thePlayer.position 

     let column = self.galaxieMapnode.tileColumnIndex(fromPosition: position) 
     let row = self.galaxieMapnode.tileRowIndex(fromPosition: position) 


     if let tile:SKTileDefinition = self.galaxieMapnode.tileDefinition(atColumn: column, row: row) { 


      if let tileBoolData = tile.userData?["wormholeTile"] as? Bool { 

       if (tileBoolData == true) { 

        print("Wormhole touched") 


       } 



      } 




     } else { 


      print("different tile") 


     } 


    } 

只激發「不同的瓷磚」輸出。

任何幫助,歡迎。

鏈接,形象的例子:the thing I want

回答

0

我想你想的其他動作完成後,運行結束塊?你可以把它作爲一個序列來完成。

var sequence = [SKAction]() 
let action = SKAction.move(to: location, duration: 1) 
let completionHandler = SKAction.run({ 
    // Check tile info here 
}) 

sequence += [action, completionHandler] 

self.player.run(SKAction.sequence(sequence)) 

通常在一個六角形的地圖,你將玩家移動到相鄰的瓷磚和檢查瓷磚屬性,那麼下一個移動動作不斷。這需要GameplayKit的圖形和尋路功能。

+0

我寫了一些[文章](https://markbrownsword.com)和[示例項目](https://github.com/markbrownsword?tab=repositories)關於SpriteKit中的六邊形瓷磚貼圖。 –

+0

謝謝馬克,我在看這個遊戲包。感謝提示。我可以回到你的另一個問題嗎? –

+0

對不起編輯:我回來了似乎我必須執行很多事情來使圖形和尋路功能,似乎我不得不重建很多文件中的很多東西我有。 GamePlay套件是我想要做的事情的唯一方法? –