• fullscreen
  • sketch64356.pde
  • int xPos = 25;
    int yPos = 25;
    void setup() {
      size(400, 200);
    void draw() {
      if (keyPressed == true) {
        if (key == CODED) {
          if (keyCode == UP) {
            yPos -= 2;
          if (keyCode == DOWN) {
            yPos += 2;
          if (keyCode == LEFT) {
            xPos -= 2;
          if (keyCode == RIGHT) {
            xPos += 2;
      rect(xPos, yPos, 50, 50);
      fill(0, 0, 0, 10);
      rect(0, 0, 400, 200);


    tweaks (0)

    about this sketch

    This sketch is running in HTML5 using Processingjs.



    Report Sketch

    Report for inappropriate content

    Please provide details if possible:

    Your have successfully reported the sketch. Thank you very much for helping to keep OpenProcessing clean and tidy :)

    Make a Copyright Infringement claim

    Tim Ewing


    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    Another fading rectangle, this time with arrow key movement.

    Andy Brent
    21 Jun 2012
    This sketch illustrates one of the key issues I had when creating pong. If I were to want the square would i need to make a statement which says "if keypressed'up' is true&&key; pressed right is true then move in the right diagonal"? Also, it's very glitchy when to keys are pressed at once, or you have the up key pressed down for example, then press the right key then soon after releasing the up key.
    Nick Gonzales
    23 Jun 2012
    The problem lies in the fact that "key" can only store one value at a time like any other variable. If you press 'w', then press 's,' for example, key would store 'w,' then store 's.' You need to create some way of remembering the previous key presses.

    Check the file "Input" I attached to my "WorldTesting" and "Screen Wrapping" sketches for an example.
    You need to login/register to comment.