SoundText (and WavData)

Rich

Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
Joined
Sep 9, 2017
Messages
451
Hi

Ive been playing with getting Sounds queued, and came up with SoundText.
Sound text allows you to assign a word to a Sound, and then you can play a phrase based on the individual words.

WavData is also required as part of SoundText. WavData reads the Wav file length in millisecs. All modules are native to CX and should work on all targets.

Repos here WavData SoundText

Demo here https://richpantson.itch.io/soundtext

example (from SoundText repo)
code_language.cerberus:
Strict

Import mojo2
Import soundtext

Class myClass Extends App
    Field cnvs:Canvas

    Method OnCreate:Int()
        SetUpdateRate(60)             
        cnvs = New Canvas
      
        LoadSoundText("player","player.wav")
        LoadSoundText("one","one.wav")
        LoadSoundText("two","two.wav")
        LoadSoundText("requires","requires.wav")
        LoadSoundText("ammo","ammo.wav")
        LoadSoundText("health","health.wav")
        LoadSoundText("keys","keys.wav")
      
        Return 0
    End
  
    Method OnUpdate:Int()
        UpdateSoundText()
        If KeyHit(KEY_SPACE) Or MouseHit(MOUSE_LEFT)
            Local player:String = (["one","two"])[Rnd(2)]
            Select Int(Rnd(3))
            Case 1
                PlaySoundText("player "+player+" requires health")
            Case 2
                PlaySoundText("player "+player+" requires ammo")
            Default
                PlaySoundText("player "+player+" requires keys")
            End
        End
        Return 0
    End
  
    Method OnRender:Int()
        cnvs.Clear (0,0.2,0) 
        cnvs.SetColor (0,0.8,0) 
        cnvs.DrawText( String("SoundText demo~nHit screen for random phrase").Split("~n")),DeviceWidth()/2,DeviceHeight()/2,0.5,0.5
        cnvs.Flush

        Return 0
    End
End

Function Main:Int()
    New myClass     
    Return 0
End
 
Last edited:
Top Bottom