File tree Expand file tree Collapse file tree
src/eu/barkmin/processing/scratch Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package eu .barkmin .processing .scratch ;
2+
3+ public class ScratchAnimatedSprite {
4+ }
Original file line number Diff line number Diff line change 11package eu .barkmin .processing .scratch ;
22
3+ import com .sun .org .apache .xpath .internal .operations .Bool ;
34import processing .core .PApplet ;
45import processing .core .PConstants ;
56import processing .core .PGraphics ;
@@ -34,7 +35,7 @@ public class ScratchStage {
3435 private float mouseX ;
3536 private float mouseY ;
3637 private boolean mouseDown ;
37- private int keyCodePressed = - 1 ;
38+ private HashMap < Integer , Boolean > keyCodePressed = new HashMap <>() ;
3839
3940 private ScratchStage (PApplet parent , boolean debug ) {
4041 parent .imageMode (PConstants .CENTER );
@@ -448,10 +449,10 @@ public boolean isMouseDown() {
448449 public void keyEvent (KeyEvent e ) {
449450 switch (e .getAction ()) {
450451 case KeyEvent .PRESS :
451- keyCodePressed = e .getKeyCode ();
452+ keyCodePressed . put ( e .getKeyCode (), true );
452453 break ;
453454 case KeyEvent .RELEASE :
454- keyCodePressed = - 1 ;
455+ keyCodePressed . put ( e . getKeyCode (), false ) ;
455456 break ;
456457 }
457458 }
@@ -463,7 +464,11 @@ public void keyEvent(KeyEvent e) {
463464 * @return key pressed
464465 */
465466 public boolean isKeyPressed (int keyCode ) {
466- return keyCodePressed == keyCode ;
467+ Boolean isPressed = keyCodePressed .get (keyCode );
468+ if (isPressed == null ) {
469+ return false ;
470+ }
471+ return isPressed ;
467472 }
468473
469474 /**
You can’t perform that action at this time.
0 commit comments