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.
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
Copy link to clipboard
Copied
Oh by the way I want to move the player with the wasd keys
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
Copy link to clipboard
Copied
that worked thank you so much
Copy link to clipboard
Copied
You're welcome!