lufy's legend
标题:
LHitList类
[打印本页]
作者:
yorhomwang
时间:
2013-5-6 13:39
标题:
LHitList类
我看lufylegend差一个功能,那就是返回碰撞列表。
如果加了这个功能就可以搞一个泡泡龙一类的游戏。
因此我帮忙封装了一下,代码如下:
function LHitList(objectA,sprite,type){
if(!objectA)trace("The first param was not assigned.");
if(!sprite)trace("The second param was not assigned.");
if(!type)type = "TestRect";
var s = this;
s.objectA = objectA;
s.objectB = null;
s.sprite = sprite;
s.ishit = false;
s.list = [];
s.type = type;
}
LHitList.prototype.getList = function(){
var s = this;
var n = s.sprite.childList.length;
if(s.type != "TestRect" && s.type != "TestArc"){
trace("Type is wrong. It must be 'TestRect' or 'TestArc'.");
}else{
while(n--){
s.objectB = s.sprite.childList[n];
if(s.type == "TestRect"){
s.ishit = LGlobal.hitTest(s.objectA,s.objectB);
}else if(s.type == "TestArc"){
s.ishit = LGlobal.hitTestArc(s.objectA,s.objectB);
}
if(s.ishit == true && s.objectB != s.objectA){
s.list[s.list.length] = s.sprite.childList[n];
}
}
return s.list;
}
}
LHitList.prototype.clearList = function(){
var s = this;
s.list = [];
}
复制代码
用法如下:
LHitList(objectA,sprite,type)
参数:
objectA:碰撞区域A
sprite:一个sprite对象,用它的成员判断是否和碰撞区域A是否碰撞
type:碰撞类型,现在只有'TestRect'和 'TestArc'两种
方法:
getList:取出碰撞列表
clearList:清楚碰撞列表
测试地址:
http://www.cnblogs.com/yorhom/articles/3062583.html
作者:
战胜自我
时间:
2014-1-23 11:21
路过 看看。
欢迎光临 lufy's legend (http://lufylegend.com/forum/)
Powered by Discuz! X2.5