在我的堆栈上工作时,在编辑模式下,我可以通过箭头键轻推任何控件。
当我的堆栈运行时,我已经取得了一些成功的移动控制"移动"命令例如
move button 1 to 100,100
在运行期间是否有更有效的方法来移动控件?
答案 0 :(得分:2)
您可以使用多种方法,具体取决于您希望动画的平滑程度。在最简单的级别,您需要通过设置与位置相关的属性来移动脚本中的对象:top,left,right,bottom,loc和rect。
set the top of button 1 to 10
如果你在一个方向上移动一个物体,你会想做这样的事情:
on moveObject
lock screen
lock messages
set the top of button 1 to 10
set the left of button 1 to 20
unlock messages
unlock screen
end moveObject
如果你想要连续动画,你会想要使用这样的东西进行循环:
on moveObject
lock screen
lock messages
local tX, tY
# Calculate new position (tX and tY)
# Move objects
set the loc of button 1 to tX, tY
unlock messages
unlock screen
# If animation is not finished, loop
if tEndCondition not true then
send "moveObject" to me in 5 milliseconds
end if
end moveObject
最后,如果你想要一个非常流畅的动画,你会想要扩展这个循环来根据时间计算对象的位置:
on animationLoop pTime
lock screen
lock messages
local tX, tY
# Calculate new position (tX and tY) based on time
# Move objects
set the loc of button 1 to tX, tY
unlock messages
unlock screen
if tEndCondition not true then
# Calculate when the next frame should be based on your target frame rate
send "moveObject" && tTime to me in tNextFrameTime
end if
end animationLoop
如果特定帧花费太长时间来计算和渲染,则最终方法提供了跳过帧的方法。最终结果是一个平滑的动画,反映了用户的期望。
答案 1 :(得分:1)
如果您在运行(浏览)模式下询问如何使用箭头键轻推对象,这里有一种方法(处理程序会进入卡片脚本):
on arrowKey pWhich
# determine some way to designate which object is to be nudged
put the long id of btn "test" into tSelObj # for example
switch pWhich
case "left"
put -1 into tXamount
put 0 into tYamount
break
case "up"
put 0 into tXamount
put -1 into tYamount
break
case "right"
put 1 into tXamount
put 0 into tYamount
break
case "down"
put 0 into tXamount
put 1 into tYamount
break
end switch
move tSelObj relative tXamount,tYamount
end arrowKey