Hi, i'm testing something about circles fading out which are triggered by keyPressed().
Triggers the sound to play once. Can be called again before the sound finishes playing.
I have made two sketches; one with an image fading out as time goes, the other with a short sound triggered by keyPressed().
i want to combine these two sketches, but the new sketch does not work well.
Can anybody help me?
Here's two codes;
'an image fading out as time goes'
- PImage test13;
- float time = 0;
- float going = 1;
- void setup()
- {
- size(500,500);
- test13 = loadImage("pattern13.png");
- }
- void draw()
- {
- background(0);
- time=time+going;
- tint(255, 200-time);
- imageMode(CENTER);
- image(test13, width/2, height/2);
- }
'a short sound triggered by keyPressed()'
- /////////////setting for sound///////////////
- import ddf.minim.*;
- Minim minim;
- //set names of intagers(which becomes random index for same sound values)
- int indexHigh3;
- //set names of sounds ([value] indicates the numbers of same sound)
- AudioSample high3;
- void setup()
- {
- size(1024, 768);
- minim = new Minim(this);
- // load a file, give the AudioPlayer buffers that are 512 samples long
- high3 = minim.loadSample("3-3_1.wav", 512);
- }
- void draw()
- {
- background(0,0,75);
- }
- void keyPressed()
- {
- imageMode(CENTER);
- if ( key == 'e' )
- {
- high3.trigger();
- }
- void stop()
- {
- // always close Minim audio classes when you are done with them
- high3.close();
- // always stop Minim before exiting
- minim.stop();
- super.stop();
- }
The sound is 3-4sec long and it does not stop after releasing key 'e'.
However, when I adapt keyPressed to the first sketch, image disappears after 1 frame.(it blinks only once)
- PImage test13;
- float time = 0;
- float going = 1;
- void setup()
- {
- size(500,500);
- test13 = loadImage("pattern13.png");
- }
- void draw()
- {
- background(0);
- }
- void keyPressed()
- {
- if (key == 'e')
- {
- time=time+going;
- tint(255, 200-time);
- imageMode(CENTER);
- image(test13, width/2, height/2);
- }
- }
I think that the second sketch works because of trigger() from minim.
The document for minim says;
Triggers the sound to play once. Can be called again before the sound finishes playing.
Can I make my image stay and fade out even though key is released? (just like that a sound does not stop after releasing key)
I want similar effect of my second sketch, but on image not on sound.
I want to 'trigger' my image to appear and fade out by pressing key.
I think it might be possible if i create void display() or something...like class...? But I'm not sure and don't know how to make it.. I've tried it but stuck in the middle. My brain is messed up. Or should I use array? I don't know where to start....T_T
1