image-processing - 加速旋转图像 - LiveCode

标签 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

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

增加它在每一帧上旋转的度数会使它看起来更快,但非常不稳定。

此外,RunDev 论坛在 Chrome、Firefox 和 Safari 上给我重定向循环和 404,关闭了对谷歌给我的大部分信息的访问。每个人都会这样吗?

最佳答案

当我在我的 mac 上的图像上尝试该代码时,它非常流畅。我假设您正在开发移动应用程序。

首先要说的是图像旋转是动态计算的。这意味着每次设置图像的能力时,LiveCode 都会重新计算图像的所有像素,这是非常昂贵的。在台式机上,你有一个非常强大的 CPU,所以旋转图像很容易处理并且看起来很流畅,但移动设备的 CPU 不那么强大,并且很难完成这个操作。

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

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

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

可能的解决方案 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

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

为了在移动设备上获得良好的性能,当您打开应用程序时,重复轮子在 359 个位置的所有图像并调用:

prepare image

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

关于image-processing - 加速旋转图像 - LiveCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24808819/

相关文章:

python - 处理视频时如何使用 matplotlib 随时间绘制每秒帧数 (fps)?

user-interface - LiveCode 负 "firstIndent"- 或其他方式来实现效果 ("hanging indent")?

c++ - opencv 中的 StereoBM 类是否对输入图像或帧进行校正?

android - OpenCV 错误 : Assertion failed (channels() == CV_MAT_CN (dtype))

PHP 动态调整图像大小(即时)

numpy - 查找一组像素附近的所有像素

mysql - 如何在 Livecode 应用程序中将 UTF-8 数据保存在 MySQL 数据库中

livecode - LiveCode 开发人员如何从标准模板模拟多个打开的文档?

ios - 如何在 livecode 8.1x 中捕获 iOS 网络浏览器中的 URL

php - 在 Mac Mavericks 上停止内置的 php 服务器 - Livecode