Hello, everyone, today I will show you how to draw the mouse frame
we officially start
First, let's draw an empty character
Then let's code
1. Preparation
(1) Expansion
brush
Add this extension ↑
(2) variable
Actually, you only need 4 variables
↑These two variables, as the name suggests, when the mouse clicks on the screen, the instant mouse x and y will be stored here.
↑ These two variables will be discussed later, it is a bit early now
But for the sake of framing in the future, here is another
↑ Used to detect whether to draw the mouse frame
start programming
First, let's set the variable
Then start the main code:
One of the key points of this lesson - drawing the mouse frame (self-made building blocks)
First, build homemade blocks
Note: Be sure to select "do not refresh the screen when running"!
Define this block:
Before that, I want everyone to understand a truth
Here, I drew a picture:
This picture can clearly illustrate my thinking
All we have to do is draw a cycle and loop it over and over again
initial positioning
painting
combination:
Done, now we just need to put it in the main code loop
However, is there some BUG, the mouse frame is drawn as soon as I click the mouse?
No, the mouse box in the computer is not like this!
It is very simple to fix this BUG, remember those two variables?
"Tolerance value x" indicates the error tolerance value of the distance from mouse x to x when the mouse is clicked
"Tolerance value y" is the same as the distance between y
Anyone who has been to junior high school knows:
The distance from a to b = |ab|
If their distance is not less than the tolerance value, then draw!
This is the thing ↑
insert condition insert it into condition
Finally, the total preview: