申し訳ありませんが、私はこれが初めてです。現在、その方向に回転する無限のランダムに移動するスプライトを作成しようとしています。ただし、rotateAction で randomPoint から生成されたランダムな位置を使用する方法がわかりません。基本的に、バグは移動先のポイントを使用する代わりにランダムに回転します。同じランダム ポイントを 2 回使用する方法はありますか?
-(void)moveRandom:(CCSprite*)roach
{
CGPoint randomPoint = ccp(arc4random()%480, arc4random()%320);
NSLog(@"%@", NSStringFromCGPoint(randomPoint));
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int randomDuration = (arc4random() % rangeDuration) + minDuration;
float dY = roach.position.y - randomPoint.y;
float dX = roach.position.x - randomPoint.x;
float offset = dX<0 ? 90.0f : -90.0f;
float angle = CC_RADIANS_TO_DEGREES(atan2f(dY, dX)) + offset;
[roach runAction:
[CCActionSequence actions:
[CCActionRotateTo actionWithDuration:0.001 angle:angle],
[CCActionMoveTo actionWithDuration:randomDuration position: randomPoint],
[CCActionCallBlock actionWithBlock:^{
[self performSelector:@selector(moveRandom:) withObject:roach afterDelay:0.5];
}],
nil]
];