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
fluidXtra
NTI CD Maker
Clear Embedded Font
Impactica
Billenium Transitions Xtra v1.1
Gravis MouseStick
QuickDraw 3D
SplashScreenX Pro
Multi Cropper
encrypt/decrypt Image
 

 

 

Behavior DeadC Scroll

Added on 6/30/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: WarrenOckrassa

A scroll barless scroller. Works horizontally or vertically with pretty much any sprite. Can scroll "lock" sprites along with the main one for layered effects (embedded images, etc).

-- DeadC, a scroller
-- By Warren "The Howdy Man" Ockrassa, warren@nightwares.com
-- This scrolls text onscreen without scrollbars
-- Drag and drop to invoke the GPDL
-- Parameters:
--  Sprite to Scroll -- self-explanatory; automatically selected when behavior is invoked
--  Accelerated Scroll -- the scroll will move faster the farther the cursor is dragged off initial mousedown locV
--  Acceleration Modifier -- the lower the number, the faster the acceleration for the scroll
--  Scrolling background/frame -- used to determine when the sprite's gone out of frame
--  Decelerate on mouseUp -- gradually decelerates the scroll when the user lets the mouse up
--  Bounce deceleration -- How rapidly the sprite bounces back when it hits the frame border
--  Vertical Scroll -- true by default; can be unchecked for horizontal scroll instead
--  Scroll other sprites -- "lock" other sprites so they scroll at the same time as the current one
--  Other sprites to scroll -- a list of the other sprites to be locked into this one's scroll

on GetBehaviorDescription  
  sContent = "This scrolls text onscreen without scrollbars." & RETURN & RETURN & "Parameters include scroll acceleration and the ability to scroll horizontally or vertically."
  return sContent  
END GetBehaviorDescription

on GetBehaviorTooltip  
  sContent = "This scrolls text onscreen without scrollbars." & RETURN & RETURN & "Parameters include scroll acceleration and the ability to scroll horizontally or vertically."
  return sContent  
END GetBehaviorTooltip

PROPERTY pnSpriteToScroll, pbAcceleratedScrollEnable, pnAccelerationModifier, pbVerticalScroll, pnStartForSlowDown, pbDecelerate, pnFrameSprite, pnBounceDeceleration, pbEmbeddedSprites, plEmbedSprites, plEmbeddedLocList

on beginSprite me  
  pnSpriteToScroll = the currentSpriteNum
  plEmbedSprites = value ( plEmbedSprites )  
  if pbEmbeddedSprites then    
    plEmbeddedLocList = []    
    repeat with nEmbed = 1 to count ( plEmbedSprites )
      nSprite = getAt ( plEmbedSprites, nEmbed )      
      -- calculate the starting positions of the "embedded" sprites relative to the starting position of the "main" one
      if pbVerticalScroll then        
        add ( plEmbeddedLocList, sprite(nSprite).locV - sprite(pnSpriteToScroll).locV )
      else add ( plEmbeddedLocList, sprite(nSprite).locH - sprite(pnSpriteToScroll).locH )      
    end repeat    
  end if  
end

on mouseEnter me
  cursor 260  
end

