如何使它们都具有相同的速度(AS3)

发布于 2024-08-19 05:19:22 字数 1236 浏览 4 评论 0原文

我目前有一个无限旋转的动画,但一开始就太快了...我尝试将 fps 降低到 12,但它只会被跳过...是否有可能通过此代码使动画变慢:

//Import TweenMax
import com.greensock.TweenMax;

//Save the horizontal center
var centerX:Number = stage.stageWidth / 2;

//Save the width of the whole gallery
var galleryWidth:Number = infiniteGallery.width;

//Speed of the movement (calculated by the mouse position in the moveGallery() function)
var speed:Number = 0.02;

//Add an ENTER_FRAME listener for the animation
addEventListener(Event.ENTER_FRAME, moveGallery);

function moveGallery(e:Event):void {

    //Calculate the new speed
    speed = -(0.02 * (mouseX - centerX));

    //Update the x coordinate
    infiniteGallery.x+=speed;

    //Check if we are too far on the right (no more stuff on the left edge)
    if (infiniteGallery.x>0) {

        //Update the gallery's coordinates
        infiniteGallery.x= (-galleryWidth/2);
    }

    //Check if we are too far on the left (no more stuff on the right edge)
    if (infiniteGallery.x<(-galleryWidth/2)) {

        //Update the gallery's coordinates
        infiniteGallery.x=0;
    }
}

此处是 演示 »

I currently have an animation that rotate infinitely but it's just too fast to begin with... I tried lowering the fps to 12 but it would just be skip.... Is there a possibility to make the animation slower by this code:

//Import TweenMax
import com.greensock.TweenMax;

//Save the horizontal center
var centerX:Number = stage.stageWidth / 2;

//Save the width of the whole gallery
var galleryWidth:Number = infiniteGallery.width;

//Speed of the movement (calculated by the mouse position in the moveGallery() function)
var speed:Number = 0.02;

//Add an ENTER_FRAME listener for the animation
addEventListener(Event.ENTER_FRAME, moveGallery);

function moveGallery(e:Event):void {

    //Calculate the new speed
    speed = -(0.02 * (mouseX - centerX));

    //Update the x coordinate
    infiniteGallery.x+=speed;

    //Check if we are too far on the right (no more stuff on the left edge)
    if (infiniteGallery.x>0) {

        //Update the gallery's coordinates
        infiniteGallery.x= (-galleryWidth/2);
    }

    //Check if we are too far on the left (no more stuff on the right edge)
    if (infiniteGallery.x<(-galleryWidth/2)) {

        //Update the gallery's coordinates
        infiniteGallery.x=0;
    }
}

here is the demo »

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零時差 2024-08-26 05:19:22

speed = -(0.02 * (mouseX - centerX)); 中尝试使用小于 0.02 的数字

Try a smaller number than 0.02 in speed = -(0.02 * (mouseX - centerX));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文