无论如何以编程方式使瓷砖地图中的瓷砖能够相互切换位置?

时间:2017-05-17 06:19:12

标签: ios swift sprite-kit

我是一名大学生,专门针对iOS开发和SpriteKit。我已经创建了一个瓦片地图,可以生成带有随机图像的图块,如果有一种方法可以通过编程方式使这些图块能够在用户触摸两个相应的图块时相互交换位置,那就很奇怪了(想想宝石迷阵)。以下是当用户触摸场景中的特定节点时调用的createTileMap()函数:

    let tileSize: CGSize = CGSize(width: labelsHolderShape!.frame.width / 9, height: labelsHolderShape!.frame.width / 9)

    // These are the tiles loaded into the tile map
    let appleTile = SKTileDefinition(texture: SKTexture(imageNamed: "Apple"), size: tileSize)
    let bananaTile = SKTileDefinition(texture: SKTexture(imageNamed: "Banana"), size: tileSize)
    let coconutTile = SKTileDefinition(texture: SKTexture(imageNamed: "Coconut"), size: tileSize)
    let grapesTile = SKTileDefinition(texture: SKTexture(imageNamed: "Grapes"), size: tileSize)
    let orangeTile = SKTileDefinition(texture: SKTexture(imageNamed: "Orange"), size: tileSize)
    let pearTile = SKTileDefinition(texture: SKTexture(imageNamed: "Pear"), size: tileSize)
    let watermellonTile = SKTileDefinition(texture: SKTexture(imageNamed: "Watermellon"), size: tileSize)

    let fruitsTileGroupRule = SKTileGroupRule(adjacency: .adjacencyAll, tileDefinitions: [appleTile, bananaTile, coconutTile, grapesTile, orangeTile, pearTile, watermellonTile])

    let fruitsTileGroup = SKTileGroup(rules: [fruitsTileGroupRule])

    let tileSet = SKTileSet(tileGroups: [fruitsTileGroup], tileSetType: SKTileSetType.grid)

    let tileMap = SKTileMapNode(tileSet: tileSet, columns: 8, rows: 8, tileSize: tileSize, fillWith: fruitsTileGroup)

    tileMap.zPosition = 3
    tileMap.alpha = 0

    addChild(tileMap)
    tileMap.run(SKAction.fadeIn(withDuration: 0.75))
}`

我会假设我必须在触摸开始/移动方法中工作或者可能完全重新编码我的createTileMap函数?

谢谢, 大卫

0 个答案:

没有答案