如何用AS实现摆动

    文章来源:中国互联 更新时间:2012-11-20 17:50:11
分享:

As3摆动算法

 

package com.klstudio.algorithms { 

import flash.events.MouseEvent; 

import flash.events.Event; 

import flash.display.MovieClip; 

import flash.display.Sprite; 

 

/**

* 摆动算法

* @author Kinglong(kinglong@gmail.com)

* @since:2010-9-20

*/ 

[SWF(width = 550, height = 400, frameRate = 24, backgroundColor = 0x333333)] 

 

public class Swing extends Sprite { 

/**

* 显示元件

*/ 

private var _icon : MovieClip; 

 

/**

* xy弧度

*/ 

private var _xAngle : Number; 

private var _yAngle : Number; 

/**

* xy摆动的速度

*/ 

private var _xSpeed : Number; 

private var _ySpeed : Number; 

/**

* xy摆动的振幅

*/ 

private var _xRadius : Number; 

private var _yRadius : Number; 

 

private var _mod : int; 

 

public function Swing() { 

_icon = new jAcid_smiley();          

addChild(_icon);         

initParams();    

stage.addEventListener(MouseEvent.CLICK, stageHandler);      

addEventListener(Event.ENTER_FRAME, enterFrameHandler); 

 

private function initParams(mod : int = 0) : void { 

_mod = mod; 

switch(_mod) { 

case 0:                  

case 1: 

case 2: 

_xAngle = _yAngle = 0; 

_xSpeed = _ySpeed = 0.05; 

_xRadius = _yRadius = 100; 

break; 

case 3: 

_xSpeed = 0.15; 

_ySpeed = 0.05; 

_xRadius = 100; 

_yRadius = 50; 

break; 

 

private function stageHandler(event : Event) : void { 

var mod : int = _mod + 1; 

initParams(mod % 4); 

 

private function enterFrameHandler(event : Event) : void { 

switch(_mod) { 

case 0: 

_icon.x = 0; 

_icon.y = 100; 

_icon.x = 200 + Math.sin(_xAngle) * _xRadius; 

_xAngle += _xSpeed; 

break;               

case 1: 

_icon.x = 100; 

_icon.y = 100; 

_icon.y = 200 + Math.cos(_yAngle) * _yRadius;                    

_yAngle += _ySpeed;  

break; 

case 2: 

case 3: 

_icon.x = 0; 

_icon.y = 100; 

_icon.x = 200 + Math.sin(_xAngle) * _xRadius;                    

_icon.y = 200 + Math.cos(_yAngle) * _yRadius; 

_xAngle += _xSpeed;              

_yAngle += _ySpeed;                      

break; 

文章来源:http://www.163ns.com,转载请注明!

在线咨询
  • 在线时间
  • 8:00-21:00
如何用AS实现摆动-中国互联

如何用AS实现摆动

    文章来源:中国互联 更新时间:2012-11-20 17:50:11
分享:

As3摆动算法

 

package com.klstudio.algorithms { 

import flash.events.MouseEvent; 

import flash.events.Event; 

import flash.display.MovieClip; 

import flash.display.Sprite; 

 

/**

* 摆动算法

* @author Kinglong(kinglong@gmail.com)

* @since:2010-9-20

*/ 

[SWF(width = 550, height = 400, frameRate = 24, backgroundColor = 0x333333)] 

 

public class Swing extends Sprite { 

/**

* 显示元件

*/ 

private var _icon : MovieClip; 

 

/**

* xy弧度

*/ 

private var _xAngle : Number; 

private var _yAngle : Number; 

/**

* xy摆动的速度

*/ 

private var _xSpeed : Number; 

private var _ySpeed : Number; 

/**

* xy摆动的振幅

*/ 

private var _xRadius : Number; 

private var _yRadius : Number; 

 

private var _mod : int; 

 

public function Swing() { 

_icon = new jAcid_smiley();          

addChild(_icon);         

initParams();    

stage.addEventListener(MouseEvent.CLICK, stageHandler);      

addEventListener(Event.ENTER_FRAME, enterFrameHandler); 

 

private function initParams(mod : int = 0) : void { 

_mod = mod; 

switch(_mod) { 

case 0:                  

case 1: 

case 2: 

_xAngle = _yAngle = 0; 

_xSpeed = _ySpeed = 0.05; 

_xRadius = _yRadius = 100; 

break; 

case 3: 

_xSpeed = 0.15; 

_ySpeed = 0.05; 

_xRadius = 100; 

_yRadius = 50; 

break; 

 

private function stageHandler(event : Event) : void { 

var mod : int = _mod + 1; 

initParams(mod % 4); 

 

private function enterFrameHandler(event : Event) : void { 

switch(_mod) { 

case 0: 

_icon.x = 0; 

_icon.y = 100; 

_icon.x = 200 + Math.sin(_xAngle) * _xRadius; 

_xAngle += _xSpeed; 

break;               

case 1: 

_icon.x = 100; 

_icon.y = 100; 

_icon.y = 200 + Math.cos(_yAngle) * _yRadius;                    

_yAngle += _ySpeed;  

break; 

case 2: 

case 3: 

_icon.x = 0; 

_icon.y = 100; 

_icon.x = 200 + Math.sin(_xAngle) * _xRadius;                    

_icon.y = 200 + Math.cos(_yAngle) * _yRadius; 

_xAngle += _xSpeed;              

_yAngle += _ySpeed;                      

break; 

文章来源:http://www.163ns.com,转载请注明!

在线咨询
  • 在线时间
  • 8:00-21:00