使用加速旋转图像 - LiveCode

Tia*_*nRB 3 image-processing livecode

我一直在使用LiveCode几天,但我发现了一个问题,并且已经被困了一整天.

我的项目是轮盘/财富之轮游戏,其中圆形图像旋转一个随机的度数,中心/北部的静态针标记其下的当前部分.

为了使图像旋转,我在按钮上使用此代码:

on mouseUp
  put random(360) into i
  repeat with x=0 to i
     set the angle of image "ruleta.png" to the angle of image "ruleta.png" + 1
     wait for 10 milliseconds
  end repeat
end mouseUp
Run Code Online (Sandbox Code Playgroud)

问题是,我可以让图像旋转,但只能达到一定的速度,并且看起来并不光滑.有没有办法每秒增加帧数?如果它可以有一个自然的自旋加速/减速,我会很棒.

增加每个框架上旋转的度数使其看起来更快,但非常不连贯.

此外,RunDev论坛在Chrome,Firefox和Safari上为我提供了重定向循环和404,关闭了对google给我的大部分信息的访问权限.这会发生在每个人身上吗?

Ben*_*ont 5

当我在我的Mac上的图像上尝试该代码时,它很好而且流畅.我假设您正在开发移动应用程序.

首先要说的是图像旋转是在运行中计算的.这意味着每次设置图像的能力时,LiveCode都会重新计算图像中所有非常昂贵的像素.在台式机上,你有一个非常强大的CPU,因此旋转图像相当容易处理并且看起来很流畅,但移动设备的CPU功能较弱,并且很难处理这种操作.

可能的解决方案1 ​​ - LiveCode考虑了图像的"resizeQuality"属性.您可以将其设置为"正常","好"和"最佳",最快的是"正常",它会产生块状图像,最慢的是"最佳",它具有更高的质量.如果您正在使用更高质量的设置,则可以通过在旋转发生时暂时降低质量来提高性能.

on mouseUp
   put random(360) into i
   set the resizeQuality of image 1 to "normal"
   repeat with x=0 to i
      set the angle of image 1 to the angle of image 1 + 1
      wait for 10 milliseconds
   end repeat

   lock screen
   set the resizeQuality of image 1 to "best"
   set the angle of image 1 to the angle of image 1 + 1
   set the angle of image 1 to the angle of image 1 - 1
   unlock screen
end mouseUp
Run Code Online (Sandbox Code Playgroud)

请注意,为了使图像以高质量重绘,我再次改变了角度.

可能的解决方案2 - 如果你无法从中获得足够的性能,最好的办法是在所有360个位置为你的车轮生成图像.然后,您可以将图像的文件名正确设置为正确的文件名.

local tImagesPath
set the itemdel to "/"
put item 1 to -2 of the filename of this stack & slash & "wheel_images" & slash into tImagesPath

set the resizeQuality of image 1 to "best"

repeat with x=0 to 359
   set the angle of image 1 to x
   export snapshot from image 1 to file tImagesPath & x & ".png" as png
   wait 1 millisecond with messages
end repeat
Run Code Online (Sandbox Code Playgroud)

该脚本可在359个位置生成高质量的车轮图像.

要在移动设备上获得良好的性能,当您打开应用程序时,请在359个位置重复显示滚轮的所有图像并致电:

prepare image
Run Code Online (Sandbox Code Playgroud)

这将导致LiveCode将图像预加载到内存中,从而可以渲染一些非常流畅的动画.