Я пытаюсь выяснить, почему это имя Tile_xxxxx является каким-то длинным случайным числом в этом коде.
SKTexture: Error loading image resource: "Tile_-4412407809"
Код, связанный с ним, находится в этом уроке: https://www.raywenderlich.com/54-how-to-make-a-game-like-candy-crush-with-spritekit-and-swift-part-2
Имя плитки задается в быстром файле GameScene.swift, строка 144.
let name = String(format: "Tile_%ld", value)
и, вероятно, будет лучше, если я добавлю код из файла сюда. Что-то устанавливает значение для чего-то, что он не может использовать. Но что? Откуда он получает hashValue от
var value = topLeft.hashValue
import SpriteKit
import GameplayKit
class GameScene: SKScene {
// Sound FX
let swapSound = SKAction.playSoundFileNamed("Chomp.wav", waitForCompletion: false)
let invalidSwapSound = SKAction.playSoundFileNamed("Error.wav", waitForCompletion: false)
let matchSound = SKAction.playSoundFileNamed("Ka-Ching.wav", waitForCompletion: false)
let fallingCookieSound = SKAction.playSoundFileNamed("Scrape.wav", waitForCompletion: false)
let addCookieSound = SKAction.playSoundFileNamed("Drip.wav", waitForCompletion: false)
var level: Level!
let tilesLayer = SKNode()
let cropLayer = SKCropNode()
let maskLayer = SKNode()
let tileWidth: CGFloat = 32.0
let tileHeight: CGFloat = 36.0
let gameLayer = SKNode()
let cookiesLayer = SKNode()
var swipeHandler: ((Swap) -> Void)?
private var swipeFromColumn: Int?
private var swipeFromRow: Int?
private var selectionSprite = SKSpriteNode()
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder) is not used in this app")
}
override init(size: CGSize) {
super.init(size: size)
anchorPoint = CGPoint(x: 0.5, y: 0.5)
// This is the Witches background image
let background = SKSpriteNode(imageNamed: "Background")
background.size = size
addChild(background)
addChild(gameLayer)
gameLayer.isHidden = true
let layerPosition = CGPoint(
x: -tileWidth * CGFloat(numColumns) / 2,
y: -tileHeight * CGFloat(numRows) / 2)
tilesLayer.position = layerPosition
maskLayer.position = layerPosition
cropLayer.maskNode = maskLayer
gameLayer.addChild(tilesLayer)
gameLayer.addChild(cropLayer)
cookiesLayer.position = layerPosition
cropLayer.addChild(cookiesLayer)
let _ = SKLabelNode(fontNamed: "GillSans-BoldItalic")
}
func addSprites(for cookies: Set<Cookie>) {
for cookie in cookies {
let sprite = SKSpriteNode(imageNamed: cookie.cookieType.spriteName)
sprite.size = CGSize(width: tileWidth, height: tileHeight)
sprite.position = pointFor(column: cookie.column, row: cookie.row)
cookiesLayer.addChild(sprite)
cookie.sprite = sprite
// Give each cookie sprite a small, random delay. Then fade them in.
sprite.alpha = 0
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.run(
SKAction.sequence([
SKAction.wait(forDuration: 0.25, withRange: 0.5),
SKAction.group([
SKAction.fadeIn(withDuration: 0.25),
SKAction.scale(to: 1.0, duration: 0.25)
])
]))
}
}
func addTiles() {
for row in 0..<numRows {
for column in 0..<numColumns {
if level.tileAt(column: column, row: row) != nil {
let tileNode = SKSpriteNode(imageNamed: "MaskTile")
tileNode.size = CGSize(width: tileWidth, height: tileHeight)
tileNode.position = pointFor(column: column, row: row)
maskLayer.addChild(tileNode)
}
}
}
for row in 0...numRows {
for column in 0...numColumns {
let topLeft = (column > 0) && (row < numRows)
&& level.tileAt(column: column - 1, row: row) != nil
let bottomLeft = (column > 0) && (row > 0)
&& level.tileAt(column: column - 1, row: row - 1) != nil
let topRight = (column < numColumns) && (row < numRows)
&& level.tileAt(column: column, row: row) != nil
let bottomRight = (column < numColumns) && (row > 0)
&& level.tileAt(column: column, row: row - 1) != nil
var value = topLeft.hashValue
value = value | topRight.hashValue << 1
value = value | bottomLeft.hashValue << 2
value = value | bottomRight.hashValue << 3
// Values 0 (no tiles), 6 and 9 (two opposite tiles) are not drawn.
if value != 0 && value != 6 && value != 9 {
let name = String(format: "Tile_%ld", value)
//print(name)
let tileNode = SKSpriteNode(imageNamed: name)
tileNode.size = CGSize(width: tileWidth, height: tileHeight)
var point = pointFor(column: column, row: row)
point.x -= tileWidth / 2
point.y -= tileHeight / 2
tileNode.position = point
tilesLayer.addChild(tileNode)
}
}
}
}