- 注册时间
- 2013-2-20
- 最后登录
- 2020-1-26
- 阅读权限
- 45
- 积分
- 1866
- 精华
- 1
- 帖子
- 181
|
我看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 |
|