Skip to content

Commit ffb29ae

Browse files
committed
e.preventDefault() works for the pong example
1 parent 9765c65 commit ffb29ae

File tree

1 file changed

+7
-0
lines changed
  • src/content/examples/en/10_Games/01_Ping_Pong

1 file changed

+7
-0
lines changed

src/content/examples/en/10_Games/01_Ping_Pong/code.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function setup() {
3434
describe(
3535
'Two narrow white rectangles and a white square representing the paddles and ball in a game of ping pong. The player scores are displayed in the upper corners, and initially text reads "Click to start"'
3636
);
37+
38+
// Add a listener to the window to "eat" the arrow key events
39+
window.addEventListener("keydown", function(e) {
40+
if(["ArrowUp", "ArrowDown"].indexOf(e.code) > -1) {
41+
e.preventDefault();
42+
}
43+
}, false);
3744
}
3845

3946
function draw() {

0 commit comments

Comments
 (0)