on mouseDown me  
  cursor 290
  pnStartForSlowDown = the mouseV
  startTimer  
  if pbAcceleratedScrollEnable and the controlDown then    
    -- ==================================================================== accelerated vertical scroll section    
    if pbVerticalScroll then      
      nStartMouseV = the mouseV      
      repeat while the stillDown        
        nDeltaV = the mouseV - nStartMouseV
        sprite(pnSpriteToScroll).locV = sprite(pnSpriteToScroll).locV + ( nDeltaV / pnAccelerationModifier )        
        if pbEmbeddedSprites then MoveEmbeds( 1 )        
        updateStage        
        if sprite(pnSpriteToScroll).top > sprite(pnFrameSprite).bottom then          
          sprite(pnSpriteToScroll).top = sprite(pnFrameSprite).bottom - 3          
          if pbEmbeddedSprites then MoveEmbeds( 1 )        
          BounceIt( -1 )          
          exit repeat          
        else if sprite(pnSpriteToScroll).bottom < sprite(pnFrameSprite).top then          
          sprite(pnSpriteToScroll).bottom = sprite(pnFrameSprite).top + 3          
          if pbEmbeddedSprites then MoveEmbeds( 1 )        
          BounceIt( 1 )          
          exit repeat          
        end if        
      end repeat      
    else      
      -- ==================================================================== accelerated horizontal scroll section      
      nStartMouseH = the mouseH      
      repeat while the stillDown        
        nDeltaH = the mouseH - nStartMouseH
        sprite(pnSpriteToScroll).locH = sprite(pnSpriteToScroll).locH + ( nDeltaH / pnAccelerationModifier )        
        if pbEmbeddedSprites then MoveEmbeds( 0 )        
        updateStage        
        if sprite(pnSpriteToScroll).right < sprite(pnFrameSprite).left then          
          sprite(pnSpriteToScroll).right = sprite(pnFrameSprite).left + 3        
          if pbEmbeddedSprites then MoveEmbeds( 0 )        
          BounceIt( 1 )          
          exit repeat          
        else if sprite(pnSpriteToScroll).left > sprite(pnFrameSprite).right then          
          sprite(pnSpriteToScroll).left = sprite(pnFrameSprite).right - 3          
          if pbEmbeddedSprites then MoveEmbeds( 0 )        
          BounceIt( -1 )          
          exit repeat        
        end if        
      end repeat      
    end if    
  else    
    if pbVerticalScroll then      
      -- ==================================================================== vertical scroll section      
      nDeltaV = sprite(pnSpriteToScroll).locV - the mouseV  
      repeat while the stillDown      
        sprite(pnSpriteToScroll).locV = the mouseV + nDeltaV
        if pbEmbeddedSprites then MoveEmbeds( 1 )        
        updateStage        
        if sprite(pnSpriteToScroll).top > sprite(pnFrameSprite).bottom then          
          sprite(pnSpriteToScroll).top = sprite(pnFrameSprite).bottom - 3          
          if pbEmbeddedSprites then MoveEmbeds( 1 )        
          BounceIt( -1 )          
          exit repeat          
        else if sprite(pnSpriteToScroll).bottom < sprite(pnFrameSprite).top then          
          sprite(pnSpriteToScroll).bottom = sprite(pnFrameSprite).top + 3          
          if pbEmbeddedSprites then MoveEmbeds( 1 )        
          BounceIt( 1 )          
          exit repeat          
        end if        
      end repeat      
    else      
      -- ==================================================================== horizontal scroll section      
      nDeltaH = sprite(pnSpriteToScroll).locH - the mouseH  
      repeat while the stillDown        
        sprite(pnSpriteToScroll).locH = the mouseH + nDeltaH
        if pbEmbeddedSprites then MoveEmbeds( 0 )        
        updateStage        
        if sprite(pnSpriteToScroll).right < sprite(pnFrameSprite).left then          
          sprite(pnSpriteToScroll).right = sprite(pnFrameSprite).left + 3        
          if pbEmbeddedSprites then MoveEmbeds( 0 )        
          BounceIt( 1 )          
          exit repeat
          else if sprite(pnSpriteToScroll).left > sprite(pnFrameSprite).right then        
          sprite(pnSpriteToScroll).left = sprite(pnFrameSprite).right - 3          
          if pbEmbeddedSprites then MoveEmbeds( 0 )        
          BounceIt( -1 )          
          exit repeat          
        end if      
      end repeat      
    end if    
  end if  
end

on BounceIt nMultiplier  
  cursor -1  
  if pbVerticalScroll then  
    repeat with nDistance = pnBounceDeceleration down to 0  
      sprite(pnSpriteToScroll).locV = sprite(pnSpriteToScroll).locV + ( nDistance * nMultiplier )      
      if pbEmbeddedSprites then MoveEmbeds( 1 )      
      updateStage      
    end repeat    
  else    
    repeat with nDistance = pnBounceDeceleration down to 0  
      sprite(pnSpriteToScroll).locH = sprite(pnSpriteToScroll).locH + ( nDistance * nMultiplier )      
      if pbEmbeddedSprites then MoveEmbeds( 0 )      
      updateStage    
    end repeat    
  end if  
END BounceIt

