Livecode 如何计算滑动屏幕的速度?-活码
我已经创建了图像幻灯片。通过创建图像组的组。如下图所示: 现在我可以用鼠标移动幻灯片了。示例代码如下Livecode 如何计算滑动屏幕的速度?-活码,livecode,Livecode,我已经创建了图像幻灯片。通过创建图像组的组。如下图所示: 现在我可以用鼠标移动幻灯片了。示例代码如下 local sScrolling local sInitialMouseX, sInitialMouseY local sInitialHScroll, sInitialVScroll on mouseDown ## Allow the group to scroll put true into sScrolling ## Record the initial touch
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的各种应用程序上有像幻灯片这样的快照图片
请为我提供指南或预览代码。您的代码提出了一些问题。你到底在滚动什么。你的照片也不太有启发性。我的猜测是,您想要决定是在鼠标点击后继续滚动,还是将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。我希望此示例将为您提供一些关于阻尼的想法(我假设您指的是加速/减速)。我在游戏和应用程序中使用了这些简单的easeIn/easeOut公式,在这些游戏和应用程序中,我使用了自己的滚动条而不是本地滚动条 (一个例子可以在“狗狗故事”应用程序中的动画中看到。。。 ) 创建一个新堆栈并添加一个名为“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
命令移动球
本地速度
将图形“Ball”的左侧设置为0
使用tIndex=1到100重复此操作
将10*easeOut(100,tIndex)放入t速度
将图形“Ball”的左侧设置为图形“Ball”+t速度的左侧
等待2毫秒
结束重复
端部移动球
pMax、pVal、pPow中的功能
局部结果
如果pPow不是数字,则在pPow中输入1.25
将(pVal/pMax)^pPow放入树结果
如果tResult>1,则
返回1
否则,如果tResult<0,则
返回0
其他的
返回结果
如果结束
伊辛结束
功能输出pMax、pVal、pPow
局部结果
如果pPow不是数字,则在pPow中输入1.25
将1-(pVal/pMax)^pPow放入树结果
如果tResult>1,则
返回1
否则,如果tResult<0,则
返回0
其他的
返回结果
如果结束
结束
什么是“想要减震并有快照图片”的确切含义?我想你需要某种视觉效果。你是在为iOS还是Android制作应用程序?然后您可以查看scrollerDidScroll、scrollerBeginDrag和scrollerEndDrag消息。scrollerDidScroll消息将允许您滚动,而ScrollerAddRag消息将告诉您是时候决定是否滑动到最后以及应用哪种效果了。我知道您告诉过我,但我不明白我应该如何评估速度值?否则,你能为我做这个过程的例子吗?感谢您的建议。阈值=ธรณีประตู. (可能不是完全正确的翻译。我的意思是一个限制,一个边界值。例如,如果您决定组应翻转到的另一侧,并且仅当用户移动手指超过50像素时,那么50是一个阈值,您可以将myThreshold替换为50。