0

I ask this question because i didn't found any solution for this kind of issues. In fact Hex map support are not very popular.

I'am making a game with the SpriteKit Framework. I use SktileMapNode with an Hexagonal map, with 1 set of 4 groups tiles.

The playernode moves on each tiles, what i wan't it's when he move on a specifics tiles some event can be triggered ( print , function , Sktransition) but for the moment i'm stuck on just detecting those tiles.

I setup the user data ( as bool ) and apply them in the code , but nothing happened, even with a touch event on a tile.

    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")


        }


    }

Only the "different tile " output is fired.

Any help are welcome.

Link for image example : the thing I want

1 Answers1

0

I think you want to run your finish block after the other actions have completed? You can do this as a sequence.

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

Typically in a hexagonal map you would move the player to an adjacent tile and check the tiles attributes, then continue with the next move action. This requires the graph and pathfinding functionality from GameplayKit.

Mark Brownsword
  • 2,287
  • 2
  • 14
  • 23
  • I wrote some [articles](https://markbrownsword.com) and [example projects](https://github.com/markbrownsword?tab=repositories) about hexagonal tile maps in SpriteKit. – Mark Brownsword May 31 '17 at 22:38
  • Thanks Mark, i looking on this Gameplaykit. Thanks for the Tips. May i come back to you for another question ? – Rahma Sinien Jun 01 '17 at 08:05
  • Sorry edit : i come back it seems i have to implement a lot of thing to make the graph and pathfinding functionnality and it seems i have to rebuild a lot of thing in many file i have. GamePlay kit is the only way to the thing i wanna do ? – Rahma Sinien Jun 01 '17 at 08:24
  • This [example](https://www.raywenderlich.com/137216/whats-new-spritekit-ios-10-look-tile-maps) might be useful to you. It uses the players position to look for objects. – Mark Brownsword Jun 01 '17 at 19:54