File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -75,23 +75,21 @@ class GameScene: SKScene {
75
75
drawBoard ( )
76
76
}
77
77
78
+ @inline ( never)
78
79
fileprivate func drawBoard( ) {
79
80
let cellSize = min ( size. width, size. height) / CGFloat( boardSize)
80
81
let offset = - cellSize * CGFloat( boardSize) / 2
81
- board = ( 0 ..< boardSize ) . map { _ in Array ( repeating: nil , count: boardSize) }
82
+ board = Array ( repeating : Array ( repeating: nil , count: boardSize) , count : boardSize )
82
83
83
- for i in 0 ..< ( boardSize * boardSize) {
84
- let row = i / boardSize
85
- let col = i % boardSize
84
+ ( 0 ..< boardSize * boardSize) . forEach { i in
86
85
let cell = SKSpriteNode ( color: GameColor . gray, size: CGSize ( width: cellSize - 10 , height: cellSize - 10 ) )
87
-
88
- // Explicit CGFloat conversion for col and row
89
- cell. position = CGPoint ( x: offset + ( CGFloat ( col) + 0.5 ) * cellSize,
90
- y: offset + ( CGFloat ( row) + 0.5 ) * cellSize)
91
-
92
- cell. name = " \( row) - \( col) "
86
+ cell. position = CGPoint (
87
+ x: offset + ( CGFloat ( i % boardSize) + 0.5 ) * cellSize,
88
+ y: offset + ( CGFloat ( i / boardSize) + 0.5 ) * cellSize
89
+ )
90
+ cell. name = " \( i / boardSize) - \( i % boardSize) "
93
91
addChild ( cell)
94
- board [ row ] [ col ] = cell
92
+ board [ i / boardSize ] [ i % boardSize ] = cell
95
93
}
96
94
}
97
95
You can’t perform that action at this time.
0 commit comments