先看实例:
?
使用实例:
//flash原创代码
//尽在自娱自乐?www.MyGameMyLove.com
//物体左右跳跃的类as2.0
//水平速度
var?xsd:Number?=?10;
//重力
var?numg:Number?=?5;
//垂直速度
var?ysd:Number?=?-18;
//声明对象
//对象名称obj_实例名称,
var?obj_mc?=?new?jump?(mc,?xsd,?numg,?ysd);
_root.onEnterFrame?=?function?()
{
obj_mc.onEnterFrame?();
};
var?keyListener:Object?=?new?Object?();
keyListener.onKeyUp?=?function?()
{
switch?(Key.getCode?())?{
case?37?:
??//trace?("");
??obj_mc.go(1);
??break;
}
};
Key.addListener?(keyListener);
[1b]类文件:##########################################[/1b]
class?jump
{
//mc目标影片
var?mc:MovieClip;
//水平速度
var?xsd:Number;
//重力
var?numg:Number;
//垂直速度
var?ysd:Number;
var?iniYsd:Number;
//地面的位置
var?iniY:Number;
private?var?jumpx:Number;
//是不是第一次开始跳跃
private?var?isFirst:Boolean?=?true;
//是否开始跳
private?var?isJump:Boolean?=?false;
//初使化
function?jump?(mc:MovieClip,?xsd:Number,?numg:Number,?ysd:Number)
{
??this.mc?=?mc;
??this.xsd?=?xsd;
??this.numg?=?numg;
??//
??this.iniYsd?=?ysd;
??this.ysd?=?ysd;
??//
??iniY?=?mc._y;
}
//跳
function?go?(jumpx:Number)
{
??if?(!isJump)?{
???isJump?=?true;
???this.jumpx?=?jumpx;
??}
}
//?检测是否跳,并作跳的处理
function?jumping?()
{
??if?(!isJump)?{
???return?0;
??}
??//
??if?(isFirst)?{
???ysd?+=?numg;
???mc._y?+=?ysd;
???mc._x?+=?xsd?*?jumpx;
???isFirst?=?false;
??}
??else?{
???if?((mc._y?+?ysd?+?numg)?
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/3454.html