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
RADAgent
Billenium Transitions Xtra v2
Foundation Director 8.5
Mouse click or Key press
NTI CD Maker
Flash Member Controls
Animated Cursor
Windows NT and Audio
Math
Havok Skittles / Bowling Game source code
 

 

 

Behavior Fade bitmap to / from pure colour behaviour

Added on 4/4/2001

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: BarrySwan (website)

Fade bitmap to / from pure colour

---------------------------> Information about this behaviour
-- [S] Fade bitmap to / from pure colour behaviour
-- Behaviour written by Barry Swan
-- E-mail: gerbil@theburrow.co.uk
-- WWW:    http://www.theburrow.co.uk

---------------------------> Property definitions for the behaviour
property pSN, pS
property pOldInk, pOldBGColor, pOldColor

property pFadeImmediately
property pStartState
property pFrames
property pRed, pGreen, pBlue

property pState, pFrame

property pOldBrightness
property pOldContrast

---------------------------> Initialise the sprite and properties
on beginSprite me
  
  -- Set up sprite properties
  pSN = me.spriteNum
  pS = sprite(pSN)
  pOldInk = pS.ink
  pOldBGColor = pS.bgcolor
  pOldColor = pS.color
  
  -- Set to use darken ink
  pS.ink = 41
  
  -- Set up initial sprite state (if not normal)
  if pStartState = #purecolour then me.SetToPureColour()
  
  -- Set properties
  pState = #default
  pFrame = 0
  
  -- Fade if set to immediately
  if pFadeImmediately = TRUE then
    if pStartState = #purecolour then pState = #fadetonormalcolours
    else pState = #fadetopurecolour
  end if
end

---------------------------> Check for values being changed - if so update sprite
on prepareFrame me
  
  -- Anything to report?
  if pState <> #default then
    
    -- Increase frame counter
    pFrame = pFrame + 1
    
    -- React according to fade type
    if pState = #fadetopurecolour then me.SetColours(pFrame)
    else me.SetColours(pFrames - pFrame)
    
    -- Has fade finished?
    if pFrame = pFrames then pState = #default
  end if
  
end

---------------------------> Set the sprite to the pure colour
on SetColours me, tStep
  
  -- Set colours
  tBG = 255 - (255 * tStep / pFrames)
  
  tFGRed = pRed * tStep * 256 / 100 / pFrames
  tFGGreen = pGreen * tStep * 256 / 100 / pFrames
  tFGBlue = pBlue * tStep * 256 / 100 / pFrames
  
  -- Set sprite values
  pS.bgcolor = rgb(tBG, tBG, tBG)
  pS.color = rgb(tFGRed, tFGGreen, tFGBlue)
  
end

---------------------------> Set the sprite to the pure colour
on SetToPureColour me
  
  -- Set sprite state to default
  pState = #default
  
  -- Call SetColours correctly
  me.SetColours(pFrames)
  
end

---------------------------> Set the sprite to it's normal values
on SetToNormalColours me
  
  -- Set sprite state to default
  pState = #default
  
  -- Call SetColours correctly
  me.SetColours(0)
  
end

---------------------------> Start the fade to pure colour
on FadeToPureColour
  
  -- Set sprite state to fade to pure colour
  pState = #fadetopurecolour
  pFrame = 0
  
end

---------------------------> Start the fade from pure colour to normal colours
on FadeToNormalColours
  
  -- Set sprite state to fade to pure colour
  pState = #fadetonormalcolours
  pFrame = 0
  
end

---------------------------> Reset the sprite when finished
on endSprite me
  
  -- Restore the old sprite properties
  pS.ink = pOldInk
  pS.bgcolor = pOldBGColor
  pS.color = pOldColor
  
end

