Wednesday, August 28, 2013

GameSalad Template Example 3: Randomised Sound Assets

The aim of this tutorial is to demonstrate the randomisation of sound events when triggered from one collision. This example includes the random choice of two different sound files but can be easily extended.

 Navigate to Scenes > Scene 1

 Go to the Attributes tab on the left hand side.
 
Create a new attribute with the + button. The attribute should be an integer type. 

Rename the attribute to Random_Number, and make sure the initial value is 0. 

Create a new rule for the main character. 

Set the Rule conditions to Actor receives event > overlaps or collides > with actor of type > InvisiSpring.

 Create another rule.
Set the rule conditions to Attribute, and select the attribute Game > Random_Number. Set the value of Random_Number to 0.  Drag this rule so that it sits within the previous rule.

Drag a sound to the behaviour area of the rule that was created in the previous step. This sound will trigger whenever the random number is equal to 0. 


Copy the rule that was created two steps ago. Set the value of Random_Number to 1 instead of 0. Select a different sound asset. This second sound will trigger whenever the random number is equal to 1. 


Add a new behaviour for Change Attributes from the Behaviour tool box on the left hand side. Select the target attribute for Game > Random_Number and enter an expression using the Random function.

Random(min, max) will appear in the expression box. 


Change this to Random(0, 1). 
Move the Change Attribute(Game.Random_Number >> Random(0, 1)) so that it sits before the first sound playback Rule.


 The following diagram summarises the logic flow of the above Rules and Behaviours:



0 comments: