This script makes your average drawing type thing, where dragging on the screen draws, and releasing the mouse stops the drawing.
1) I think this is needed to make the stage mouse events work.
2) This shape will contain the drawing.
3) Make sure you add it to the stage!
4) This will be the colour of the pen.
5) This will be the thickness of the line.
6) Ensures that the drawing only starts when the person presses down on the stage.
7) Gives a starting point for the drawing, so it doesn't pick up from where the last one finished.
8) See 6.
9 and 10) Makes sure the drawing stops when the mouse is released.
11) I gave the function a proper name so it would be easy to remove. Technically, this function could have been declared outside the init function, but it still works.
12) I guess the if statement isn't really necessary with this version because oldX should always exist... sorry.
13) Draws a line from 'moveTo' to 'lineTo'.
14) Make sure to update the stage after each line.
15) Gives a new starting point for the next line.
(That last stage.update() isn't needed either, sorry.)
No comments:
Post a Comment
Please enter your message here...