Platform SDK: DirectX

Step 8: Play a Motif

[Visual Basic]

This tutorial pertains only to applications written in C++. See DirectMusic Visual Basic Tutorials.

[C++]

DMDonuts uses several motifs to accent the game action: for example, when the player's ship bounces off the edge of the screen and when an object is hit by the player's fire.

Playing a motif is very simple, as the following code from the CheckForHits function shows. The MOTIF_BLOWUP motif is played whenever a donut is hit.

gpPerformance->PlaySegment(
        gapMotif[gnCurrentStyle][MOTIF_BLOWUP], 
        DMUS_SEGF_SECONDARY | DMUS_SEGF_GRID, 0, NULL);
 

The motif must be played as a secondary segment so that it does not interrupt the main theme being played as the primary segment. It is cued to play on a grid boundary, the lowest resolution at which it can play without being out of step with the primary segment. The rtStartTime parameter is 0, indicating that the segment should play as soon as the first boundary is reached, and the ppSegmentState parameter is NULL because there's no need to access the segment while it is playing.

Next: Step 9: Handle Notifications