override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let location = touch?.location(in: self) {
let nodeArray = self.nodes(at: location)
if nodeArray.first?.name == "playButton" {
let transition = SKTransition.fade(withDuration: 0.5)
let gameScene = GameScene(size: self.size)
gameScene.scaleMode = SKSceneScaleMode.aspectFill
self.view?.presentScene(gameScene, transition: transition)
}
}
}
答案 0 :(得分:0)
<body>
<div class="container">
<div class="item" id="item1" onclick="colorRed('item1')">click me to paint me red</div>
<div class="item" id="item2" onclick="colorRed('item2')">click me to paint me red</div>
<div class="item" id="item3" onclick="colorRed('item3')">click me to paint me red</div>
<div class="item" id="item4" onclick="colorRed('item4')">click me to paint me red</div>
<div class="item" id="item5" onclick="colorRed('item5')">click me to paint me red</div>
</div>
<script>
function colorRed(param){
document.getElementById(param).style.backgroundColor = "red";
}
</script>
</body>
如果我的问题是对的,那么这就是解决方案。您可以添加或替换图像代码,而不是红色。我创建了一个函数,其中一个参数只更新了被点击的元素。