[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.29,0:00:03.80,Default,,0000,0000,0000,,You've already learned how \Nto make your own variables and use them. Dialogue: 0,0:00:03.80,0:00:06.66,Default,,0000,0000,0000,,Now we're going to learn \Nabout two special variables: Dialogue: 0,0:00:06.66,0:00:09.35,Default,,0000,0000,0000,,{\i1}mouseX{\i0} and {\i1}mouseY{\i0}. Dialogue: 0,0:00:10.22,0:00:12.67,Default,,0000,0000,0000,,You never have to make \Nthese variables yourself, Dialogue: 0,0:00:12.67,0:00:15.98,Default,,0000,0000,0000,,and in fact you shouldn't,\Nbecause they already exist. Dialogue: 0,0:00:15.98,0:00:19.60,Default,,0000,0000,0000,,You see, the program sets the values \Nof these variables behind the scenes, Dialogue: 0,0:00:19.60,0:00:23.76,Default,,0000,0000,0000,,making sure that the value of mouseX\Nis always the {\i1}x{\i0} position of your mouse, Dialogue: 0,0:00:23.76,0:00:27.55,Default,,0000,0000,0000,,and the value of mouseY \Nis always the {\i1}y{\i0} position of your mouse. Dialogue: 0,0:00:27.55,0:00:30.86,Default,,0000,0000,0000,,This makes it really easy to do\Ncool, interactive things Dialogue: 0,0:00:30.86,0:00:32.56,Default,,0000,0000,0000,,based on the user's mouse position. Dialogue: 0,0:00:33.43,0:00:35.87,Default,,0000,0000,0000,,Let's look at this ellipse\Nthat I'm drawing here. Dialogue: 0,0:00:35.87,0:00:39.37,Default,,0000,0000,0000,,So, right now, \NI'm always drawing it at 200, 200. Dialogue: 0,0:00:40.61,0:00:43.83,Default,,0000,0000,0000,,If I use mouseX and mouseY, \Nthese special variables, Dialogue: 0,0:00:44.44,0:00:48.29,Default,,0000,0000,0000,,then I can actually draw it\Nat mouseX and mouseY. Dialogue: 0,0:00:49.34,0:00:52.36,Default,,0000,0000,0000,,Now, if I move my mouse \Nover the canvas, you can see Dialogue: 0,0:00:52.36,0:00:55.29,Default,,0000,0000,0000,,the ellipse is always being drawn\Nwhere my mouse is -- Dialogue: 0,0:00:55.29,0:00:57.19,Default,,0000,0000,0000,,so it follows my mouse around. Dialogue: 0,0:00:57.19,0:01:00.00,Default,,0000,0000,0000,,That's pretty cool; can you tell\Nwhat I'm drawing? Whee! Dialogue: 0,0:01:00.47,0:01:04.12,Default,,0000,0000,0000,,If you're going to use mouseX and mouseY,\Nyou've got to make sure Dialogue: 0,0:01:04.12,0:01:06.36,Default,,0000,0000,0000,,that you use them inside\Nthe {\i1}draw = function (){\i0} Dialogue: 0,0:01:06.36,0:01:08.14,Default,,0000,0000,0000,,because look what happens Dialogue: 0,0:01:09.58,0:01:12.70,Default,,0000,0000,0000,,if we move these two lines of code\Noutside the {\i1}draw = function (){\i0}. Dialogue: 0,0:01:13.29,0:01:14.44,Default,,0000,0000,0000,,You see? Dialogue: 0,0:01:14.87,0:01:19.21,Default,,0000,0000,0000,,Now this code here only gets run once, Dialogue: 0,0:01:19.21,0:01:21.81,Default,,0000,0000,0000,,so this ellipse is only drawn once, Dialogue: 0,0:01:21.81,0:01:24.04,Default,,0000,0000,0000,,and it's drawn wherever my mouse\Nhappened to be Dialogue: 0,0:01:24.04,0:01:26.14,Default,,0000,0000,0000,,at the very, very beginning\Nof the program. Dialogue: 0,0:01:26.72,0:01:30.34,Default,,0000,0000,0000,,That's why we {\i1}need{\i0} to have it\Ninside the {\i1}draw = function (){\i0}, Dialogue: 0,0:01:30.34,0:01:32.46,Default,,0000,0000,0000,,because the {\i1}draw = function (){\i0}\Nis this function Dialogue: 0,0:01:32.46,0:01:35.78,Default,,0000,0000,0000,,that's called repeatedly over\Nand over while our program is running. Dialogue: 0,0:01:35.78,0:01:39.15,Default,,0000,0000,0000,,So we want that when it gets called,\Nit looks at what the current value Dialogue: 0,0:01:39.15,0:01:43.25,Default,,0000,0000,0000,,of mouseX and mouseY is, and then\Nit draws the ellipse at that position. Dialogue: 0,0:01:43.25,0:01:46.06,Default,,0000,0000,0000,,If you think about it, it's \Nactually very similar to an animation -- Dialogue: 0,0:01:46.06,0:01:48.56,Default,,0000,0000,0000,,it's changing over time, \Njust in a different way. Dialogue: 0,0:01:49.19,0:01:52.06,Default,,0000,0000,0000,,Okay, now we can do \Nall sorts of fun things. Dialogue: 0,0:01:52.57,0:01:55.72,Default,,0000,0000,0000,,What if, instead of drawing it \Nat mouseX and mouseY, Dialogue: 0,0:01:56.35,0:02:02.59,Default,,0000,0000,0000,,I drew it at mouseX still but I fixed\NmouseY at something like 300? Dialogue: 0,0:02:03.23,0:02:07.37,Default,,0000,0000,0000,,Now you can see that the ellipse \Nonly follows my x coordinate, Dialogue: 0,0:02:07.37,0:02:09.20,Default,,0000,0000,0000,,ignoring whatever I do in the y. Dialogue: 0,0:02:10.99,0:02:16.87,Default,,0000,0000,0000,,Then, what if I now draw it at mouseX\Nand mouseY, bringing that back, Dialogue: 0,0:02:16.87,0:02:19.76,Default,,0000,0000,0000,,but I get rid of the background,\Njust commenting that out? Dialogue: 0,0:02:20.55,0:02:25.23,Default,,0000,0000,0000,,{\i1}Woo{\i0}! Now look, I've got \Nthis funky paintbrush thing. Dialogue: 0,0:02:25.23,0:02:27.03,Default,,0000,0000,0000,,That's pretty awesome. Dialogue: 0,0:02:27.03,0:02:30.47,Default,,0000,0000,0000,,Or, or, I could even switch\Nthese variables. Dialogue: 0,0:02:31.03,0:02:32.89,Default,,0000,0000,0000,,Let me bring back our background. Dialogue: 0,0:02:32.89,0:02:37.70,Default,,0000,0000,0000,,I'll switch these variables here, \NmouseY and mouseX, Dialogue: 0,0:02:37.70,0:02:39.20,Default,,0000,0000,0000,,and then see what happens. Dialogue: 0,0:02:39.20,0:02:41.23,Default,,0000,0000,0000,,Now it just feels really, really weird. Dialogue: 0,0:02:41.23,0:02:43.85,Default,,0000,0000,0000,,I've got these mouse controls \Nthat are doing opposite Dialogue: 0,0:02:43.85,0:02:45.58,Default,,0000,0000,0000,,of what I would expect them to. Dialogue: 0,0:02:45.58,0:02:48.32,Default,,0000,0000,0000,,But that's cool, you could imagine \Nmaking a whole game Dialogue: 0,0:02:48.32,0:02:50.95,Default,,0000,0000,0000,,which is about trying to draw something\Nor do something Dialogue: 0,0:02:50.95,0:02:52.94,Default,,0000,0000,0000,,while using inverted mouse controls. Dialogue: 0,0:02:53.04,0:02:58.91,Default,,0000,0000,0000,,That's it for mouseX and mouseY --\Nreally, pretty fun. Enjoy!