所以我有一个绘制正方形的方法,它会随机抽取三角形,然后返回绘图方块。如何连续运行drawTriangle()
一段时间,然后突破它?
drawShape(){
drawSquare();
if (arc4random_uniform(50) == 0){
for 5 seconds{ << how do I implement that part?
stopDrawSquare();
drawTriangle();
}
}
}
SKAction *draw = [SKAction sequence:@[
[SKAction waitForDuration:1 withRange:1],
[SKAction performSelector:@selector(drawShape) onTarget:self]
]];
[self runAction:[SKAction repeatActionForever:draw] withKey:@"drawShape"];
答案 0 :(得分:3)
创建2个ivars:
BOOL ready;
BOOL drawTriangle;
将ready设置为默认值true,将drawTriangle设置为默认值false。
将此代码添加到您的更新方法(或您决定应该去的任何地方)
if(ready == true) {
if (arc4random_uniform(50) == 0) {
drawTriangle = true;
ready = false;
SKAction *wait0 = [SKAction waitForDuration:5.0];
SKAction *block0 = [SKAction runBlock:^{
ready = true;
}];
[self runAction:[SKAction sequence:@[wait0, block0]]];
} else {
drawTriangle = false;
}
}
if(drawTriangle == true) {
NSLog(@"draw triangle");
} else {
NSLog(@"draw square");
}