Skip to content

example.SoundEffects

Felipe Manga edited this page Sep 13, 2019 · 3 revisions
import femto.input.Button;
import femto.palette.Psygnosia;
import femto.font.TIC80;
import femto.Game;
import femto.State;
import femto.sound.Mixer;

class Main extends State {
    // These are wav files
    S1 s1;
    S2 s2;
    S3 s3;

    public static void main(String[] args){
        // Initialize the Mixer at 8khz
        Mixer.init(8000);
        Game.run( TIC80.font(), new Main() );
    }

    void init(){
        // create an instance of each sound
        // put each one on its own channel (up to 4 channels) so they don't cut each other off
        s1 = new S1(0);
        s2 = new S2(1);
        s3 = new S3(2);
    }
        
    void update(){
        if( Button.B.justPressed() )
            s2.play();

        if( Button.Left.justPressed() )
            s1.play();

        if( Button.Right.justPressed() )
            s3.play();
    }
}
Clone this wiki locally