ユーザーがタップしている間はボタンの画像を変更したいが、画面から指を離した場合は元の画像に戻す(スプライトキットを使用している)ユーザーがボタンをタップしている限り、ボタンの画像を変更したいですか?
マイコード:?
var SettingButton = SKSpriteNode(imageNamed: "SettingButton1.0")
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let locationUser = touch.location(in: self)
if atPoint(locationUser) == SettingButton{
let SettingButton = SKSpriteNode(imageNamed: "SettingButton2.0") //change the image
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let locationUser = touch.location(in: self)
if atPoint(locationUser) == SettingButton{
//change image back to original
}
}
}
の質感を交換してみてくださいあなたのコードはコンパイルされますか?ランタイムエラーが発生しますか?あなたのコードは、あなたが期待することをしません。より具体的にしてください。 –
touchesBegan関数の上のボタンから画像を変更する方法がわかりません@DavidPásztor – Jay23