Canvas Bootcamp 14 - Mouse Coordinates JavaScript Tutorial

preview_player
Показать описание
In this exercise we are going to cover one of the most crucial aspects of making interactive canvas applications with JavaScript. We will demonstrate how to read or capture the user mouse coordinates upon specific events.
Рекомендации по теме
Комментарии
Автор

Five years on and this is still extremely useful.
Many Thanks for sharing your knowledge

samdavepollard
Автор

wow very important tutorial even after 9 years

mohammadnoushadsiddiqui
Автор

I used this explanation to move the paddle on my little breakout game. Thanks brother.

ninthcrusade
Автор

Great video! Exactly what I was looking for. Going to watch all the rest videos.

janokotek
Автор

Great video. You have explained things much better than many others. Thanks much!

joeandurien
Автор

These tutorials ROCK.  They are the best things going!!!  Change

chrismalcheski
Автор

This is actually a very important tutorial.. Thank you Adam...

killerb
Автор

If you create an element and add ID attribute to it, browser will automatically create a variable equal to its ID and referencing it to that element. So you don't need to create the "status" variable and assign because "status was already created, you can just type "status" without creating a var and it's equal to already.

great videos btw, im learning a lot. thanks.

edko
Автор

Amazing man, thanks for clarifying mouse coordinates! :)

Anothergames
Автор

Hey Thanks, Adam Khoury, this video is very help full for me, to do my Class project about Canvas. Thanks.

Jony
Автор

Hai, I want to get the canvas coordinates when canvas is wrapped under div which is scrollable area.

anandks
Автор

How many parts will this series have? I think they're quite helpful. Thanks a lot Adam!

ChristFan
Автор

I wanted to change the background color according to the mouse position on the canvas, This is the bass of the my idea so thank you for that. How would I apply this to my code? do I use a class/id?

avigdahlpeck
Автор

Alright, I understand everything in this video. I'm just curious. After making the rectangles show up where the clientX, ClientY clicks, how would I precede to animate the rectangles? Like for instance, to make the rectangles to slide down the screen.

augusttierney
Автор

Scrolling the page that the canvas is on ruins the Y-coordinate for me! What is going on?

oomoses
Автор

Hey Adam, thatnk you for this greate video! Please I have a question to ask you; I've tried many ways to create a circle enstead of a box. see this code which id did not work with me.

<!DOCTYPE html>
 <html>
 <head>
 <style>
 </style>
 <script>
window.onload = function () {
var canvas =
ctx = canvas.getContext("2d");
x1 = 50;
y1 = 50;
moving, move;

ctx.canvas.addEventListener("mousedown", function(event){ moving= true; move(event); });
ctx.canvas.addEventListener("mousemove", function(event){ move(event); });
ctx.canvas.addEventListener("mouseup", function(){ moving= false; });

function move(event){
if (moving){
mouseX = event.clientX - ctx.canvas.offsetLeft;
mouseY = event.clientY - ctx.canvas.offsetTop;

= mouseX;
= mouseY;

0, 500, 500);
= "red";
mouseY, 15, 0, Math.PI*2, false);


}
}

}
 </script>
 </head>
 <body>
 <canvas id="canvas" width="500" height="500" ></canvas>
 </body>
 </html>

Thank you for your time!!  ^___^

adildafrallah
join shbcf.ru