0

これはおそらく簡単な質問ですが、キャラクターが地面に接触するたびに単純な足音サウンドを再生しようとすると問題が発生します。

誰かが親切にこれを見てもらえますか:

// I want to play a sound when the walk is at frame 4
[[SimpleAudioEngine SharedEngine]playEffect:@"footstep.mp3"];
[pleaseplaymysoundatthisframe@"walk%04d.png"];

どんな助けでも大歓迎です!

4

2 に答える 2

0

必要な遅延を計算する方がはるかに簡単で、必要な瞬間にサウンドを再生できると思います。

または、アニメーションを 2 つに分割して一連のアクションを作成することもできます。最初のアクションは、アニメーションの 0 ~ 4 フレームを使用する CCAnimate であり、メソッドを呼び出してサウンドを再生する CCCallFunc アクションよりも、残りのフレームを使用する CCAnimate アクションです。

于 2012-08-28T11:07:34.183 に答える
0

あなたはこのようなことをすることができます(マイレージは変わるかもしれません、これは私の虚弱な記憶から漏れています):

// i suppose you have your animFrames in some local var animFrames
// and your CCSprite in some other local/iVar frameOne

float animationDuration=0.8f;
int animationFrames=12;
float fourthFrameTime=animationDuration*4/animationFrames;
float animFrameDelay=animationDuration/animationFrames;

id animateSprite=[CCAnimation animationWithFrames:animFrames delay:animFrameDelay];
id playFootsteps = [CCSequence actions:[CCDelayTime actionWithDuration:fourthFrameTime],
                                       [CCCallFunc actionWithTarget:self
                                                           selector:@selector(playFootSteps)],nil];
id spawn = [CCSpawn actions:animateSprite,playFootsteps,nil];
[frameOne runAction:spawn];


// and somewhere an 

-(void) playFootSteps{
    [[SimpleAudioEngine SharedEngine]playEffect:@"footstep.mp3"];
}

これがアプリで繰り返されるテーマである場合は、任意のオブジェクト インスタンスから自家製のプロトコル/インターフェイスを介して呼び出すことができるメタ サウンド マネージャーを作成することをお勧めします (通常は「シングルトン」を使用して、cocos2d の一般的なアプローチに固執します)。そして、そこでサウンドの開始/停止/再開の複雑さを管理します。

于 2012-08-28T21:29:39.603 に答える