UIKitとSpriteKit(2)

空白の場所をクリックすると、そこに入れることのできる数字が表示されます。

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: cookiesLayer)
        let (success, column, row) = convertPoint(location)
        if success && level.tableAt(column: column, row: row) == 0 {
            if row_touchedb4 >= 0 { // not the first time, recover to the original state
                let num = level.tableAt(column: column_touchedb4, row: row_touchedb4)
                print(row_touchedb4, column_touchedb4, num)
                let sprite = SKSpriteNode(imageNamed: spriteNames[num])
                sprite.size = CGSize(width: TileWidth, height: TileHeight)
                sprite.position = pointFor(column: column_touchedb4, row: row_touchedb4)
                cookiesLayer.addChild(sprite)
                selectionSprite.run(SKAction.removeFromParent())
            }
            column_touchedb4 = column
            row_touchedb4    = row
            let location = touch.location(in: self)
            let sprite: SKNode? = atPoint(location)
            sprite?.run(SKAction.removeFromParent())
            selectionSprite = SKSpriteNode(imageNamed: "Undef-Highlighted")
            selectionSprite.size = CGSize(width: TileWidth, height: TileHeight)
            selectionSprite.position = pointFor(column: column, row: row)
            cookiesLayer.addChild(selectionSprite)
            showCandidate(column: column, row: row)
 }

プログラムは、まだまだ改良の余地があります。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.