This is my SKAction:
这是我SKAction:
naarRechts = SKAction.moveToX(positionX , duration: 0.22)
player.runAction(naarRechts)
In that duration of 0.22 sec I do NOT want this action to run:
在0.22秒内,我不希望这个动作运行:
if CGRectIntersectsRect(player.frame, car.frame){
player.position.x = car.position.x
}
What is the magic line of code where I can detect if my first SKAction is running, or to detect wether the player is in movement or not..
有什么神奇的代码,我可以检测我的第一次滑行是否在运行,或者检测玩家是否在移动。
1 个解决方案
#1
2
You can create a class variable var playerIsInAction = false
then set it to true
just after you run the action. Also change the method so that you can write a completion code (after the action ends) where you set the bool back to false
.
您可以创建一个类变量var playerIsInAction = false,然后在运行操作之后将其设置为true。还可以更改方法,以便您可以在将bool设置为false的地方(操作结束后)编写完成代码。
It should be something like this :
应该是这样的:
playerIsInAction = true
player.runAction(naarRechts, completion: {() in
playerIsInAction = false
})
And you check for the bool
然后你检查一下bool
if CGRectIntersectsRect(player.frame, car.frame) && playerIsInAction == false {
//Code
}
#1
2
You can create a class variable var playerIsInAction = false
then set it to true
just after you run the action. Also change the method so that you can write a completion code (after the action ends) where you set the bool back to false
.
您可以创建一个类变量var playerIsInAction = false,然后在运行操作之后将其设置为true。还可以更改方法,以便您可以在将bool设置为false的地方(操作结束后)编写完成代码。
It should be something like this :
应该是这样的:
playerIsInAction = true
player.runAction(naarRechts, completion: {() in
playerIsInAction = false
})
And you check for the bool
然后你检查一下bool
if CGRectIntersectsRect(player.frame, car.frame) && playerIsInAction == false {
//Code
}