FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 779 : keyPressed doesn't acknowledge
Last modified: 2008-06-11 08:41
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
INVALID -
Pr
i
ority:
P2
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
efghsus
Assigned To:
fry
Attachment
Type
Created
Size
Actions
Description
: Opened: 2008-05-29 07:18
in process of writing a prog at some point the keypressed function wether
as own procedure or as bool in the draw() method would not aknwoledge any
keystrokes. when playing around with the code, i found that even changing
or removing remarks would affect the behaviour of this. happened with the
0135beta, not testet as embedded in html.
here's the code which doesnt work, however changing some lines within the
big remarkblock at the end will sometimes enable keystrokes again. also, if
they don't work, sometimes that happens after the 2nd compilation or
execution of the prog.
please forgive me if im temporarily stoopid or something. found nothing in
the other bug sections so far.
----8<-----8<-----
void setup() {
size(200,200);
}
void draw() {
if (keyPressed==true) {
background(0);
}
}
/*
class tdash {
tdashfield[][] Map;
int w,h;
int ngems;
tdash() {
ngems=0;
newlevel(20,20);
}
// create and initialize the Map[][] structure
void newlevel(int xs, int ys) {
Map = new tdashfield[ys][xs];
for (int j=0; j<ys; j++) {
for (int i=0; i<xs; i++) {
Map[j][i] = new tdashfield();
}
}
w=xs;
h=ys;
ngems=0;
}
// create random level
void randomlevel(int xs, int ys,int seed) {
randomSeed(seed);
for (int j=0; j<ys; j++) {
for (int i=0; i<xs; i++) {
if (floor(random(2))==0) Map[j][i].typ=_sand;
if (floor(random(9))==0) Map[j][i].typ=_wall;
if (floor(random(13))==0) Map[j][i].typ=_stone;
if (floor(random(18))==0) { Map[j][i].typ=_gem; ngems++; }
}
}
boarder();
// add at least one gem
if (ngems==0) {
Map[floor(random(ys-2)+1)][floor(random(xs-2)+1)].typ = _gem;
ngems++;
}
}
// draw a wall around level
void boarder() {
for (int i=0;i<w;i++) { Map[0][i].typ=_wall; Map[h-1][i].typ=_wall; }
for (int i=0;i<h;i++) { Map[i][0].typ=_wall; Map[i][w-1].typ=_wall; }
}
// draw the level in plain mode
void drawlevel() {
background(0);
int sx=min(w,mx);
int sy=min(h,my);
for (int j=0;j<sy;j++) {
for (int i=0;i<sx;i++) {
float i1=i*fs;
float j1=j*fs;
switch (Map[j][i].typ) {
case 0: fill(0); stroke(0); rect(i1,j1,fs,fs); break;
case 1: fill(100,80,0); stroke(100,70,0); rect(i1,j1,fs,fs); break;
case 2: fill(130,130,130); stroke(70,70,70); rect(i1,j1,fs,fs);
break;
case 3: fill(70,60,60); stroke(30,30,30);
ellipse(i1+fs/2,j1+fs/2,fs,fs); break;
case 4: fill(170,210,250); stroke(70,110,130);
ellipse(i1+fs/2,j1+fs/2,fs,fs); break;
}
}
}
}
// trys to apply some gravity to the object Map[j][i]
boolean fall(int i, int j) {
if (Map[j+1][i].typ==0) {
Map[j+1][i].ntyp=Map[j][i].typ;
Map[j+1][i].falling=1;
Map[j][i].ntyp=0;
return(true);
}
if ((Map[j+1][i+1].typ==0)&(Map[j][i+1].typ==0)) {
Map[j+1][i+1].ntyp=Map[j][i].typ;
Map[j+1][i+1].falling=1;
Map[j][i].ntyp=0;
return(true);
}
if ((Map[j+1][i-1].typ==0)&(Map[j][i-1].typ==0)) {
Map[j+1][i-1].ntyp=Map[j][i].typ;
Map[j+1][i-1].falling=1;
Map[j][i].ntyp=0;
return(true);
}
return(false);
}
// make one step in time
void timestep() {
int i,j;
for (j=1;j<h-1;j++) {
for (i=1;i<w-1;i++) {
Map[j][i].ntyp=Map[j][i].typ;
}
}
for (j=1;j<h-1;j++) {
for (i=1;i<w-1;i++) {
if ((Map[j][i].typ==_stone)|(Map[j][i].typ==_gem)) {
if (fall(i,j)) { } else {
Map[j][i].falling=0;
}
}
}
}
for (j=1;j<19;j++) {
for (i=1;i<19;i++) {
Map[j][i].typ=Map[j][i].ntyp;
}
}
}
}
// structure holding each fields variables
class tdashfield {
int typ,ntyp,falling;
tdashfield() {
typ = 0;
ntyp=0;
falling=0;
}
}
*/
Additional Comment
#1 From fry 2008-05-29 07:58
my guess is that your code is using up a lot of cycles, and not giving any
time for draw() to run, so the "if (keyPressed)" code doesn't actually have
a chance to go.
Additional Comment
#2 From fry 2008-06-11 08:41
no response, closing bug.