Copy link to clipboard
Copied
Hello,
I am developing a little game in AnimateCC HTML5 Canvas scripts, trying to create a "flappy bird" effect when the user presses the space bar. It works fine when I test it on the browser, however, after publishing it as HTML and trying to run it on a Live Server in VSCode (it doesn't run on the browser after publishing) the spacebar press is not working at all. But the rest of the game seems to be just fine.
Here is a snippet of my code:
var spacebar_pressed = false;
var gameStart = false;
var userVelocity = 0;
var gravity = 0.5;
var user = this.user;
window.onkeydown = function (event) {
if (event.keyCode == 32) {
gameStart = true;
spacebar_pressed = true;
};
};
window.onkeyup = function () {
if (event.keyCode == 32) {
spacebar_pressed = false;
};
}
function fallDown() {
user.y = user.y + userVelocity;
userVelocity = userVelocity + gravity;
}
function flyUp() {
userVelocity = -15;
user.play();
}
function animate() {
if (spacebar_pressed) {
flyUp();
} else if (gameStart) {
fallDown();
};
requestAnimationFrame(animate);
};
animate();
Any ideas on why it isn't working?
Thank you.
Copy link to clipboard
Copied
any errors in the developer console?
Copy link to clipboard
Copied
Not during testing, everything works ok and there are no errors. I don't really know how to open a developer console when running the published work in a server and not a browser...
Copy link to clipboard
Copied
you're not opening in a browser from that server?