【问题标题】:Spinning an Image with acceleration - LiveCode加速旋转图像 - LiveCode
【发布时间】:2014-09-08 15:16:25
【问题描述】:

我已经使用 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,关闭对谷歌提供给我的大部分信息的访问。每个人都会遇到这种情况吗?

【问题讨论】:

    标签: image-processing livecode


    【解决方案1】:

    使用用户 Benjamin Beaumont 提供的代码(再次感谢!),我让它按我想要的方式运行。为了让它平滑移动和减速,我使用了以下代码:

    on mouseUp
      put randomInRange(15,45) into i
      set the resizeQuality of image 1 to "normal"
      put 0 into mi
      repeat with x=0 to i
         set the angle of image 1 to the angle of image 1 + (i - mi)
         put mi+1 into mi
         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
    

    减速是完全线性的,但看起来还不错,注意 randomInRange 不是 LiveCode 函数,如果有人想要,这里是:

    function randomInRange lowerLimit,upperLimit
         return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
    end randomInRange
    

    【讨论】:

      【解决方案2】:

      当我在我的 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
      

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

      可能的解决方案 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 将图像预加载到内存中,从而可以渲染一些非常流畅的动画。

      【讨论】:

      • 谢谢!第一个解决方案使它以相同的速度运行,我不是为任何移动设备构建的,我使用的是 OSX 和 1gb 显卡和 16g RAM,所以这不是问题,可以吗?第二种解决方案给了我一个错误(无法在 [Path of image] 附近打开文件(或标记文件)。此代码进入按钮,对吗?
      • 啊,那是因为找不到文件夹。。我在 LiveCode 堆栈文件旁边手动创建了它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      相关资源
      最近更新 更多