Line 1,925: |
Line 1,925: |
| this.playSoundPitched("toyPiano", 1800); | | this.playSoundPitched("toyPiano", 1800); |
| break; | | break; |
| + | } |
| + | </syntaxhighlight> |
| + | </dd> |
| + | |
| + | <dt><tt>playSoundAfterDelay</tt></dt> |
| + | <dd> |
| + | Sometimes, you need to play a sound after waiting a certain period of time, for the current player at no particular location. In this case, you can call the <tt>DelayedAction.playSoundAfterDelay()</tt> method: |
| + | <syntaxhighlight lang="c#"> |
| + | // During a lightning storm, if the random chance is met, |
| + | // the screen will flash, and then |
| + | // a distant lightning strike sound will play after a |
| + | // randomly generated duration of time in milliseconds |
| + | if (Game1.random.NextDouble() < 0.5) |
| + | DelayedAction.screenFlashAfterDelay((float) (0.3 + Game1.random.NextDouble()), Game1.random.Next(500, 1000)); |
| + | DelayedAction.playSoundAfterDelay("thunder_small", Game1.random.Next(500, 1500)); |
| + | // ... |
| + | </syntaxhighlight> |
| + | You can also change the sound's pitch with this function, or call this function several times at once to call them in a predetermined order: |
| + | <syntaxhighlight lang="c#"> |
| + | // When using the phone that is purchasable from the Carpenter's Shop, |
| + | // it will play a specific sequence of dial beeps at predetermined times: |
| + | private void playShopPhoneNumberSounds(string whichShop) |
| + | { |
| + | Random random = new Random(whichShop.GetHashCode()); |
| + | DelayedAction.playSoundAfterDelay("telephone_dialtone", 495, pitch: 1200); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 1200, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 1370, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 1600, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 1850, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 2030, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 2250, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_buttonPush", 2410, pitch: (1200 + random.Next(-4, 5) * 100)); |
| + | DelayedAction.playSoundAfterDelay("telephone_ringingInEar", 3150); |
| } | | } |
| </syntaxhighlight> | | </syntaxhighlight> |