Can't move with scripts - HTML5

Community Beginner ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

So I've been trying to create a game with Adobe

Animate and HTML5 canvas just for fun.

Anyways I can't seem to get player movement to work.

I've tried using:

var canvas = document.getElementById("canvas");
canvas.addEventListener("keydown", doKeyDown, true);
function doKeyDown(e) {
	var playerSpeed = 100;
	//W Key
	if (e.keyCode == 87) {
		this.player.y-=playerSpeed;
	}
	//S Key
	if (e.keyCode == 83) {
		this.player.y+=playerSpeed;
	}
	//A Key
	if (e.keyCode == 65) {
		this.player.x-=playerSpeed;
	}
	//D Key
	if (e.keyCode == 68) {
		this.player.x+=playerSpeed;
	}
}

 And it didn't work, so if you can help please do.

Thanks in advance.

TOPICS
Code

Views

65

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Oct 01, 2021 Oct 01, 2021
Hi. There's no need to create a reference to canvas because one is automatically created by Animate and is stored in a global variable called canvas. To move characters using keys, there are two samples (simple and advanced) in this link: https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/move_char_using_keys Please let us know if you haver any further questions. Regards, JC

Likes

Translate

Translate
Community Beginner ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

Oh by the way I want to move the player with the wasd keys

Likes

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
Adobe Community Professional ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

Hi.

 

There's no need to create a reference to canvas because one is automatically created by Animate and is stored in a global variable called canvas.

 

To move characters using keys, there are two samples (simple and advanced) in this link:
https://github.com/joao-cesar/adobe/tree/master/animate%20cc/html5_canvas/move_char_using_keys

 

Please let us know if you haver any further questions.

 

Regards,

JC

Likes

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 Beginner ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

that worked thank you so much

Likes

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
Adobe Community Professional ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

LATEST

You're welcome!

Likes

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