[ActionScript 3.0] AS3.0 对象在矩形范围随机运动
package com.views
{ import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event; /**
* @author:Frost.Yen
* @E-mail:871979853@qq.com
* @create: 2016-7-7 下午2:33:56
*
*/
public class LogoView extends Sprite
{
private var _stageW:Number = 1920;
private var _stageH:Number = 1080;
private var _mc:MovieClip = new MovieClip();
public function LogoView(bmp:Bitmap)
{
_mc.addChild(bmp);
bmp.x = -bmp.width*0.5;
bmp.y = -bmp.height*0.5;
initLogo();
} private function initLogo():void{ //随机位置
_mc.x = Math.random()*_stageW;
_mc.y = Math.random()*_stageH;
//随机速度和方向
Math.random()>0.5?_mc.speedX = Math.random()*5+1 : _mc.speedX = -1 * Math.random()*5+1
Math.random()>0.5?_mc.speedY = Math.random()*5+1 : _mc.speedY = -1 * Math.random()*5+1
//因为logo的坐标原点是logo的中心,所以用该函数用来调整logo位置,防止移出边界
adjustBall(_mc);
//添加logo到显示列表
addChild(_mc);
//用ENTER_FRAME侦听器使logo运动
//startMove();
} private function adjustBall(mc:MovieClip):void{
if(mc.x > _stageW-mc.width/2){mc.x = _stageW-mc.width/2;}
if(mc.x < mc.width/2){mc.x = mc.width/2};
if(mc.y > _stageH-mc.height/2){mc.y = _stageH-mc.height/2;}
if(mc.y < mc.height/2){mc.y = mc.height/2;}
} private function onEnterFrame(evt:Event):void{
//改变logo的坐标让小球运动
evt.target.x += evt.target.speedX;
evt.target.y += evt.target.speedY;
//检测logo是否碰到舞台边界
if(evt.target.x >= _stageW-evt.target.width/2 || evt.target.x <= evt.target.width/2){
evt.target.speedX *= -1;
}
if(evt.target.y >= _stageH-evt.target.height/2 || evt.target.y <= evt.target.height/2){
evt.target.speedY *= -1;
}
}
public function startMove():void
{
_mc.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
public function stopMove():void
{
_mc.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
}
[ActionScript 3.0] AS3.0 对象在矩形范围随机运动的更多相关文章
- [ActionScript 3.0] AS3.0和AS2.0的相互通信
AS3和AS2之间的通信,最好的方式可能就是LocalConnection了. AS2向AS3发送数据,即AS2调用AS3的函数: as2.0代码(按钮上写的发送信息代码): on (release) ...
- [ActionScript 3.0] AS3.0 让一个视频无缝循环播放的一个偏方
一个视频要循环播放,通常的办法都是播放完后再重新播放,但是不可避免的播放结束和重新开始播放这个时间点上会有停顿,如何解决这个问题,说个偏方吧! package com.views { import f ...
- [ActionScript 3.0] AS3.0 下雨及涟漪效果
帧代码: stage.frameRate = 80; function init(x1:Number,y1:Number) { var mc:MovieClip=new MovieClip(); ad ...
- [ActionScript 3.0] AS3.0 对象在一定范围随机显示不重叠
import flash.geom.Rectangle; import flash.display.MovieClip; import flash.display.Sprite; var arr:Ar ...
- [ActionScript 3.0] AS3.0 本机鼠标指针
Flash Player 10.2添加了内置的本机鼠标指针(native mouse cursor)支持,虽然在之前的版本里我们可以侦听MouseEvent事件来模拟鼠标指针,但是在有了原生的本机鼠标 ...
- [ActionScript 3.0] AS3.0 动态加载显示内容
可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...
- [ActionScript 3.0] AS3.0 涂鸦及擦除功能,撤销重做步骤记录实例
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BlendMo ...
- [ActionScript 3.0] AS3.0 简单封装Socket的通信
Socket服务器 package com.controls.socket { import com.models.events.AppEvent; import com.models.events. ...
- [ActionScript 3.0] AS3.0 Socket通信实例
以下类是充当Socket服务器的例子 package { import flash.display.Sprite; import flash.events.Event; import flash.ev ...
随机推荐
- linux 2.6.21版本的内核合法的MAC地址
当执行ifconfig eth0 hw ether 11:22:33:44:55:66时,当前内核显示修改成功,但是ping时只无限发送ARP包,PC机也已经给板子回ARP包,但没有任何ICMP包的信 ...
- Visual Studio 编译项目失败,提示找不到文件
博客地址:http://blog.csdn.net/FoxDave 今天碰到了一个蠢问题,虽然咱们正常情况下是遇不到的,但这确实是个应该注意的地方,所以简单记录一下. Visual Studio ...
- windows核心编程---第二章 字符和字符串处理
使用vc编程时项目-->属性-->常规栏下我们可以设置项目字符集合,它可以是ANSI(多字节)字符集,也可以是unicode字符集.一般情况下说Unicode都是指UTF-16.也 ...
- HDU 4734 F(x)
这题可能非递归版好写? #include<iostream> #include<cstdio> #include<cstring> #include<algo ...
- MySQL起航
以前学php的时候用过MySQL,但是都没有认真地学习,只会在php代码中用几条极其简单SQL语句,以为MySQL就这么点用法,当时还在嘲笑学长们为什么会觉得MySQL难学,真是太尴尬了.好在开了数据 ...
- 十分钟了解分布式计算:Petuum
Petuum是一个机器学习专用分布式计算框架,本文介绍其架构,并基于文章 More Effective Distributed ML via a Stale Synchronous Parallel ...
- border-image(转载)
本文转自:http://www.zhangxinxu.com/wordpress/2010/01/css3-border-image%E8%AF%A6%E8%A7%A3%E3%80%81%E5%BA% ...
- Nagios NSclient Failed to get CPU value: \238(_total)\6: Failed to get mutex :(
一台Windows Server 2012的nsclient出现以下的错误,表示无法获得CPU信息 2016-08-08 10:31:33: e:..\..\..\..\trunk\modules\C ...
- REST概念和应用 - TODO
Motivation Sometimes I fell like giving up, then I remember I have a lot of motherfuckers to prove w ...
- ubuntu下mysql的常用命令,MySQL数据库的基本操作命令
一.mysql服务操作 0.查看数据库版本 sql-> status; 1.net start mysql //启动mysql服务 2.net stop mysql //停止mysql服务 3 ...