点击浏览该文件 源文件:
点击浏览该文件
此方法不同于Target类,它将功能实现写在chaser上面,使他可以追踪任何一个mc(也可以是其他对象,但主要是针对mc作的这个dd^^)。
Target类则是将功能实现在‘目标’上,使它可以被任何1个对象所追踪。
l 易扩展,继承Chaser类后可以在calculateChase方法中添加需要的追踪属性。
l 通用性。
l 性价比高。。功能要求中等的场合。譬如追踪导弹,有趣的拖动条等。
l 只能追踪特定的属性,不能对不同的对象选择不同的追踪属性,追踪的功能难以细分(下个dd解决这个问题,恩)
l 其他的还在想。。。
*_x
*_y
*_xscale
*_yscale
*_width
*_height
*_rotation
*_alpha
*
*使用方法:将一个mc连接到xp.gameLib.chase.Chaser类或其子类,并设置onChase事件处理函数,用户在onChase函数中实现追踪的具体实现。
*Chaser类仅提供了简单的即时追踪效果.
*不支持指定步长的追踪,或几何速率的追踪。用户可以在子类中扩展并实现这些功能。
*/
classxp.gameLib.chase.Chaserextendsxp.system.MovieClipAdv{
/**
*触发器
*/
staticvarimpulser:Object;
/**
*defaultpropertieslistinwhichthepropertywillbechase.
*默认的属性列表。
*/
staticvardefaultPropList:Object={
_x:1,
_y:1,
_xscale:1,
_yscale:1,
_width:1,
_height:1,
_rotation:1,
_alpha:1
};
/**
*propertieslist,use’addProperty’,’delProperty’toaddorremovepropertiesfromchasing。
*@seeaddProperty
*@seedelProperty
*属性列表,设置那些属性可以被追踪到。当Chaser实例被实例化后,就具有了默认的属性列表。
*/
varpropList:Object;
/**
*mclisttowhichthisChaserchases.
*mc列表,记录那些mc被这个Chaser实例追踪了
*/
privatevarmlist:Array;
/**
*totalweightvalue.
*总的权重。
*/
vartotalWeight:Number;
/**
*constructor
*监听impulser的callChase事件,初始化成员变量。
*/
publicfunctionChaser(){
//forsubclasscreatea’constructor’property.
//functionimplementedinMovieClipAdv.
this["createConstructor"](arguments);
if(impulser==undefined){
impulser=createImpulser();
}
impulser.addListener(this);
propList=newObject();
for(variindefaultPropList){
propList[i]=defaultPropList[i];
}
mlist=newArray();
totalWeight=0;
}
/**
*overWritten
*createaimpulser.
*@returnimpulserimplemented’xp.events.Broadcaster’interface.
*生成一个触发器,定时调用callChase函数,默认生成的impulser每帧调用1次callChase,子类可以覆盖此函数。
*/
functioncreateImpulser():Object{
returnxp.system.Broadcaster.createAutoBroadcaster("callChase",2);
}
/**
*addapropertytochase
*@paramnStringpropertyname
*添加一个被追踪的属性
*/
functionaddProp(n:String){
propList[n]=1;
}
/**
*deleteapropertytochase
*@paramnStringpropertyname
*删除一个被追踪的属性
*/
functiondelProp(n:String){
deletepropList[n];
}
/**
*addanothertargettochase,optionallyspecifyingaweightvalueforcalculatingchasingresult.
*@parammMovieClipinstancetochase.
*@paramwweight.
*添加一个被追踪的目标。
*/
functionaddTarget(m:MovieClip,w:Number){
if(!m)return;
if(w==undefined||isNaN(w))w=1;
//pushinstancetoqueue,&rememberitsposition.










共有 0 位网友发表了评论,得分 0 分,平均 0 分 查看完整评论