Loading...
Processing Forum
Recent Topics
All Forums
Move this topic
Forum :
Share your Work
Programming Questions
Core Library Questions
Contributed Library Questions
Android Processing
Processing with Other Languages
Integration and Hardware
Library and Tool Development
Events and Opportunities
General Discussion
Sub forum :
Move this topic
Cancel
Programming Questions
nfeldbaum
Can I use keyPressed() and get the affects to stay
in
Programming Questions
•
1 year ago
Hi,
Is it possible to use keyPressed (and then key ==) and get what happens to stay on the screen? For example:
if (keyPressed)
{
if (key == 'o')
{
image(img4,x,mouseY);
x--;
}
Can I get the image to stay on the screen and to keep moving?
1
Replies(2)
benja
Re: Can I use keyPressed() and get the affects to stay
1 year ago
The variable "key" always holds the last key that has been pressed. Example:
void setup(){}
void draw(){
if(key == 'o')
background(255, 0, 0);
else
background(0, 0, 0);
}
If you want to use other keys as well, you would have to store use a variabel to store, that a certain key has already been pressed. Here is an example where 'o' toggles the background-color:
boolean oPressed;
void setup(){}
void draw(){
if(oPressed)
background(255, 0, 0);
else
background(0, 0, 0);
}
void keyPressed(){
if(key == 'o')
oPressed = !oPressed;
}
Leave a comment on benja's reply
calsign
Re: Can I use keyPressed() and get the affects to stay
1 year ago
Ah! Mere seconds!
Try creating a global
boolean
, setting that to
true
, and then checking for that in
draw()
:
boolean imageVisible; //The variable
void setup() {
size(400, 400);
//Load image and do other stuff
}
void draw() {
if(imageVisible) { //Check the variable
image(img4, x, mouseY);
x --;
}
}
void keyPressed() {
if(key == 'o') {
imageVisible = true;
}
}
Leave a comment on calsign's reply
Change topic type
Topic Type :
Discussions
Questions
No of days :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to nfeldbaum's question
Top
Reply
{"z20521894":[25080000001762961],"z22342353":[25080000001764578],"z5123726":[25080000001765141]}
Statistics
2
Replies
295
Views
1
Followers
Tags
No tags available for this topic.
Cancel
Actions
Permalink
Related Posts
Trying to create getter/setter meth...
detect what keys are currently held...
Use of keyPressed to call new sates...
How to avoid repetition when a key ...
tint get and explode !!!