我正在使用Swift制作基于3D回合的Mac OS地牢游戏。 我已经完成了3D地牢部分-它会随机生成一个地牢,并将地牢的每个正方形以字符串形式保存为数组(例如流氓,它使用文本字符表示墙壁等...)
我想使用SpriteKit制作地牢的2D地图,而SKTileMap似乎是一种合乎逻辑的方法,但是我在使用代码时遇到了麻烦。
作为一项学习练习,我创建了一个新项目,并在窗口中填充了一个“自定义”视图,我将其设置为使用SKView类,并尝试以编程方式制作一个国际象棋棋盘格贴图,但是我只能显示一种颜色。
这是代码
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
public class BitemporalWrapper<V extends Serializable> implements Bitemporal, Serializable {
...
@Override
public Bitemporal copyWith(Interval validityInterval) {
// force record interval to be 'from now'
return new BitemporalWrapper<>(SerializationUtils.clone(value), validityInterval);
}
...
}
public class WrappedBitemporalProperty<V extends Serializable> extends BitemporalProperty<V, BitemporalWrapper<V>> { ... }
public class BitemporalProperty<V extends Serializable, T extends Bitemporal> implements Serializable { .. }
没有
@IBOutlet var spriteView: SKView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let scene = SKScene()
let greenTexture = SKTexture(imageNamed: "green")
let greenDefinition = SKTileDefinition(texture: greenTexture)
let greenGroup = SKTileGroup(tileDefinition: greenDefinition)
let redTexture = SKTexture(imageNamed: "red")
let redDefinition = SKTileDefinition(texture: redTexture)
let redGroup = SKTileGroup(tileDefinition: redDefinition)
let tileSet = SKTileSet(tileGroups: [greenGroup, redGroup], tileSetType: .grid)
let backgroundGroup = redGroup
let tileMap = SKTileMapNode(tileSet: tileSet, columns: 5, rows: 5, tileSize: CGSize(width: 10, height: 10), fillWith: backgroundGroup)
tileMap.setTileGroup(greenGroup, forColumn: 0, row: 0)
tileMap.setTileGroup(greenGroup, forColumn: 0, row: 2)
tileMap.setTileGroup(greenGroup, forColumn: 0, row: 4)
tileMap.setTileGroup(greenGroup, forColumn: 1, row: 0)
tileMap.setTileGroup(greenGroup, forColumn: 1, row: 2)
tileMap.setTileGroup(greenGroup, forColumn: 1, row: 4)
tileMap.setTileGroup(greenGroup, forColumn: 2, row: 0)
tileMap.setTileGroup(greenGroup, forColumn: 2, row: 2)
tileMap.setTileGroup(greenGroup, forColumn: 2, row: 4)
tileMap.setTileGroup(greenGroup, forColumn: 3, row: 0)
tileMap.setTileGroup(greenGroup, forColumn: 3, row: 2)
tileMap.setTileGroup(greenGroup, forColumn: 3, row: 4)
tileMap.setTileGroup(greenGroup, forColumn: 4, row: 0)
tileMap.setTileGroup(greenGroup, forColumn: 4, row: 2)
tileMap.setTileGroup(greenGroup, forColumn: 4, row: 4)
tileMap.setTileGroup(greenGroup, forColumn: 5, row: 0)
tileMap.setTileGroup(greenGroup, forColumn: 5, row: 2)
tileMap.setTileGroup(greenGroup, forColumn: 5, row: 4)
scene.addChild(tileMap)
spriteView.presentScene(scene)
}
地图全是红色,但地图全是绿色。
需要进行哪些更改才能使其像瓷砖地图一样变成红色和绿色的国际象棋棋盘?