cocos2d가 어떻게 작동하는지 (레이어, 장면, 어린이 등)에 대한 기본 지식이 있다고 가정 할 때,이 방법을 사용하십시오.
CGSize winSize = [[CCDirector shareDirector] winSize];
CCSprite *block = [CCSprite spriteWithFile:@"block.png"];
// Generate a random x position
CGFloat x = arc4random() % winSize.width;
// Position the block at a random x, just above the top of the screen
block.position = ccp(x, winSize.height + block.contentSize.height/2);
// Tell the block to fall down to the bottom of the screen over 2 seconds
CCMoveTo *fall = [CCMoveTo actionWithDuration:2 position:ccp(block.position.x, 0 - block.contentSize.height/2)];
[block runAction:fall];
당신이, 당신은 설정 콜백 함수가 너무 자주 "createBlock"간격으로 함수를 호출 할 수있는 블록의 일정한 흐름에서 발생하고 싶었다면. 블록을 끊임없이 재생성하는 것은 그리 효율적이지 않지만, 오프 스크린 블록 목록을 유지하고 필요할 때 다시 위로 떨어지게하는 것이 가장 간단합니다.
CCSequence *rainBlocks = [CCSequence actions: [CCCallBlock actionWithBlock:^{
[self createBlock];
}],
[CCDelayTime actionWithDuration:3],
nil]];
[self runAction:[CCRepeatForever actionWithAction:rainBlocks]];
나는 구문에 100 %가 아니지만 일반적인 생각입니다.
감사합니다. 그것은 완벽하게 작동했습니다. 나는 당신이 말했던 것처럼 오프 스크린과 스크린 블럭에서 트랙을 유지하기 위해 배열을 변경해야했다. – sbjluke