Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
New bitmap from existing member
Tony's Quick Script Maker
Clear Embedded Font
MPEG Video
Generic behavior to copy a file
Change FillCycles Continuously
80's Arcade High Score Name Entry Behavior
MP3 Player
Prevent Hour Glass Cursor after AVI Ends
All purpose status bar
 

 

 

Article Text Drop Shadows (and a moving light)

Added on 8/23/1999

 

Compatibilities:
D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

How can I give text a drop shadow and have it change based on a virtual "light"?

Get the source
Unlike field members, text members don't default to all the "nice" drop shadow effects.  If you want them you have to make them, but lingo can help you out.  Since text members can change properties such as forecolor independent of their parent cast members, this isn't too difficult to do.  You can either put a second version of the same sprite on the stage, or we can let lingo handle this task.  We will need to know what the text will use as reference (a light), what it will follow (mouse or sprite), and a general offset of how far the shadow stretches from the light.

We set up a basic getPropertyDescriptionList handler to choose these parameters, then use the beginSprite handler to start or create the shadow sprite.   The exitFrame handler takes care of the rest.  It double checks for a text member, then gets the relative distance from the "light" and sends the shadow the other direction.  Below is the code...  

property spriteNum, shadowSprite, follow, followSPrite, rangeOffset

on getPropertyDescriptionList me
  p_list = [:]
  if the currentSpriteNum > 0 and sprite(the currentSpriteNum).member.type = #text then
    p_list.addProp(#shadowSprite, [#format : #integer, #comment : "Which sprite to use as the shadow?", #default : (the currentSpriteNum + 1)])
    p_list.addProp(#follow, [#format : #symbol, #comment : "What should the shadow follor?", #default : #mouse, #range : [#mouse, #sprite, #nothing]])
    p_list.addProp(#rangeOffset, [#format : #float, #comment : "Offset value for the shadow:", #default : 100.0])
    p_list.addProp(#followSprite, [#format : #integer, #comment : "If following a sprite, which sprite?", #default : the currentSpriteNum + 2])
  end if
  return p_list
end

on beginSprite me
  if sprite(spriteNum).member.type = #text then
    if sprite(shadowSprite).member.type = #empty then
      puppetSprite shadowSprite true
    end if
    sprite(spriteNum).ink = 36
    sprite(shadowSprite).ink = 36
    sprite(shadowSprite).member = sprite(spriteNum).member
    sprite(shadowSprite).forecolor = 255
    sprite(shadowSprite).locz = sprite(spriteNum).locZ - 1
  end if
end

on endSprite me
  puppetSprite shadowSprite false
end

on enterFrame me
  if sprite(spriteNum).member.type = #text then
    if follow = #mouse then
      distance = sprite(spriteNum).loc - point(the mouseH, the mouseV)
      sprite(shadowSprite).loc = sprite(spriteNum).loc + (distance / point(rangeOffset, rangeOffset))
    else if follow = #sprite then
      distance = sprite(spriteNum).loc - sprite(followSprite).loc
      sprite(shadowSprite).loc = sprite(spriteNum).loc + (distance / point(rangeOffset, rangeOffset))
    end if
  end if
end

on getBehaviorDescription me
  return "Drop this behavior on a text member and assign an empty sprite or a sprite with a second instance of the same cast member. Choose the " & quote & "light" & quote & " and you are ready to go."
end

Notice that it is important to put an endSprite handler to turn puppeting off on the sprite, otherwise the "shadow" will linger after the text is gone.   That's it.  (Ehhibit 1)

How can you take this to the next step?  How about adding other types of cast members, multiple lights with blends and multiple shadows.  Experiment with it and have fun.  Happy coding.

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail