[AS3]as3控制减速运动代码实例
[AS3]as3控制减速运动代码实例,as3控制减速,as3移动,as3位置
x方向的移动:(mouseX - object.x) * speed;
y方向的移动:(mouseY - object.y) * speed;
物体与目标位置的距离:
var vx:Number = (mouseX - circle.x);
var vy:Number = (mouseY - circle.y);
var distance:Number = Math.sqrt(vx*vx + vy*vy);
- package {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- public class Sample0515 extends Sprite
- {
- private var timer:Timer;
- private var circle:Sprite;
- public function Sample0515()
- {
- circle = new Sprite();
- circle.graphics.beginFill(0xFFFF00);
- circle.graphics.drawCircle(0,0,25);
- circle.graphics.endFill();
- this.addChild(circle);
- stage.addEventListener(MouseEvent.CLICK,onClick);
- timer = new Timer(30);
- timer.addEventListener(TimerEvent.TIMER,onTimer);
- timer.start();
- }
- private function onClick(event:MouseEvent):void
- {
- if(circle.x != mouseX && circle.y != mouseY)
- {
- timer.start();
- }
- }
- private function onTimer(event:TimerEvent):void
- {
- var vx:Number = (mouseX - circle.x);
- var vy:Number = (mouseY - circle.y);
- var distance:Number = Math.sqrt(vx*vx + vy*vy);
- if(distance<1)
- {
- timer.stop();
- circle.x = mouseX;
- circle.y = mouseY;
- }
- else
- {
- circle.x += vx * 0.1;
- circle.y += vy * 0.1;
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...