• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Spacebar Press not working when game is published and running in VSCode LiveServer extension.

New Here ,
Jan 02, 2023 Jan 02, 2023

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.

TOPICS
ActionScript , Code , Other , Publish package

Views

150

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

any errors in the developer console?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2023 Jan 02, 2023

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

LATEST

you're not opening in a browser from that server?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines