Can't run my sketch anymore...

edited December 2 in Library Questions

I'm using Processing 3.3.6 on Windows 10. So I've made a game (it's supposed to be like Crazy Chicken/Moorhuhn) with a main menu and all but if I set too many targets (30) I can't play it, it just crashes and returns: "Could not run the sketch."

I'm fairly new to programming as a whole, but my assumption would be that it is somehow overwhelmed? I'm also not sure what part of the code is causing the problem, so I don't know what I should show you...

If it is of any interest: I'm also using the sound library and so far I've implemented 19 different soundfiles, which already caused me some problems. I've made 2 separate classes for the sound, because somehow one sound class can only manage 15 SoundFiles.

Answers

  • so I don't know what I should show you...

    Everything. Runnable examples will get you the best quality replies. Currently we have NOTHING.

  • I've made 2 separate classes for the sound, because somehow one sound class can only manage 15 SoundFiles

    Classes don't work that way in general. You are doing your best to guess what is causing your problems, but some of your guesses are probably not right. Sharing your code will help us help you.

  • Ok then, here we go:

    My main sketch:

    PFont pixfont;
    int windowsize = 900;
    import processing.sound.*;
    Screen currentScreen;
    
    void setup() {
      size(1600, 900);
      currentScreen = new realgameScreen();
      pixfont = createFont("fonts/Minecraft.ttf", 32);
      textFont(pixfont);
    }
    
    void draw() {
    
      //Screen handling
      if (currentScreen.changeScreen == true) {
        currentScreen = currentScreen.newScreen;
      }
    
      currentScreen.update();
      currentScreen.draw();
    }
    
    void changeScreen(Screen newScreen) {
      currentScreen = newScreen;
    }
    
    void mouseClicked() {
      currentScreen.mouseClicked();
    }
    
    void mousePressed(){
     currentScreen.mousePressed(); 
    }
    
    void keyPressed(){
     currentScreen.keyPressed(); 
    }
    

    Screen class:

    class Screen {
    
      boolean changeScreen = false;
      Screen newScreen;
    
      void draw() {
      }
    
      void update() {
      }
    
      void changeScreen(Screen newScreen) {
        changeScreen = true;
        this.newScreen = newScreen;
      }
    
    
      void mouseClicked() {
      }
    
      void mousePressed() {
      }
    
      void keyPressed(){
      }
    }
    

    Button class:

    class Button {
    
      boolean drueber;
      String text;
      float xPos;
      float yPos;
      float laenge;
      float breite;
      float textxPos;
      color gelb = color(255, 255, 0);
      color schwarz = color(0);
      boolean clicked = false;
    
       Sound effekte;
    
      Button(String text, float textxPos, float xPos, float yPos, float laenge, float breite) {
        this.text = text;
        this.xPos = xPos;
        this.yPos = yPos;
        this.laenge = laenge;
        this.breite = breite;
        this.textxPos = textxPos;
    
      effekte = new Sound(TheGame_v3.this);
      }
    
      void zeichnen() {
        if (mouseX >= xPos && mouseX <= xPos + laenge && mouseY >= yPos && mouseY <= yPos + breite) {
          fill(gelb);
          if (mousePressed) {
            fill(50);
            stroke(gelb);
            strokeWeight(3);
          }
        } else {
          fill(schwarz);
          strokeWeight(1);
          stroke(gelb);
        }
        rect(xPos, yPos, laenge, breite);
        if (mouseX >= xPos && mouseX <= xPos + laenge && mouseY >= yPos && mouseY <= yPos + breite) {
          fill(schwarz);
          if (mousePressed) {
            fill(gelb);
          }
         } else {
          fill(gelb);
        }
        if ((text.length() * (breite * 0.75)) / 1.84 > laenge) {
          textSize(laenge / text.length() * 1.84);
        } else {
          textSize(breite * 0.75);
        }
        text(text, textxPos, yPos + breite * 0.75);
      }
    
      void mousePressed() {
        if (mouseX >= xPos && mouseX <= xPos + laenge && mouseY >= yPos && mouseY <= yPos + breite) {
          effekte.play(3);
        }
      }
    
      void mouseClicked() {
        if (mouseX >= xPos && mouseX <= xPos + laenge && mouseY >= yPos && mouseY <= yPos + breite) {
          effekte.play(4);
          clicked = true;
        }
      }
    }
    

    Sound class:

    class Sound {
    
      SoundFile tetris;
      SoundFile coin;
      SoundFile mushroom;
      SoundFile buttonclick;
      SoundFile buttonrelease;
      SoundFile supermario;
      SoundFile dubstep;
      SoundFile miss;
      SoundFile gameover;
      SoundFile tick;
      SoundFile snackbar;
      SoundFile explosion;
      SoundFile shotgunshot;
      SoundFile cock;
      SoundFile reload;
      SoundFile triplebaby;
    
    
      float fadevalue = 0.5;
    
      Sound(PApplet p) {
        tetris = new SoundFile(p, "soundeffects/monotetris.wav");
        coin = new SoundFile(p, "soundeffects/coin.mp3");
        mushroom = new SoundFile(p, "soundeffects/mushroom.wav");
        buttonclick = new SoundFile(p, "soundeffects/buttonclick.wav");
        buttonrelease = new SoundFile(p, "soundeffects/buttonclickrelease.wav");
        supermario = new SoundFile(p, "soundeffects/mariotheme.wav");
        dubstep = new SoundFile(p, "soundeffects/gamemusic.wav");
        miss = new SoundFile(p, "soundeffects/miss.wav");
        gameover = new SoundFile(p, "soundeffects/gameover.wav");
        tick = new SoundFile(p, "soundeffects/tick.wav");
        snackbar = new SoundFile(p, "soundeffects/snackbar.wav");
        explosion = new SoundFile(p, "soundeffects/explosion2.wav");
        shotgunshot = new SoundFile(p, "soundeffects/shotgun_shoot.wav");
        cock = new SoundFile(p, "soundeffects/reload.wav");
        reload = new SoundFile(p, "soundeffects/shotgun_reload.wav");
        triplebaby = new SoundFile(p, "soundeffects/triplebaby.wav");
      }
    
      void play(int tracknr) {
        switch(tracknr) {
        case 0:
          tetris.amp(0.5);
          tetris.loop();
          break;
    
        case 1:
          coin.amp(1);
          coin.play();
          break;
    
        case 2:
          mushroom.amp(0.2);
          mushroom.play();
          break;
    
        case 3:
          buttonclick.amp(1);
          buttonclick.play();
          break;
    
        case 4:
          buttonrelease.amp(1);
          buttonrelease.play();
          break;
    
        case 5:
          supermario.amp(0.5);
          supermario.loop();
          break;
    
        case 6:
          dubstep.amp(0.5);
          dubstep.play();
          break;
    
        case 7:
          miss.amp(2);
          miss.play();
          break;
    
        case 8:
          tick.amp(4);
          tick.play();
          break;
    
        case 9:
          snackbar.amp(1);
          snackbar.play();
          break;
    
        case 10:
          explosion.amp(1);
          explosion.play();
          break;
    
        case 11:
          shotgunshot.amp(0.5);
          shotgunshot.play();
          break;
    
        case 12:
          cock.amp(1);
          cock.play();
          break;
    
        case 13:
          reload.amp(1);
          reload.play();
          break;
    
        case 14:
          triplebaby.amp(1);
          triplebaby.play();
          break;
        }
      }
    
      void fade() {
        supermario.amp(fadevalue);
        if (fadevalue >= 0) {
          fadevalue -= 0.0025;
        } else {
          supermario.stop();
        }
      }
    
      void gameover() {
        supermario.stop();
        gameover.amp(1);
        gameover.play();
      }
    }
    

    Sound2 class:

    class Sound2 {
    
      SoundFile wombocombo;
      SoundFile happyfeet;
      SoundFile getout;
      SoundFile hitmarker;
    
      Sound2(PApplet p) {
        wombocombo = new SoundFile(p, "soundeffects/wombocombo.wav");
        happyfeet = new SoundFile(p, "soundeffects/happyfeet.wav");
        getout = new SoundFile(p, "soundeffects/happyfeet.wav");
        hitmarker = new SoundFile(p, "soundeffects/hitmarker.wav");
      }
    
      void play(int tracknr) {
        switch(tracknr) {
          case 0:
          wombocombo.amp(0.5);
          wombocombo.play();
          break;
    
          case 1:
          happyfeet.amp(0.5);
          happyfeet.play();
          break;
    
          case 2:
          getout.amp(0.5);
          getout.play();
          break;
    
          case 3:
          hitmarker.amp(1);
          hitmarker.play();
          break;
        }
      }
    }
    

    Main Menu class:

    class mainScreen extends Screen {
    
      Button play;
      Button options;
      Button close;
    
      mainScreen() {
        play = new Button("Play", width / 2.15, width / 4, height * 0.51, width / 2, 80);
        options = new Button("Options", width / 2.3, width / 4, height * 0.62, width / 2, 80);
        close = new Button("Exit", width / 2.15, width / 4, height * 0.73, width / 2, 80);
      }
    
      void draw() {
        background(0);
        fill(255,255,0);
        textSize(100);
        text("The Game", width / 2.85, height / 3);
        play.zeichnen();
        options.zeichnen();
        close.zeichnen();
      }
    
      void update() {
        if(play.clicked == true){
          changeScreen(new gameScreen());
        }
        if(options.clicked == true){
         changeScreen(new Options()); 
        }
        if(close.clicked == true){
         exit(); 
        }
      }
    
      void mouseClicked(){
       play.mouseClicked(); 
       options.mouseClicked();
       close.mouseClicked();
      }
    
      void mousePressed(){
       play.mousePressed();
       options.mousePressed();
       close.mousePressed();
      }
    }
    

    Options class:

    class Options extends Screen{
    
      Button goback;
    
      Options(){
        goback = new Button("Go back", width / 2.3, width / 4, height * 0.62, width / 2, 80);
      }
    
      void draw(){
        background(0);
        textSize(100);
        fill(255,255,0);
        text("Options", width / 2.6, height / 3);
        goback.zeichnen();
      }
    
      void update(){
        if(goback.clicked == true){
         changeScreen(new mainScreen()); 
        }
      }
    
      void mouseClicked(){
       goback.mouseClicked(); 
      }
    
      void mousePressed(){
       goback.mousePressed(); 
      }
    }
    

    Target class:

    class Target {
    
      Sound effects;
    
      PImage mtndw;
    
      float groesse;
      float xPos;
      float yPos;
      float speed;
      boolean visibility;
      float opacity;
      color farbe;
      String reward;
      float gameoverfade = 255;
      int img;
      boolean redraw;
      float Xcorrection;
      float Ycorrection;
    
      Target(String reward, int img, boolean redraw) {
        this.redraw = redraw;
        this.img = img;
        this.reward = reward;
        mtndw = loadImage("images/mtndew.png");
        groesse = random(30, 100);
        xPos = random(width);
        yPos = random(TWO_PI);
    
        if(img == 1){
         Xcorrection = 1.35;
         Ycorrection = 0.75;
        }else{
          Xcorrection = 1;
          Ycorrection = 1;
        }
    
        if (redraw == false) {
          speed = 250 / groesse;
        } else {
          int side;
          side = floor(random(2));
          if (side == 0) {
            speed = 250 / groesse;
          } else {
            speed = (250 / groesse) * -1;
          }
        }
    
        visibility = true;
        opacity = 255;
        farbe = color(random(255), random(255), random(255));
        effects = new Sound(TheGame_v3.this);
      }
    
      void calculate() {
        xPos += speed;
        yPos += 0.05;
        if (redraw == false) {
          if (xPos >= width + groesse) {
            xPos = groesse * -1;
          }
        } else {
          if (xPos >= width + groesse) {
            xPos = groesse * -1;
            if (visibility == false) {
              visibility = true;
              opacity = 255;
            }
          }
          if (xPos <= groesse * -2) {
            xPos = width;
            if (visibility == false) {
              visibility = true;
              opacity = 255;
            }
          }
        }
      }
    
      void draw() {
        stroke(255, gameoverfade);
        strokeWeight(1);
        if (visibility == true) {
          switch(img) {
          case 0:
            fill(farbe, gameoverfade);
            rect(xPos, (height / 2) + (sin(yPos) * (height / 4)), groesse, groesse);
            break;
    
          case 1:
            tint(255, 255);
            image(mtndw, xPos, (height / 2) + (sin(yPos) * (height / 4)), groesse * 1.35, groesse * 0.75);
            break;
          }
        } else {
          opacity -= 2;
          fill(255, 255, 0, opacity);
          textSize(40);
          text(reward, xPos, (height / 2) + (sin(yPos) * (height / 4)));
        }
      }
    
      boolean click() {
        if (mouseX >= xPos - ((groesse * Xcorrection) / 2) && mouseX <= (xPos + ((groesse * Xcorrection) * 1.5)) && mouseY >= ((height / 2) + (sin(yPos) * (height / 4))) - ((groesse * Ycorrection) / 2) && mouseY <= ((height / 2) + (sin(yPos) * (height / 4))) + ((groesse * Ycorrection) * 1.5)) {
          if (visibility == true) {
            visibility = false;
            return true;
          }
        }
        return false;
      }
    }
    

    Pregame class:

    class gameScreen extends Screen {
    
      int number = 30;
      int timer = 0;
      int intertimer = 0;
      int gold = 0;
      int lives = 3;
      boolean gameover = false;
      boolean gobackdraw = false;
    
      String rewardtext = "+" + 420 / number + "g";
      PImage heart;
    
      Target[] clickme = new Target[number];
      Sound effects;
      Button yes;
      Button goback;
    
      gameScreen() {
        heart = loadImage("images/pixheart.png");
        for (int i = 0; i < number; i++) {
          clickme[i] = new Target(rewardtext, 0, false);
        }
        yes = new Button("YES", width / 3.2, width / 3.3, height * 0.666, width / 10, 80);
        goback = new Button("Exit", width / 2.2, width / 2.275, height * 0.666, width / 10, 80);
        effects = new Sound(TheGame_v3.this);
        effects.play(5);
      }
    
      void draw() {
        timer++;
        background(0);
        textSize(50);
        fill(255, 255, 0);
        text("Gold: " + gold, width * 0.666, 70);
        fill(255, 0, 0);
        text("Lives: ", width * 0.2, 70);
        float heartxPos = width * 0.3;
        for (int i = 0; i < lives; i++) {
          image(heart, heartxPos, 30, 50, 50);
          heartxPos += width * 0.03;
        }
        for (int i = 0; i < number; i++) {
          clickme[i].draw();
          if (gameover == false) {
            clickme[i].calculate();
          } else if (clickme[i].gameoverfade > 30) {
            clickme[i].gameoverfade -= 1.5;
          } else {
            fill(255, 0, 0);
            textSize(200);
            text("GAME OVER", width * 0.13, height * 0.5);
            goback.zeichnen();
            gobackdraw = true;
          }
        }
        if (gold == 420) {
          intermission();
        }
      }
    
      void intermission() {
        effects.fade();
        intertimer++;
        if (intertimer >= 360) {
          fill(255, 255, 0, 255);
          textSize(80);
          text("The free version ends here.", width / 6, height / 3);
        }
        if (intertimer >= 480) {
          text("Pay 420g for the full game?", width / 6, height / 1.85);
        }
        if (intertimer >= 600) {
          baitbutton();
          yes.zeichnen();
        }
      }
    
      float bbxPos = width * 0.6;
      float bbyPos = height * 0.666;
      int tries = 0;
      void baitbutton() {
        fill(0);
        strokeWeight(1);
        stroke(255, 255, 0);
        rect(bbxPos, bbyPos, 160, 80);
        textSize(60);
        fill(255, 255, 0);
        text("NO", bbxPos + 40, bbyPos + 60);
        while (mouseX >= bbxPos - 80 && mouseX <= bbxPos + 240 && mouseY >= bbyPos - 80 && mouseY <= bbyPos + 240) {
          bbxPos = random(width - 160);
          bbyPos = random(height - 80);
          tries++;
        }
        if (tries >= 20) {
          fill(255, 0, 0);
          textSize(40);
          text("<=== Press the goddamn button!!!", width / 2.4, height * 0.725);
        }
      }
    
      void update() {
        if (yes.clicked == true) {
          effects.play(2); 
          changeScreen(new realgameScreen());
        }
        if (goback.clicked == true) {
          changeScreen(new mainScreen());
        }
      }
    
      void mousePressed() {
        if (timer >= 20 && gold < 420 && gameover == false) {
          int falsecount = 0;
          for (int i = 0; i < number; i++) {
            if (clickme[i].click() == true) {
              effects.play(1);
              gold += 420 / number;
            } else {
              falsecount++;
            }
          }
          if (falsecount == number) {
            effects.play(7);
            lives--;
            if (lives == 0) {
              gameover = true;
              effects.gameover();
            }
          }
        }
        if (intertimer >= 600) {
          yes.mousePressed();
        }
        if (gobackdraw == true) {
          goback.mousePressed();
        }
      }
    
      void mouseClicked() {
        if (intertimer >= 600) {
          yes.mouseClicked();
        }
        if (gobackdraw == true) {
          goback.mouseClicked();
        }
      }
    }
    
  • Realgame class:

    class realgameScreen extends Screen {
    
      int number = 30;
    
      Sound effects;
      Sound2 effekts;
      Target[] cans = new Target[number];
    
      PFont clockfont;
      PImage pepecool;
      PImage shell;
      PImage shotgun;
    
      int timer = 0;
      int start;
    
      int tensecs;
      int secs;
      int tenthsecs;
      int centisecs;
      int millisecs;
      float[] onecorrection = new float[5];
      boolean[] limiter = new boolean[3]; 
      boolean gameover = false;
      boolean iscocking = false;
      boolean isreloading = false;
      int cockingtime;
      int ammo = 6;
    
    
      realgameScreen() {
        clockfont = createFont("fonts/DS-DIGI.TTF", 32);
        pepecool = loadImage("images/pepecool.jpg");
        shell = loadImage("images/shellv2.png");
        shotgun = loadImage("images/shotgun.png");
        effects = new Sound(TheGame_v3.this);
        effekts = new Sound2(TheGame_v3.this);
        for (int i = 0; i < number; i++) {
          cans[i] = new Target("+1$", 1, true);
        }
        start = millis();
        effects.play(6);
        for (int i = 0; i < 5; i++) {
          onecorrection[i] = 0;
        }
        for (int i = 0; i < 3; i++) {
          limiter[i] = false;
        }
      }
    
      void draw() {
        background(0);
        if (millis() - start > 2500 && millis() - start < 6841) {
          timer++;
          tint(255, timer);
          image(pepecool, 0, 0, width, height);
        } else if (millis() - start >= 6841) { // <---- DROP
          background(0);
          countdown(0.865, 70, 50974);
          image(shotgun, 20, 40, 400, 100);
          float shellxPos = width * 0.275;
          for (int i = 0; i < ammo; i++) {
            image(shell, shellxPos, 30, 34, 80);
            shellxPos += width * 0.02;
          }
          if (gameover == false) {
            for (int i = 0; i < number; i++) {
              cans[i].calculate();
              cans[i].draw();
            }
            if (millis() >= cockingtime + 1000) {
              iscocking = false;
            }
            if (isreloading == true && ammo < 6) {
              reloading();
            }
            if (ammo == 6 && limiter[2] == true) {
              iscocking = true;
              cockingtime = millis();
              isreloading = false; 
              limiter[2] = false;
              effects.play(12);
            }
            if (ammo == 0 && millis() % 1000 <= 500) {
              textSize(50);
              fill(0, 255, 0, 255);
              text("RELOAD!!!", width * 0.275, 80);
            }
          }
        }
      }
    
    
      void countdown(float xPos, float yPos, int startvalue) {
        textFont(clockfont);
        fill(255, 30);
        textSize(70);
        text("88:888", width * xPos, yPos);
        fill(255, 0, 0);
        millisecs = constrain(floor(((startvalue - (millis() - start)) / 1) % 10), 0, 9);
        centisecs = constrain(floor(((startvalue - (millis() - start)) / 10) % 10), 0, 9);
        tenthsecs = constrain(floor(((startvalue - (millis() - start)) / 100) % 10), 0, 9);
        secs = constrain(floor(((startvalue - (millis() - start)) / 1000) % 10), 0, 9);
        tensecs = constrain(floor((startvalue - (millis() - start)) / 10000), 0, 9);
    
        if (tensecs == 1) {
          onecorrection[0] = 0.012;
        } else {
          onecorrection[0] = 0;
        }
        if (secs == 1) {
          onecorrection[1] = 0.012;
        } else {
          onecorrection[1] = 0;
        }
        if (tenthsecs == 1) {
          onecorrection[2] = 0.012;
        } else {
          onecorrection[2] = 0;
        }
        if (centisecs == 1) {
          onecorrection[3] = 0.012;
        } else {
          onecorrection[3] = 0;
        }
        if (millisecs == 1) {
          onecorrection[4] = 0.012;
        } else {
          onecorrection[4] = 0;
        }
    
        if (tensecs == 0 && millis() % 1000 <= 16.666 && millis() - start < startvalue) {
          effects.play(8);
        }
        if (millis() - start >= startvalue - 1500 && limiter[0] == false) {
          effects.play(9);
          limiter[0] = true;
        }
        if (millis() - start >= startvalue && limiter[1] == false) {
          effects.play(10);
          limiter[1] = true;
        }
    
        text(tensecs, width * (xPos + onecorrection[0]), yPos);
        text(secs, width * (xPos + 0.0205 + onecorrection[1]), yPos);
        text(":", width * (xPos + 0.043), yPos);
        text(tenthsecs, width * (xPos + 0.053 + onecorrection[2]), yPos);
        text(centisecs, width * (xPos + 0.0735 + onecorrection[3]), yPos);
        text(millisecs, width * (xPos + 0.095 + onecorrection[4]), yPos);
        textFont(pixfont);
    
        if (tensecs == 0 && secs == 0 && tenthsecs == 0 && centisecs == 0 && millisecs == 0) {
          gameover = true;
        }
      }
    
      void reloading() {
        if (millis() % 580 <= 16.666) {
          ammo++;
          effects.play(13);
        }
      }
      boolean happyfeet = true;
    
      void mousePressed() {
        if (millis() - start >= 6841 && gameover == false) {
          if (ammo > 0) {
            if (iscocking == false && isreloading == false) {
              ammo--;
              iscocking = true;
              cockingtime = millis();
              effects.play(11);
              effects.play(12);
              int falsecount = 0;
              for (int i = 0; i < number; i++) {
                if (cans[i].click() == true) {
    
                } else {
                  falsecount++;
                }
              }
              println(falsecount);
              switch(falsecount) {
              case 25:
                effekts.play(2);
                break;
              case 26:
                effekts.play(2);
                break;
              case 27:
                effects.play(14);
                break;
              case 28:
                if (happyfeet == true) {
                  effekts.play(1);
                  happyfeet = false;
                  break;
                } else {
                  effekts.play(0);
                  happyfeet = true;
                  break;
                }
              }
            }
          }
        }
      }
    
      void keyPressed() {
        if (key == 'r' || key == 'R') {
          if (ammo < 6) {
            isreloading = true;
            limiter[2] = true;
          }
        }
      }
    }
    
  • You can download the images, fonts and sound files I've used here: https://drive.google.com/file/d/1fdd7q1-AerGbbH0ZIwk18I-TClYEbZqX/view?usp=sharing

  • Please post your code via github. It is not difficult. Notice there is something missing: TheGame_v3.

    Do you have an error in the console? What does it say?

    Kf

  • edited December 3 Answer ✓

    Got it. It looks like you have, for example:

    1. hardcoded 15 different sound files into each Sound object
    2. attached a Sound object to every instance of the Button class.
    3. made 6 buttons.

    So you have loaded 15 * 1 * 1 * 6 = 90 loaded sound files. That's bad!

    Instead you could try:

    • Have a Sound object accept 1 sound file in its constructor, and save that in a variable
    • Attach 1 Sound object to a Button
    • Make 6 Buttons:

    1 * 1 * 1 * 6 = 6 sound files. That's good!


    Also, why is this under Library Questions?

  • Have a Sound object accept 1 sound file in its constructor, and save that in a variable

    So should I make a switch for the sound files in the constructor? I'm not sure if I understand that right

  • Thanks a lot! I've now made a switch inside the constructor, so I only load the SoundFiles I actually need.

  • edited December 4

    Glad it is working for you.

    You could also just pass the argument to the class constructor -- no case statements necessary, no reprogramming the entire class every time you add a single new sound.

    You are thinking of a Sound object as a Swiss army knife full of sound files.

    army-2186_640

    I'm suggesting that you use a Sound object like a tool handle. Make as many handles as you want, use one handle for one thing.

    s-l300

    So have the Sound class constructor take an argument, filestring:

    Class Sound {
        SoundFile sf;
        Sound(PApplet p, String filestring){
          sf = new SoundFile(p, filestring);
        }
    }
    

    Plug one sound file into one handle by making a new Sound from a filestring:

    coinSound = new Sound(p, "soundeffects/coin.mp3");
    

    ...and use it:

    float coinamp = 1.0; coinSound.play(coinamp); coinSound.fade();

    Now you can create a bunch of sounds -- as many as you need, but no more.

    cutting-solutions

    like this:

    beepSound = new Sound(p, "soundeffects/beep.mp3");
    bopSound = new Sound(p, "soundeffects/bop.mp3");
    boopSound = new Sound(p, "soundeffects/boop.mp3");
    

    and even create more Constructor arguments to customize them:

    beepSound = new Sound(p, "soundeffects/beep.mp3", myamp, myfade );
    

    ...instead of having a big collection of heavy duty swiss army knives that are all complicated yet all identical.

    images

Sign In or Register to comment.