Flash动画教程学习(一)--动画基础

第一部          ActionScript动画基础

第二章 动画基础

  1. 类和OOP:

基类、包、导入、构造函数、继承、

Sprite精灵

移除侦听事件:removeEventListener(,);

帧循环:

默认循环、gotoAndPlay()

  1. addChild添加元件到舞台上

removeChild将一个元件从舞台移除,却不删除

  1. 鼠标事件:

CLICK/DOUBLE_CLICK/MOUSE_DOWN/MOUSE_MOVE/MOUSE_OUT/MOUSE_OVER/MOUSE_UP/MOUSE_WHEEL/ROLL_OUT/ROLL_OVER

  1. 鼠标位置:针对MC

如果:MC 100.100    鼠标:150.250 则

mouseX:150     mousey:250

MC.mouseX: 50    MC.mouseY:150

  1. 键盘事件:KEY_DOWN   KEY_UP:
  2. 键盘代码:charCode:按下键的字符如“a”、keyCode:按下键的数字“65”

第三章 动画中的三角学

  1. 弧度和度数的转换:

度:degree

弧度:radian = 57.2958*degree

Radians = degrees*Math.PI/180;

Degrees = radians*180/Math.PI;

正弦:sin(degrees*Math.PI/180)

正切:tan(degrees*Math.PI/180);

  1. 使用graphics画出arrow:

package {

         import flash.display.Sprite;

        

         public class Arrow extends Sprite {

                   public function Arrow() {

                            init();

                   }

                   public function init():void {

                            graphics.lineStyle(1, 0, 1);

                            graphics.beginFill(0xffff00);

                            graphics.moveTo(-50, -25);

                            graphics.lineTo(0, -25);

                            graphics.lineTo(0, -50);

                            graphics.lineTo(50, 0);

                            graphics.lineTo(0, 50);

                            graphics.lineTo(0, 25);

                            graphics.lineTo(-50, 25);

                            graphics.lineTo(-50, -25);

                            graphics.endFill();

                   }

         }

}

Arrow旋转:

package

{

         import flash.display.Sprite;

         import flash.events.Event;

         public class RotateToMouse extends Sprite {

                   private var arrow:Arrow = new Arrow();

                  

                   public function RotateToMouse()    {

                            init();

                   }

                   private function init():void {

                            //var arrow = new Arrow();

                            addChild(arrow);

                            arrow.x = stage.stageWidth / 2;

                            arrow.y = stage.stageHeight / 2;

                            addEventListener(Event.ENTER_FRAME, onEnterFrame);

                   }

                   public function onEnterFrame(event:Event):void {

                            var dx:Number = mouseX - arrow.x;

                            var dy:Number = mouseY - arrow.y;

                            var radians:Number = Math.atan2(dy, dx);

                            arrow.rotation = radians * 180 / Math.PI;

                   }

         }

}

注意:变量声明的范围

Math.atan(y/x):求反正切

Math.atan2(y,x):能区分正负的反正切,别忘了转换为度数

  1. 正弦曲线:

graphics.lineStyle(-10, -10, -11);

graphics.beginFill(0xffff00);

graphics.moveTo(200, 200);

for(var angle:Number = 0;angle < Math.PI*2;angle+=0.1){

         graphics.lineTo(200+angle*100, 200+Math.sin(angle)*100);

}

graphics.endFill();

  1. 将数值保持在动画代码之外。
  2. 脉冲动画:

ball.scaleX = ball.scaleY = 1 + Math.sin(angle)*0.5;

  1. 画圆:

ball.x = 200 + Math.sin(angle)*50;

ball.y = 200 + Math.cos(angle)*50;

  1. 椭圆:

ball.x = 200 + Math.sin(angle)*100;

ball.y = 200 + Math.cos(angle)*200;

  1. 求两个球之间的距离:

Math.Sqrt((X1-x2)*(X1-x2)+(y1-y2)*(y1-y2));

第四章 渲染技术

  1. drawing API

clear():移除绘画

lineStyle(width,color,alpha):线条样式(线条宽度,颜色,透明度)

moveTo(x,y):起点

lineTo(x,y):从当前点画到下一个点,直线

curveTo(x1,y1,x2,y2):从当前点画到下一个点,曲线(第一个点控制点,第二个点终点)

beginFill(color,,alpha):注意alphia从0-1.0

endFill():结束填充

beginGradientFill(fillType,colors,alphas,ratios,matrix):渐变填充,

使用方法:

Mc.graphics.***

  1. 什么是文档类?
  2. 曲线:

import flash.display.Sprite;

var s:Sprite = new Sprite();

addChild(s);

s.graphics.lineStyle(1);

s.graphics.moveTo(100,100);

s.graphics.lineTo(110,110);

s.graphics.curveTo(114,0,115,115);

  1. 滤镜(发光)

投影:drop shadow

模糊:blur

发光:glow

浮雕:bevel

渐变浮雕:gradient bevel

渐变发光:gradient glow

颜色矩阵:color matrix

卷积滤镜:convolution

置换贴图:displacement map

import flash.filters.GlowFilter;

var b:GlowFilter = new GlowFilter(5);

var f:Array = new Array();

f.push(b);

s.filters = f;

  1. 位图:bitmap和bitmapData:

画好bitmapData后,无法添加到舞台上;

使用bitmap,var mybitamap:bitmap = bitmap(bitmapdata)

  1. 载入或者嵌入内容:

影片运行时:载入;影片编译时:嵌入。

1>载入内容:flash.display.Loader;

需要创建一个:flash.net.URLLoader实例,放置路径

Var loader:Loader = new Loader();

addChild(loader);

loader.load(new URLRequest(“picture.jpg”));

2>嵌入内容:需要用到Embed

[Embed(source=”picture.jpg”)];

Private var Image:Class;//作为一个类使用(类型可能为bitmap/mc)

posted @ 2012-03-31 10:44  tinytiny  阅读(445)  评论(0编辑  收藏  举报