Functions like mousePressedkeyPressed or the released ones are callback functions, meaning they are called once when the respective event happens. Draw is called in a infinite loop (by default at 60fps) and updates the 'canvas' once each frame. So if you draw inside a callback function the draw will be fast erased by next background call in draw (assuming you have one).
You can do either, use a flag changed in callback function to turn on/off the drawing of the ellipse:
//global
boolean doDraw = false
//in draw
if(doDraw)
ellipse(x, y, w, h)
//in callback
if(key ... the usual)
doDraw = !doDraw // this will toggle the boolean
or, if you are adding lots of stuff to be draw, use a collection and add a new instance at callback
or yet use the var keyPressed direct in draw. Usually this is not recommended, as it tends to be not precise for detecting key presses reporting several times for one press (remember 60 times each sec). But maybe in that case it may be a good choice...
You would need to keep track of if the ellipse should be drawn somehow. If the right combinations of buttons is pressed and the ellipse is not already showing, it should start showing. If the right combinations of buttons is pressed and the ellipse is already showing, it should stop showing.
You will probably want to use a new boolean to track this.
boolean ellipse_showing = false;
When does this value change? When do you use it to determine if something else should happen?
Really I'm just playing around and I was just wondering. When I pasted your first code in, I changed the"CMD" to an ellipse, and it only flashed the ellipse every time I pressed the combo of keys. So I was just wondering if I could have it were, it showed the ellipse as long as I held down the combination of keys. Thanks to _vk it reminded me that I could of just threw everything in a void draw.
thanks again to everybody helping me out!
Answers
@TfGuy44 didn't you mean
keyReleased
instead ofmouseReleased
? :)^:)^
w_pressed must be set false after cmd and after any key (except w)
alright thanks guys!
so say if I wanted to draw an ellipse, how would I make it stay there until i released 's' button? It's just flashing the ellipse.
Functions like
mousePressed
keyPressed
or the released ones are callback functions, meaning they are called once when the respective event happens. Draw is called in a infinite loop (by default at 60fps) and updates the 'canvas' once each frame. So if you draw inside a callback function the draw will be fast erased by nextbackground
call in draw (assuming you have one).You can do either, use a flag changed in callback function to turn on/off the drawing of the ellipse:
or, if you are adding lots of stuff to be draw, use a collection and add a new instance at callback
or yet use the var
keyPressed
direct in draw. Usually this is not recommended, as it tends to be not precise for detecting key presses reporting several times for one press (remember 60 times each sec). But maybe in that case it may be a good choice...This can be combined with handling in callback functions.
You would need to keep track of if the ellipse should be drawn somehow. If the right combinations of buttons is pressed and the ellipse is not already showing, it should start showing. If the right combinations of buttons is pressed and the ellipse is already showing, it should stop showing.
You will probably want to use a new boolean to track this.
When does this value change? When do you use it to determine if something else should happen?
Alright it makes sense now. Thanks for the quick help, I'm new on here and I'm loving it.
Really I'm just playing around and I was just wondering. When I pasted your first code in, I changed the"CMD" to an ellipse, and it only flashed the ellipse every time I pressed the combo of keys. So I was just wondering if I could have it were, it showed the ellipse as long as I held down the combination of keys. Thanks to _vk it reminded me that I could of just threw everything in a void draw. thanks again to everybody helping me out!