zoukankan      html  css  js  c++  java
  • Flash动画教程学习(三)高级运动

    第三部分 高级运动

    第八章 缓动和弹性

    1. 缓动:越是靠近目标越慢

                                var vx:Number = (targetX - ball.x) * easing;

                                var vy:Number = (targetY - ball.y) * easing;

                                ball.x += vx;

                                    ball.y += vy;

    何时停止缓动?

    If(Math.abs(dx)<1){

      Ball.x = target;

      removeEventListener(Event.ENTER_FRAME);

      trace(“done”);

    }

    跟随目标移动:

                                var vx:Number = (mouseX - ball.x) * easing;

                                var vy:Number = (mouseY - ball.y) * easing;

                                ball.x += vx;

                                    ball.y += vy;

    1. 缓动不只是应用于运动:

    透明度:ball.alpha += (targetAlpha-ball.alpha)*easing;

    旋转:arrow.rotation += (targetRotation-arrow.rotation)*easing;

    颜色:red += (redTarget - red)*easing;

    1. 弹性:(一维弹性)越是靠近目标越快(初始位置和目标位置保持一定距离,以便加速)

                                var dx:Number = targetX - ball.x;

                                var ax:Number = dx * spring;

                                vx += ax;

                                    ball.x += vx;

    加入摩擦值:

                                var dx:Number = targetX - ball.x;

                                var ax:Number = dx * spring;

                                vx += ax;

                                vx *= friction;//0.95

                                    ball.x += vx;

    二维弹性:带摩擦力

                                var dx:Number = targetX - ball.x;

                                var dy:Number = targetY - ball.y;

                                var ax:Number = dx * spring;

                                var ay:Number = dy * spring;

                                vx += ax;

                                vy += ay;

                                vx *= friction;

                                vy *= friction;

                                ball.x += vx;

                                    ball.y += vy;

    移动目标点的弹性:跟随鼠标弹动(将targetX更改为mouseX就OK了)

                                var dx:Number = mouseX - ball.x;

                                    var dy:Number = mouseY - ball.y;

    画出求与鼠标间的线:

                                graphics.clear();

                                graphics.lineStyle(1);

                                graphics.moveTo(mouseX, mouseY);

                                    graphics.lineTo(ball.x, ball.y);

    多目标点弹性:

    利用函数调用、循环、数组实现

  • 相关阅读:
    算法
    jquery-lazyload延迟加载图片
    配置图片服务器
    Flutter开发之dart语言从入门到精通(从入坑到入土)
    阿里淘系技术分享:Flutter 快速上手方法!!!
    如何优雅的处理 Android 重复点击 [建议收藏]
    还谈论Android的前景?根本没什么好问的……
    一个商业级智能家居 Android 开源项目分享
    【前端算法】拼多多技术面试算法题分享
    美团Android岗面试真题:手写红黑树详解
  • 原文地址:https://www.cnblogs.com/tinytiny/p/2432835.html
Copyright © 2011-2022 走看看