---------------------------> Input the initial property values
on getPropertyDescriptionList me
  
  -- Set up list
  tlData = [:]
  
  -- Options for start state
  tlData[#pStartState] = [¬
      #format: #symbol,¬
      #default: #purecolour,¬
      #range: [#purecolour, #normalcolours],¬
      #comment: "Starting state of bitmap (as pure colour or the normal colours):"¬
  ]
  
  -- Options for fade in / out
  tlData[#pFadeImmediately] = [¬
      #format: #boolean,¬
      #default: TRUE,¬
      #comment: "Fade immediately or not (if not fades when code triggers it):"¬
  ]
  
  -- Options for number of frames to fade over
  tlData[#pFrames] = [¬
      #format: #integer,¬
      #default: 30,¬
      #comment: "Number of frames to fade over:"¬
  ]
  
  -- Options for red
  tlData[#pRed] = [¬
      #format: #integer,¬
      #default: 100,¬
      #range: [#min: 0, #max: 100],¬
      #comment: "Red intensity of fade colour (measured in percentage with 100% being no change):"¬
  ]
  
  -- Options for green
  tlData[#pGreen] = [¬
      #format: #integer,¬
      #default: 100,¬
      #range: [#min: 0, #max: 100],¬
      #comment: "Green intensity of fade colour (measured in percentage with 100% being no change):"¬
  ]
  
  -- Options for blue
  tlData[#pBlue] = [¬
      #format: #integer,¬
      #default: 100,¬
      #range: [#min: 0, #max: 100],¬
      #comment: "Blue intensity of fade colour (measured in percentage with 100% being no change):"¬
  ]
  
  -- Return list
  return tlData
  
end

---------------------------> Description of the behaviour in the behaviour inspector
on getBehaviorDescription me
  
  -- Create description string
  tInfo = "[S] Fade bitmap to / from pure colour behaviour" & RETURN & RETURN
  
  tInfo = tInfo & "Behaviour by Barry Swan" & RETURN
  tInfo = tInfo & "E-mail: gerbil@theburrow.co.uk" & RETURN
  tInfo = tInfo & "www:    www.theburrow.co.uk" & RETURN & RETURN
  
  tInfo = tInfo & "Drop this behaviour onto a bitmap sprite to make it fade to / from a pure colour either automatically or under lingo control." & RETURN
  tInfo = tInfo & "Note that it uses the DARKEN ink. Therefore it will override the ink setting for the sprite in the score." & RETURN
  tInfo = tInfo & "The DARKEN ink has transparency identical to MATTE ink." & RETURN & RETURN
  
  tInfo = tInfo & "Parameters are:" & RETURN & RETURN
  
  tInfo = tInfo & "Start state of image - either it starts as the pure colour or it starts as normal." & RETURN
  tInfo = tInfo & "Fade immediately - if set to true the fade occurs immediately, otherwise it is triggered through behaviour handlers." & RETURN
  tInfo = tInfo & "Number of frames for fade to take." & RETURN
  tInfo = tInfo & "Red intensity of pure colour - measured as a percentage with 100% being maximum intensity." & RETURN
  tInfo = tInfo & "Green intensity of pure colour - measured as a percentage with 100% being maximum intensity." & RETURN
  tInfo = tInfo & "Blue intensity of pure colour - measured as a percentage with 100% being maximum intensity." & RETURN & RETURN
  
  tInfo = tInfo & "Behaviour handlers are:" & RETURN & RETURN
  tInfo = tInfo & "me.SetToPureColour() - sets the sprite to the pure colour." & RETURN
  tInfo = tInfo & "me.SetToNormalColours() - sets the sprite to it's normal colours." & RETURN
  tInfo = tInfo & "me.FadeToPureColour() - Starts the sprite fading from normal colours to the pure colour." & RETURN
  tInfo = tInfo & "me.FadeToNormalColours() - Starts the sprite fading from the pure colour to it's normal colours." & RETURN & RETURN
  
  tInfo = tInfo & "You can change the properties and the behaviour will update the graphic when any of the behaviour handlers are called." & RETURN
  tInfo = tInfo & "To alter the number of frames the fade takes, change the 'pFrames' property of the sprite." & RETURN
  tInfo = tInfo & "To alter the red component of the pure colour, change the 'pRed' property of the sprite." & RETURN
  tInfo = tInfo & "To alter the green component of the pure colour, change the 'pGreen' property of the sprite." & RETURN
  tInfo = tInfo & "To alter the blue component of the pure colour, change the 'pBlue' property of the sprite." & RETURN
  
  -- Return string
  return tInfo
  
end

 


Contact

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

Send e-mail