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
Change the LineSize of a Shape Cast Member
UpDown Timer
Toggle ImageEnabled Property of a Flash Sprite
Movable Hole with Mask Ink
alt.multimedia.director
Rotate a Flash Sprite
MostFramesScript
Tree View
Animate Text Shadow
The Director Podcast
 

 

 

Behavior Composite Images with Alpha

Added on 11/29/2004

 

Compatibilities:
D8 D8_5 D9 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

This behavior composites multiple image objects with alpha but does not suffer from the common problem of the images getting ragged or muddled alphas in the process.

--Copyright 2004-2005
--Chuck Neal
--MediaMacros, Inc.
--Enjoy ;)
on compositeImage vImage, vDestImage, vDestRect, vSourceRect, vBackColor
  if vBackCOlor = void then vBackColor = rgb(0,0,0)
  iDestImage = vDestImage.duplicate()
  
  --Fill with a solid back color
  iDestImage.fill(iDestImage.rect, vBackCOlor)
  
  iSourceImage = vImage.duplicate()
  
  -- get the original alpha channel
  iAlphaBuffer = vDestImage.extractAlpha()
  
  --get the composite alpha
  if iSourceImage.depth = 32 then
    iSourceAlphaBuffer = iSourceImage.extractALpha()
  else
    --create a new super image alpha
    iSourceAlphaBuffer = image(iSourceImage.width, iSourceImage.height, 8, #grayscale)
    iSourceAlphaBuffer.fill(iSourceAlphaBuffer.rect, rgb(0,0,0))    
  end if
  
  --Disable both alphas for the copy pricess
  vDestImage.useAlpha = FALSE
  iSourceImage.useAlpha = FALSE
  
  
  
  iDestMask = iAlphaBuffer.createMask()
  iDestImage.copyPixels(vDestImage, vDestImage.rect, vDestImage.rect, [#maskimage : iDestMask, #ink : #add, #dither : 1969])
  
  iSourceMask = iSourceImage.extractalpha().createMask()
  iDestImage.copyPixels(iSourceImage, vDestRect, vSourceRect, [#maskimage : iSourceMask, #dither : 1969])
  
  --reverse dark to light
  iAlphaReverse = image(iSourceImage.width, iSourceImage.height, 8, #grayscale)
  --alphatoAdd.duplicate()
  iAlphaReverse.fill(iAlphaReverse.rect, rgb(0,0,0))
  iAlphaReverse.copyPixels(iSourceAlphaBuffer, iAlphaReverse.rect, iSourceAlphaBuffer.rect, [#ink : #reverse])
  
  iALphaBuffer.copyPixels(iAlphaReverse, vDestRect, vSourceRect, [#ink:#subtractpin])
  
  -- apply the alpha changes
  iDestImage.setAlpha(iALphaBuffer)  
  iDestImage.useAlpha = TRUE    
  return iDestImage
end  

 


Contact

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

Send e-mail