We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Ok, I am using the KeyCoded method to get a rectangle to move around the screen. I know the challenges of it already, I am just trying to figure out a way around it.
1) Since the Draw Function continues to run, I am pressing the LEFT arrow and the rectangle runs off the screen leaving a ghosting trail behind it. So instead I am going to use KeyRelease(): so that it doesn`t continually move once the key is not being pressed.
2) The trail is because I am not clearing the screen or changing the background to white after each key press - but what if I am making a game and there are other objects on the screen, I don`t want them to disappear each time the key is pressed. How can I get around this.
x1=100 x2=25 y1=0 y2=25 def setup(): size(200, 200) background(255) # white def draw(): global x1,y1,x2,y2 fill(155) rect(x1, y1, x2, y2) def keyReleased(): global x1, y1, x2, y2 rect(x1, y1, x2, y2) if (key==CODED): if (keyCode == LEFT): x1=x1-10 rect(x1, y1, x2, y2) elif (keyCode== RIGHT): x1=x1+10 rect(x1,y1,x2,y2) elif (keyCode== UP): y1=y1-10 rect(x1,y1,x2,y2) elif (keyCode== DOWN): y1=y1+10 rect(x1,y1,x2,y2)