Articles Archive
Articles Search
Director Wiki
 

Customizing a sprite's cursor

March 27, 2001
by Will Turnage

Dear Multimedia Handyman,

Is there a list anywhere of what the values are for cursors?

Sam Birch

Dear Sam,

If you want to change the cursor in your project, there are two ways that Lingo lets you do this. The first way uses the Lingo command cursor followed by an integer representing the number for the cursor, such as:

cursor 2

When you call the cursor command directly, it changes the cursor's appearance throughout your movie. While this makes sense in certain situations, such as displaying the watch/hourglass when loading a movie or just hiding the cursor altogether, in most cases you'll just want the cursor to change when you roll over a specific sprite in your movie. In this situation, instead of just calling the cursor command, you set the cursor of a specific sprite like this:

sprite(3).cursor = 2

This code will change the cursor of sprite 3 to the crosshair cursor. Once you've called this command, Director will always display the crosshair cursor when it's over sprite 3 no matter where you are in the Score, or which cast member is currently displayed in sprite 3. If you want to turn off the custom cursor for any sprite, then just set the sprite's cursor equal to zero, or

sprite(3).cursor = 0

If you've read Director's help regarding cursors, you'll see that it only lists 5 or 6 different cursor options. This is a bit misleading because, in fact there are 25 different options for cursors that are built in to Director. You can use anyone of these 25 cursors in your movie without needing extra artwork or Xtras. The 25 cursors and their corresponding integers are:

0
-1
1
2
3
4
200
254
256
257
258
259
260
272
280
281
284
285
286
290
291
292
301
302
303
No cursor set (Arrow)
Arrow
I-Beam
Crosshair
Crossbar
Watch (or hourglass on Windows)
Blank
Help
Pencil
Eraser
Select
Bucket
Hand
Lasso
Finger
Dropper
Vertical Size
Horizontal Size
Diagonal Size
Closed Hand
No Drop Hand
Copy Closed Hand
Airbrush
Zoom In
Zoom Out

Luckily, you don't need to learn all 25 of these numbers if you want to assign custom cursors in your project. Below is the code for a simple behavior you can use that will assign a custom cursor to your sprite. Best of all, it displays a popup menu of the cursors' names instead of their numbers, making it very easy to use.

property pCursor
property pSavedCursor

on beginSprite me

  pSavedCursor = sprite(me.spriteNum).cursor
  sprite(me.spriteNum).cursor = pCursor

end

on endSprite me

  sprite(me.spriteNum).cursor = pSavedCursor

end

on getPropertyDescriptionList

  return [#pCursor: [#format: #cursor, #default: 0, #comment: "Select cursor:"]]

end

The key to this behavior is in the getPropertyDescriptionList handler. By setting the format of your pCursor property equal to #cursor, you tell Director to display a popup menu of all the different cursor types.

The rest of the behavior's code is pretty simple. When the behavior begins, it saves the cursor value currently assigned to the sprite into a variable. Then it changes the cursor of the sprite to the cursor you want. Finally, when the sprite ends, it sets the cursor of the sprite equal to its original value.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.