a Tuesday feature

by William Hurley

More Control Over Sprite Positions with Lingo and the Cursor

Last week we discussed controlling sprites on stage using the random command in Lingo. This week I discuss using Lingo to control the movements of sprites on stage with the cursor, which becomes very useful when creating Shockwaves that require the user to move objects.

In the tutorial this week we look at both making sprites movable on the stage, and making sprites track with the movement of the cursor on stage.

Steps for Making the Blue Ball Movable on the Stage.
Step 1: Set the stage size in Director to 250 pixels in Width and 250 pixels in Height. To do this choose "Preferences" from the file menu. This was our first step last week so if you have forgotten how do this refer to last week's tutorial. Set the stage size and make sure that the stage is centered on the screen, then click the button marked OK.

Step 2: Import a graphic into the Cast window. Again we will use the blue ball, but you can use anything that you would like for this step. Position the graphic you have imported in the center of the Stage window.

Step 3: We want the ball to be movable on stage. To allow the ball to be moved when it is clicked on, select the sprite of the ball (Sprite 01) and then click on the checkbox to make it movable on the stage as seen in Figure 1.

Figure 1


Step 4: Double-click the Score Script at Frame 1. Enter the following Lingo script in to the window provided.

on exitFrame
  go to the frame
end

This will cause the playback head to loop at this first frame. Since we have set the Sprite to be movable, users will be able to click on the ball and then drag it around the area of the stage. Try this yourself within the bounds of the first Shockwave movie at the top of this page.

Steps for Making the Blue Ball Follow the Cursor on the Stage.
Step 1: Double-click the Score Script at Frame 1. Replace the current Lingo script with the following Lingo script into the window provided.

on enterFrame
  set the locH of sprite 1 to the mouseH
  set the locV of sprite 1 to the mouseV
end
on exitFrame
  go to the frame
end

With this done, try moving the cursor into the area of the second movie. When you do this the ball will track the cursor everywhere it goes. You will also notice the illusion is given that if you move the cursor faster, the ball will start lagging behind. As the cursor slows, the ball will gradually catch up.

This finishes our first set of experiments that involve controlling objects with Lingo and the cursor. We'll move on to new subjects next week (unless any new questions pop up).

Again if you would like anything explained in more detail, just send me an e-mail.

Past installments of Simply Shocking

http://www.internet.com/