Flash basic Theory Class chapter III Application of Trigonometry Ⅱ

Source: Internet
Author: User
Tags addchild range sin

Back to "flash Basic Theory Class-Catalog"

Linear vertical Motion

In the wave1.as file, a linear vertical motion is added, just to add some inspiration to our animation. The following is the code for this file:

package {
 import flash.display.Sprite;
 import flash.events.Event;
 public class Wave1 extends Sprite {
  private var ball:Ball;
  private var angle:Number = 0;
  private var centerY:Number = 200;
  private var range:Number = 50;
  private var xspeed:Number = 1;
  private var yspeed:Number = .05;
  public function Wave1() {
   init();
  }
  private function init():void {
   ball = new Ball();
   addChild(ball);
   ball.x = 0;
   addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }
  public function onEnterFrame(event:Event):void {
   ball.x += xspeed;
   ball.y = centerY + Math.sin(angle) * range;
   angle += yspeed;
  }
 }
}

Heart Movement

Use sine as a tool, not just for controlling physical locations. In the pulse.as file, a value is used to influence the scaling of the ball to achieve a heartbeat effect, the code is as follows:

package {
 import flash.display.Sprite;
 import flash.events.Event;
 public class Pulse extends Sprite {
  private var ball:Ball;
  private var angle:Number = 0;
  private var centerScale:Number = 1;
  private var range:Number = .5;
  private var speed:Number = .1;
  public function Pulse() {
   init();
  }
  private function init():void {
   ball = new Ball();
   addChild(ball);
   ball.x = stage.stageWidth / 2;
   ball.y = stage.stageHeight / 2;
   addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }
  public function onEnterFrame(event:Event):void {
   ball.scaleX = ball.scaleY = centerScale +Math.sin(angle) * range;
   angle += speed;
  }
 }
}

The principle is the same, Centerscale represents the scaling ratio of 100%, range represents range, and speed represents speed. Not only that, sine wave is also applied in attributes such as alpha,rotation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.