Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How can I make my code more efficent when it comes to implementing sound files

$
0
0

as i have this set up as a tree and i want it to look better and work more effiecently than it already does So if you could help with my tree that would be greatly appricated

`import processing.sound.*;

import g4p_controls.*;

import java.util.ArrayList;
import java.util.List;
PImage menu;
SoundFile Harrible;
SoundFile cremeyboy;
SoundFile bianca;
SoundFile C;
SoundFile Excuse;
PImage[] scenes = new PImage[10];
boolean startscreen = true;
boolean startmusic = true;
Node root;
Node currentScene;


void setup() {

  size(1280, 720);
  menu = loadImage("menu.jpg");

  Excuse = new SoundFile(this,"noExcuse.wav");
  C = new SoundFile(this, "Condragulation.wav");
  Harrible = new SoundFile(this, "Harrible.mp3");
  cremeyboy = new SoundFile(this, "cremey boy.wav");
  bianca = new SoundFile(this, "bianca.wav");
  root = new Node("scene1.png", 1,"choose your queen you have the choice from bianca and dela");
  currentScene = root;

  root.left = new Node("scene2.png", 2,"You chose bianca now go to the work room");
  root.right = new Node("scene3.png", 3, "you chose bendelacreme now go to the work room to see to choose you couture (you can go either left or right) ");
  Node iterator;
  iterator = root.left;


  iterator.left = new Node("elganzabianca.png", 69,"Choose Left or Right for which couture you want dependent on what couture you choose will determine the reception you get");
  iterator.right = new Node("elganzabianca.png", 69,"Choose Left or Right for which couture you want dependent on what couture you choose will determine the reception you get");
  iterator = root.right;


  iterator.left = new Node("scene7.png", 1111,"yeet");
  iterator.right = new Node("scene7.png", 9999,"yeet");
  iterator = root.left.left;

  iterator.left = new Node("EndScene1.png", 10,"You have to sashay away");
  iterator.right = new Node("EndScene1.png", 8,"You won the judges over with your couture");
  iterator = root.left.right;

 iterator.left = new Node("EndScene1.png", 8,"Not all the judges agree but you do live another week but you won the challenge");
  iterator.right = new Node("EndScene1.png", 6,"Thats terrible nobody liked your couture and for that you sashay away");
  iterator = root.right.right;

iterator.left = new Node("EndScene1.png", 5,"You argued with ru now you sashay away");
  iterator.right = new Node("EndScene1.png", 8,"Great Job you live to see another");
  iterator = root.right.left;

  iterator.left = new Node("EndScene1.png", 6,"Thats Horrible ");
  iterator.right = new Node("EndScene1.png", 8,"You Won the Challenge you can now leave the stage a get ready for another week");
  iterator = root.left.left.right;

   iterator.left = new Node("Finscreen.png", 8,"yeet");
  iterator.right = new Node("Finscreen.png", 9,"yeet");
  iterator = root.left.right.left;

  iterator.left = new Node("Finscene.png", 10,"Sorry Dela No one liked your couture so you haved to sashay away");
  iterator.right = new Node("Finscene.png", 11,"Do the stanky leg b xoxoxo :^) you won now you can sleep ");
  iterator = root.right.right.left;
  createGUI();
}

void draw() {
  if (startscreen) {
    background(menu);


  } else {
    background(255);
    startmusic = false;
    image(currentScene.scene, 0, 0);
  }

  text(currentScene.Dialog, 500, 100);


//these if statements play the audio and stop it after it has has played



  if (currentScene.index == 1) {
    currentScene.index =-1;
  }

  if (currentScene.index ==-1){


  }
  if (currentScene.index == 3) {


    cremeyboy.play();
    currentScene.index =-3;
  }

  if (currentScene.index ==-3){


  }

  if (currentScene.index == 2) {
    bianca.play();
    currentScene.index =-2;
  }

  if (currentScene.index ==-2){


  }

    if (currentScene.index == 6) {
    Harrible.play();
    currentScene.index =-6;
  }

  if (currentScene.index ==-6){

  }
      if (currentScene.index == 7) {
    Harrible.play();
    currentScene.index =-7;
  }

  if (currentScene.index ==-7){

  }

     if (currentScene.index == 5) {
    Harrible.play();
    currentScene.index =-5;
  }

  if (currentScene.index ==-5){


  }
    if (currentScene.index == 8) {
    C.play();
    currentScene.index =-8;
  }

  if (currentScene.index ==-8){

  }

     if (currentScene.index == 10) {
    Excuse.play();
    currentScene.index =-10;
  }

  if (currentScene.index ==-10){

  }
  println(255, currentScene.index);
}

void keyPressed() {

  if (keyCode == RIGHT) {

    currentScene = currentScene.right;


  }
    if (keyCode == LEFT){

      currentScene = currentScene.left;

    }

}

DISPLAY
interface Display{
 void display(); 
}

NODE
public class Node implements Display{
  void display(){

  }

 PImage scene;
 int index;
 Node left;
 Node right;
  String Dialog;
 Node (String filename,int i, String DialogInput){ 
   scene = loadImage(filename);
   index = i;
   Dialog = DialogInput;


 }

}

Gui

/* =========================================================
 * ====                   WARNING                        ===
 * =========================================================
 * The code in this tab has been generated from the GUI form
 * designer and care should be taken when editing this file.
 * Only add/edit code inside the event handlers i.e. only
 * use lines between the matching comment tags. e.g.

 void myBtnEvents(GButton button) { //_CODE_:button1:12356:
     // It is safe to enter your event code here  
 } //_CODE_:button1:12356:

 * Do not rename this tab!
 * =========================================================
 */

public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:446807:
  println("button1 - GButton >> GEvent." + event + " @ " + millis());
  startscreen = false;
  button1.dispose();
  button2.dispose();
} //_CODE_:button1:446807:

public void button2_click1(GButton source, GEvent event) { //_CODE_:button2:341443:
  println("button2 - GButton >> GEvent." + event + " @ " + millis());
  exit();
} //_CODE_:button2:341443:



// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  button1 = new GButton(this, 116, 511, 127, 43);
  button1.setText("Start");
  button1.setLocalColorScheme(GCScheme.GOLD_SCHEME);
  button1.addEventHandler(this, "button1_click1");
  button2 = new GButton(this, 116, 558, 128, 52);
  button2.setText("Exit");
  button2.setLocalColorScheme(GCScheme.ORANGE_SCHEME);
  button2.addEventHandler(this, "button2_click1");
}

// Variable declarations 
// autogenerated do not edit
GButton button1; 
GButton button2; `

Viewing all articles
Browse latest Browse all 2896

Trending Articles