Tom's Lingo Behaviors
縦のスクロール


--Behaviors 1--

property SpriteNum,pInitLocV,pLimitBottom,pUpBtnSpriteNum,pDownBtnSpriteNum
on beginSprite me
  --スクロールするスプライトのthe locV の初期値
  set pInitLocV to the locV of sprite SpriteNum
  --スクロールするスプライトの最後までスクロールしたthe locV の値
  set pLimitBottom to pInitLocV - (the bottom of sprite SpriteNum - the bottom of sprite pDownBtnSpriteNum)
end

on exitFrame me
  if the locV of sprite SpriteNum >= pInitLocV then
    set the locV of sprite SpriteNum to pInitLocV
  else if the bottom of sprite SpriteNum <= pLimitBottom then
    set the locV of sprite SpriteNum to pLimitBottom
  end if
end

on MoveDown me,moveValue
  --下へスクロールする
  set the locV of sprite SpriteNum to (the locV of sprite SpriteNum) - moveValue
  if the locV of sprite SpriteNum <= pLimitBottom then
    set the locV of sprite SpriteNum to pLimitBottom
  end if
end

on MoveUp me,moveValue
  --上へスクロールする
  set the locV of sprite SpriteNum to (the locV of sprite SpriteNum) + moveValue
  if the locV of sprite SpriteNum >= pInitLocV then
    set the locV of sprite SpriteNum to pInitLocV
  end if
end

on CulcNowPercentage me
  return float(pInitLocV - (the locV of sprite SpriteNum)) / (pInitLocV - pLimitBottom)
end

on Move me,moveValue
  --スクロールボックスと連動して動く
  set the locV of sprite SpriteNum to  (pLimitBottom - pInitLocV) * moveValue + pInitLocV
end

on getPropertyDescriptionList
  set propList to [:]
  addProp propList,#pUpBtnSpriteNum,[#comment:"上ボタンのスプライト番号は?",#format:#integer,#default:3]
  addProp propList,#pDownBtnSpriteNum,[#comment:"下ボタンのスプライト番号は?",#format:#integer,#default:4]
  return propList
end

--Behaviors 2--

property SpriteNum,pTargetSpriteNum,pScrollBoxSpriteNum,pMode,pSpeed

on mouseDown me
  repeat while the stillDown
    case pMode of
      #up: 
        sendSprite(pTargetSpriteNum, #MoveUp,pSpeed)
        sendSprite(pTargetSpriteNum, #CulcNowPercentage)
        set myvalue to the result
        sendSprite(pScrollBoxSpriteNum, #move,myvalue)
      #down:
        sendSprite(pTargetSpriteNum, #MoveDown,pSpeed)
        sendSprite(pTargetSpriteNum, #CulcNowPercentage)
        set myvalue to the result
        sendSprite(pScrollBoxSpriteNum, #move,myvalue)
    end case
    updateStage
  end repeat
end

on getPropertyDescriptionList
  set propList to [:]
  addProp propList,#pMode,[#comment:"上下ボタンのどっち?",#format:#symbol,#range:[#up,#Down]#default:#up]
  addProp propList,#pTargetSpriteNum,[#comment:"スクロールするスプライト番号?",#format:#integer,#default:1]
  addProp propList,#pScrollBoxSpriteNum,[#comment:"スクロールボックスのスプライト番号?",#format:#integer,#default:1]
  addProp propList,#pSpeed,[#comment:"スクロールの速さ?",#format:#integer,#default:12]
  
  return propList
end

--Behaviors 3--

property SpriteNum,pInitLocV,pLimitBottom,pTargetSpriteNum,pScrollBarSpriteNum

on beginSprite me
  --スクロールボックスのスプライトのthe locV の初期値
  set pInitLocV to the locV of sprite SpriteNum
  --スクロールボックスのスプライトの最後までスクロールしたthe locV の値
  set pLimitBottom to pInitLocV + (the height of sprite pScrollBarSpriteNum) - (the height of sprite SpriteNum)
end

on mouseDown me
  repeat while the stillDown
    set the locV of sprite SpriteNum to the mouseV
    if the locV of sprite SpriteNum <= pInitLocV then
      set the locV of sprite SpriteNum to pInitLocV
    end if
    if the locV of sprite SpriteNum >= pLimitBottom then
      set the locV of sprite SpriteNum to pLimitBottom
    end if
    CulcNowPercentage me
    set myValue to the result
    sendSprite(pTargetSpriteNum,#Move,myValue)
    updateStage
  end repeat
end

on Move me,moveValue
  --スクロールボタンと連動して動く
  set the locV of sprite SpriteNum to (pLimitBottom - pInitLocV) * moveValue + pInitLocV
end

on CulcNowPercentage me
  return float(pInitLocV - (the locV of sprite SpriteNum)) / (pInitLocV - pLimitBottom)
end

on getPropertyDescriptionList
  set propList to [:]
  addProp propList,#pTargetSpriteNum,[#comment:"スクロールするスプライト番号?",#format:#integer,#default:1]
  addProp propList,#pScrollBarSpriteNum,[#comment:"スクロールバーのスプライト番号?",#format:#integer,#default:1]
  
  return propList
end
上記のビヘイビアは、以下のように使用します。
Behaviors 1は、スクロールするスプライトに張り付けてください。
Behaviors 2は、上下のボタンに張り付けてください。
Behaviors 3は、スクロールボックスtに張り付けてください。


E-mail to tomsaito@most-web.com
[ To Director Top Page ]
[ To Tom's Home Page ]