更改touch内的touch.name而不再运行?(Change node.name inside of touch without running again?)

编程入门 行业动态 更新时间:2024-10-26 15:17:25
更改touch内的touch.name而不再运行?(Change node.name inside of touch without running again?)

我想点击某个spritenode并更改该spritenode的值。 这是问题所在。 当我这样做,并设置一个if语句,它知道去if语句。 但是,我不希望它在下次单击按钮之前运行。

例:

apple.name = "apple" override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in: self) let node : SKNode = self.atPoint(location) if node.name == "apple" { appple.name = "orange" print("Hello") } if node.name = "orange" { //do this } } }

有没有办法做到这一点?

I want to click on a certain spritenode and change the value of that spritenode. Here is the problem. When i do that, and set a if statement it knows to go to that if statement. However, i don't want it to run until next time the button is clicked.

Example:

apple.name = "apple" override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in: self) let node : SKNode = self.atPoint(location) if node.name == "apple" { appple.name = "orange" print("Hello") } if node.name = "orange" { //do this } } }

Is there a way to do this?

最满意答案

首先,在你的第二个if语句中,你没有检查值“==”你正在为它赋值“=”。

无论如何,解决问题的一个简单方法是添加else if语句。

if node.name == "apple" { appple.name = "orange" print("Hello") }else if node.name == "orange" { //do this }

first of all in your second if statement you are not checking the value "==" your are assigning a value "=" to it.

anyway a simple solution to your problem is to add an else if statement.

if node.name == "apple" { appple.name = "orange" print("Hello") }else if node.name == "orange" { //do this }

更多推荐

本文发布于:2023-07-26 03:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Change   touch   running   node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!