基於這個原始發佈的問題我的問題:Making a sprite move randomly across the screen使多個對象/精靈在屏幕內隨機移動?
它解釋瞭如何從屏幕上的點位置內的任何隨機位置開始在屏幕上移動精靈。但我的問題是,如何修改代碼,以便在特定間隔後多次將對象/精靈(同一圖像文件)隨機放置在屏幕上,或者多個對象/精靈(不同的圖像文件)放在屏幕經過特定的時間間隔後。
示例:我想讓氣泡在屏幕上的任何位置突然冒出來並開始在屏幕上移動。泡沫應該每3秒彈出一次。氣泡應該能夠在任意位置進入屏幕並離開屏幕。
初始化:
CCSprite* s = [CCSprite spriteWithFile:@"yourImage.png"];
[self addChild: s];
[self moveRandom:s];
移動精靈各地:
-(void)moveRandom:(CCSprite*)s
{
CGPoint randomPoint = ccp(arc4random()%480, arc4random()%320);
NSLog(@"%@", NSStringFromCGPoint(randomPoint));
[s runAction:
[CCSequence actions:
[CCMoveTo actionWithDuration:arc4random()%5+1 position: randomPoint],
[CCCallBlock actionWithBlock:^{
[self performSelector:@selector(moveRandom:) withObject:s afterDelay:0.5];
}],
nil]
];
}
我:M採用了最新版本的Xcode。
你的github帳戶中的哪個文件有示例代碼? – user3290191
https://github.com/edfrederick/bugsquash/blob/master/scripts/actors/BugActor.js是你正在尋找的文件 – EdFred