会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
HelloCG
越挫越勇.
博客园
首页
新随笔
联系
订阅
管理
弹性鼠标跟随
1.创建小球精灵
Ball.as
package
{
import
flash.display.Sprite;
public
class
Ball
extends
Sprite
{
public
var
radius:
Number
;
public
var
color:
uint
;
public
function
Ball (radius:
Number
,color:
uint
)
{
this
.radius
=
radius;
this
.color
=
color;
Init ();
}
public
function
Init ():
void
{
graphics.beginFill
(color);
graphics.drawCircle
(
0
,
0
,radius);
graphics.endFill
();
}
}
}
2.构建弹性鼠标跟随动画
Spring.as
package
{
import
flash.display.Sprite;
import flash.events.Event;
public
class
Spring
extends
Sprite
{
private
var
ball:Ball;
private
var
spring:
Number
=
0.1
;
private
var
vx:
Number
=
0
;
private
var
vy:
Number
=
0
;
private
var
friction:
Number
=
0.9
;
private
var
gravity:
Number
=
0.5
;
public
function
Spring ()
{
Init ();
}
public
function
Init ():
void
{
ball
=
new
Ball(
20
,
0xFF00FF
);
addChild
(ball);
addEventListener
(
Event.ENTER_FRAME
,EnterFrame);
}
private
function
EnterFrame (e:
Event
):
void
{
var
dx:
Number
=
mouseX
-
ball.
x
;
var
dy:
Number
=
mouseY
-
ball.
y
;
var
ax:
Number
=
dx
*
spring
;
var
ay:
Number
=
dy
*
spring;
vx
+=
ax;
vy
+=
ay;
vy
+=
gravity;
vx
*=
friction;
vy
*=
friction;
ball.
x
+=
vx;
ball.
y
+=
vy;
graphics.clear
();
graphics.lineStyle
(
1
);
graphics.moveTo
(ball.
x
,ball.
y
);
graphics.lineTo
(
mouseX
,
mouseY
);
}
}
}
注意:帧率提高,效果会准确。
posted @
2008-12-31 15:47
HelloCG
阅读(
201
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
公告