Search tutorials
Step 2: Re-drawing the user's art
Now go to the sixth frame of the root timeline, insert a keyframe and remove the ok movie clip. Paste the following code into the actions panel.
pen.clear()
pen.lineStyle(1, 000000, 100)
pen.moveTo(lines.line1[0], lines.line1[1])
_root.onEnterFrame = function(){
line += 1
name = "line"+line
if(lines[name][0]=="break"){
pen.moveTo(lines[name][1], lines[name][2])
line += 1
name = "line"+line
}
if(line<=segments){
pen.lineTo(lines[name][0], lines[name][1])
}
}
_root.onMouseDown = null
_root.onMouseMove = null
This code is kind of complicated. First it clears all the drawings in the pen movie clip, and sets up it's line style. Then, it moves to the first position. Then, every frame, the line variable adds one, and we set the name variable to "line"+line(so if line is 3 then name is line3.) Then, if the current thing to do is break, then the pen moves to the new position, adds one to the line variable, and sets name to "line"+line(again) This way, instead of having a pause in the drawing, it moves to the new position and draws a new line at the same time. Finally, if not all the lines have been drawn, we draw a line to the current position. Export the movie and make a drawing. Then click OK. The game will draw your drawing for you! It does it pretty slow, though. Increase the frame rate. This will make the lines draw faster. That's it! You've just made a fun game. You can also make a different impression of the art by adding things like 5 or 10 to the lines variable. This will let the computer make the art more robotic. But don't add more than one if there's a break in the drawing! Then the drawing will start at different points instead of just going to points faster. Export different versions of the swf. Try changing the lineStyle for each frame. Try making the computer make a random version of the art! This will be easy to do. Simply type in the following code instead of lines += 1
lines += random(5)+1
Try lots of variations and even send them to me if you really like them.
| » Level Intermediate |
|
Added: 2004-12-24 Rating: 8 Votes: 7 |
| » Author |
| Just started working with Flash. |
| » Download |
| Download the files used in this tutorial. |
| Download (3 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!