lufy's legend

标题: onframe下遍历生成的障碍物做碰撞检测,安卓手机不执行 [打印本页]

作者: liwenjie    时间: 2016-11-23 10:56
标题: onframe下遍历生成的障碍物做碰撞检测,安卓手机不执行
控制2个小汽车躲避障碍物游戏,背景向下滚动,小车可以左右躲避,障碍物随机生成和背景一起向下,车碰到障碍物游戏结束,整个项目用了一个onframe里面代码如下,iphone和PC都没问题,安卓不执行碰撞,好像是onframe里面有遍历造成的安卓不执行,大神们给看下,谢谢。
function onframe()
{
        bgcon();//背景层滚动
   if(stageSpeed-- < 0){
     stageSpeed = 80;
        addzaw();//添加障碍物
        }
        var key = null;
        var _child;
        for(key in stageLayer.childList)//遍历障碍物
        {
                _child = stageLayer.childList[key];
                _child.y+=5;
                lable.text=count;
                if(LGlobal.hitTestRect(_child,c_0) || LGlobal.hitTestRect(_child,c_1)){//碰撞检测
                bgs.remove();//清除移动背景
                stageLayer.remove();//清除障碍物层       
                gameover();//游戏结束提示
        }

                if(_child.y>1000)//障碍物落到车下面自动销毁
                {
                        count++;
                        _child.visible=false;
                        _child.remove();
                }
        }
}
作者: liwenjie    时间: 2016-11-23 11:15
翻看了之前别人的提问,找到了一个方法好像问题解决了,更改后的代码如下:
function onframe()
{
        bgcon();//背景层滚动
   if(stageSpeed-- < 0){
     stageSpeed = 80;
        addzaw();//添加障碍物
        }
        var _child;
        for(var key=0;key<stageLayer.childList.length;key++)//遍历障碍物
        {
                _child = stageLayer.childList[key];
                _child.y+=5;
                lable.text=count;
                if(_child.hitTestObject(c_0) || _child.hitTestObject(c_1)){//碰撞检测
                bgs.remove();//清除移动背景
                stageLayer.remove();//清除障碍物层       
                gameover();//游戏结束提示
        }
                if(_child.y>1000)//障碍物落到车下面自动销毁
                {
                        count++;
                        _child.visible=false;
                        _child.remove();
                }
        }
}




欢迎光临 lufy's legend (http://lufylegend.com/forum/) Powered by Discuz! X2.5