如何计算幻灯片的速度? - 动态代码

时间:2014-05-17 17:17:59

标签: livecode

我创建了图像幻灯片。通过创建图像组组。就像这个图像一样:

enter image description here

现在我可以使用鼠标进行滑动移动。示例代码如下。

local sScrolling
local sInitialMouseX, sInitialMouseY
local sInitialHScroll, sInitialVScroll

on mouseDown
   ## Allow the group to scroll
   put true into sScrolling

   ## Record the initial touch position
   put item 1 of the mouseLoc into sInitialMouseX
   put item 2 of the mouseLoc into sInitialMouseY

   ## Record the initial hScroll and vScroll
   put the vScroll of me into sInitialVScroll
   put the hScroll of me into sInitialHScroll
end mouseDown

on mouseMove mouseX, mouseY
   ## If the screen is being touched then
   if sScrolling then      
      ## Calculate how far the touch has moved since it started
      put mouseY - sInitialMouseY into tVChange
      put mouseX- sInitialMouseX into tHChange

      ## Reset the hScroll and vScroll to follow the touch
      lock screen
      --      set the vScroll of me to sInitialVScroll - tVChange
      set the hScroll of me to sInitialHScroll - tHChange
      unlock screen
      put the hScroll of me && tHChange into fld "labS"
   end if
end mouseMove

on mouseRelease
   mouseUp
end mouseRelease

on mouseUp
   put false into sScrolling
end mouseUp

我想要一个阻尼,并在IOS的各种应用程序上播放像幻灯片一样的Snap图片。

请指导我或预览代码。

2 个答案:

答案 0 :(得分:1)

我希望这个例子能给你一些关于阻尼的想法(我假设你的意思是加速/减速)。我在游戏和应用程序中使用了这些简单的easeIn / easeOut公式,其中我使用了自己的滚动条而不是本机滚动条。

(可以在'Dog Tales'应用程序的动画中看到一个例子...... http://dogtales.splash21.com/chapter1-2.php

创建一个新堆栈并添加一个名为“Ball”的图形。将以下代码放入卡片中......

command moveBall
   local tSpeed
   set the left of graphic "Ball" to 0
   repeat with tIndex = 1 to 100
      put 10 * easeOut(100, tIndex) into tSpeed
      set the left of graphic "Ball" to the left of graphic "Ball" + tSpeed
      wait for 2 millisecs
   end repeat
end moveBall


function easeIn pMax, pVal, pPow
   local tResult
   if pPow is not a number then put 1.25 into pPow
   put (pVal / pMax) ^ pPow into tResult
   if tResult > 1 then
      return 1
   else if tResult < 0 then
      return 0
   else
      return tResult
   end if
end easeIn


function easeOut pMax, pVal, pPow
   local tResult
   if pPow is not a number then put 1.25 into pPow
   put 1 - (pVal / pMax) ^ pPow into tResult
   if tResult > 1 then
      return 1
   else if tResult < 0 then
      return 0
   else
      return tResult
   end if
end easeOut

答案 1 :(得分:0)

您的代码提出了一些问题。例如。究竟是什么滚动。你的照片也不太具启发性。我的猜测是你要决定是否在mouseUp之后继续滚动或者将hscroll设置回其原始值。显然,你需要一些阈值,我不知道阈值的值,所以你现在必须自己解决这个问题。

on mouseUp
   put false into sScrolling
   if (sInitialMouseX - sInitialHScroll) > myThreshold then
     set the hScroll of me to myScrollTillTheEnd
   else
      set the hScroll of me to sInitialHScroll 
   end if
end mouseUp

如果您决定该组应该翻转到另一侧,并且仅当用户将手指移动超过50个像素时,则50是阈值,您可以将myThreshold替换为50。