How to play different files from different items in dropdown menu from controlp5 ?
in
Contributed Library Questions
•
3 months ago
Hi, I
have created 3 sketches which play music, animate things and load background images.
I'd like to join all them together into one sketch by using dropdown menu from controlp5 library.
I've done the dropdown menu which displays different images when the different items have been choosen, but I need more fuctionality - music and animation, different for different items.
I'd like to join all them together into one sketch by using dropdown menu from controlp5 library.
I've done the dropdown menu which displays different images when the different items have been choosen, but I need more fuctionality - music and animation, different for different items.
How can I make these items appear different objects, players, for example ?
Here is my code:
- import controlP5.*;
- ControlP5 cp5;
- DropdownList d1;
- PImage[] images = new PImage[3];
- int selectedImage;
- int cnt = 0;
- void setup() {
- size(775, 500);
- cp5 = new ControlP5(this);
- d1 = cp5.addDropdownList("ImageSelect",width/2-50,100,100,120).setPosition(0, 22);
- customize(d1);
- images[0] = loadImage("visuals_1.png");
- images[1] = loadImage("visuals_2.png");
- images[2] = loadImage("visuals_3.png");
- }
- void customize(DropdownList ddl) {
- ddl.setBackgroundColor(color(250));
- ddl.setItemHeight(20);
- ddl.setBarHeight(20);
- ddl.captionLabel().set("Interval view");
- ddl.captionLabel().style().marginTop = 5;
- ddl.captionLabel().style().marginLeft = 5;
- ddl.valueLabel().style().marginTop = 5;
- ddl.addItem("1st layer", 0);
- ddl.addItem("2nd layer", 1);
- ddl.addItem("3rd layer", 2);
- ddl.setColorBackground(color(60));
- ddl.setColorActive(color(255, 128));
- }
- void draw() {
- background(128);
- image(images[selectedImage],0,0);
- }
- void controlEvent(ControlEvent theEvent) {
- if (theEvent.isGroup()) {
- if (theEvent.group().name() == "ImageSelect") {
- selectedImage = int(theEvent.group().value());
- }
- } else if(theEvent.isController()) {
- }
- }
1