if(tama.tag == 2){
int rand = arc4random() % 10;
float x;
if(rand == 1){
x = -1 * x;
}
tama.position = ccp(tama.position.x - x, tama.position.y - 5.0f);
}
1/10の確率でxの方向を変えたいのですが、xにローカル変数を使うと毎回値が更新されうまくいきません。
グローバル変数を使えばできるのは分かるですが、なんか納得いきません。
上手な書き方を教えてください。よろしくお願いします。
(objective-c,xcode)