2014-07-17 72 views
3

我一直在使用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的,关闭大部分的信息谷歌给我的访问。这是否发生在每个人身上?

回答

2

使用由用户本杰明·博蒙特(再次感谢!)提供的代码,我得到了它运行像我想要的。为了给它平滑运动和减速,我用下面的代码:

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 
5

当我在我的苹果机上的图像上尝试代码时,它很好,很流畅。我会假设你正在开发一款移动应用程序。

首先要说的是,图像旋转是即时计算的。这意味着每次设置图像的能力时,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预加载图像到内存使它可能会呈现一些非常流畅的动画。

+0

Thanks!第一种解决方案使其具有相同的速度,我不会为任何易移动设备构建,而我正在使用带有1GB视频卡和16克RAM的OSX,因此不会是问题,可以吗? 第二个解决方案给我一个错误(无法打开文件(或标记文件)附近的[图像的路径]。这段代码进入按钮,对吧? – TianRB

+0

啊,这将是因为它无法找到文件夹..我在我的LiveCode堆栈文件旁边手动创建它。 –