on mouseUp me
  cursor 260  
  if pbDecelerate then    
    nTimeSpent = the timer
    if voidP ( nTimeSpent ) or nTimeSpent < 1 then nTimeSpent = 1
    nPixelsPerTick = pnStartForSlowDown / nTimeSpent    
    if pbVerticalScroll then      
      -- ================================================================================ vertical momentum to stop section    
      if the mouseV < pnStartForSlowDown then        
        nMultiplier = -1        
      else nMultiplier = 1      
      repeat with nAmount = nPixelsPerTick down to 0        
        sprite(pnSpriteToScroll).locV = sprite(pnSpriteToScroll).locV + nAmount * nMultiplier        
        if pbEmbeddedSprites then MoveEmbeds( 1 )        
        updateStage        
        if sprite(pnSpriteToScroll).top > sprite(pnFrameSprite).bottom then          
          sprite(pnSpriteToScroll).top = sprite(pnFrameSprite).bottom - 3          
          if pbEmbeddedSprites then MoveEmbeds( 1 )        
          BounceIt( -1 )          
          exit repeat          
        else if sprite(pnSpriteToScroll).bottom < sprite(pnFrameSprite).top then          
          sprite(pnSpriteToScroll).bottom = sprite(pnFrameSprite).top + 3          
          if pbEmbeddedSprites then MoveEmbeds( 1 )        
          BounceIt( 1 )        
          exit repeat          
        end if        
      end repeat    
    else    
      -- ================================================================================ horizontal momentum to stop section    
      if the mouseH > pnStartForSlowDown then        
        nMultiplier = -1        
      else nMultiplier = 1      
      repeat with nAmount = nPixelsPerTick down to 0        
        sprite(pnSpriteToScroll).locH = sprite(pnSpriteToScroll).locH + nAmount * nMultiplier        
        if pbEmbeddedSprites then MoveEmbeds( 0 )        
        updateStage        
        if sprite(pnSpriteToScroll).right < sprite(pnFrameSprite).left then          
          sprite(pnSpriteToScroll).right = sprite(pnFrameSprite).left + 3        
          if pbEmbeddedSprites then MoveEmbeds( 0 )        
          BounceIt( 1 )          
          exit repeat          
        else if sprite(pnSpriteToScroll).left > sprite(pnFrameSprite).right then          
          sprite(pnSpriteToScroll).left = sprite(pnFrameSprite).right - 3          
          if pbEmbeddedSprites then MoveEmbeds( 0 )        
          BounceIt( -1 )          
          exit repeat          
        end if        
      end repeat      
    end if    
  end if  
end

on MoveEmbeds bVert  
  if bVert then    
    repeat with nEmbed = 1 to count ( plEmbedSprites )      
      nSprite = getAt ( plEmbedSprites, nEmbed )
      nLoc = getAt ( plEmbeddedLocList, nEmbed )
      sprite(nSprite).top = sprite(pnSpriteToScroll).top + nLoc      
    end repeat    
  else    
    repeat with nEmbed = 1 to count ( plEmbedSprites )    
      nSprite = getAt ( plEmbedSprites, nEmbed )
      nLoc = getAt ( plEmbeddedLocList, nEmbed )
      sprite(nSprite).left = sprite(pnSpriteToScroll).left + nLoc      
    end repeat    
  end if  
END MoveEmbeds

on mouseLeave me  
  cursor -1  
end

on GetPropertyDescriptionList me  
  if not ( the currentSpriteNum ) then    
    -- behavior has been dropped on the script channel; kickout
    exit    
  end if
  return [ #pbAcceleratedScrollEnable: [ #comment: "Accelerated Scroll (CTRL-drag to accelerate)", #format:  #boolean, #default: TRUE ], #pnAccelerationModifier: [ #comment: "Acceleleraton Modifier (higher = less acceleration):", #format:  #integer, #default: 8, #range: [#min: 1, #max: 20] ], #pnFrameSprite: [ #comment: "Scrolling background/frame sprite:", #format:  #integer, #default: the lastChannel, #range: [#min: 1, #max: the lastChannel] ], #pnBounceDeceleration: [ #comment: "Deceleration factor on bounce back from edge of frame:", #format:  #integer, #default: 10, #range: [#min: 1, #max: 20] ], #pbDecelerate: [ #comment: "Decelerate scroll on mouseUp?", #format:  #boolean, #default: TRUE ], #pbVerticalScroll: [ #comment: "Vertical Scroll (uncheck for horizontal scroll instead)", #format:  #boolean, #default: TRUE ], #pbEmbeddedSprites: [ #comment: "Scroll other sprites with this one?", #format:  #boolean, #default: FALSE ], #plEmbedSprites: [ #comment: "Sprites to scroll with this one (plain linear list format)", #format: #list, #default: "[]" ] ]  
end GetPropertyDescriptionList

 


Contact

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

Send e-mail