首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字符hitTest墙

字符hitTest墙
EN

Stack Overflow用户
提问于 2014-09-20 23:06:05
回答 1查看 153关注 0票数 0

我目前的平台游戏项目的问题是,字符在撞到角色左侧的墙壁之前就停止了,而在角色的右侧停止太晚了。

下面是与问题相关的脚本:

代码语言:javascript
复制
char.topBumping=false;
char.bottomBumping=false;
char.leftBumping=false;
char.rightBumping=false;

char.speed=0;
char.maxSpeedConstant=10;
char.minSpeedConstant=-10;

char.xVel=0;
char.yVel=0;

stage.addEventListener(Event.ENTER_FRAME,EnterFrame);
function EnterFrame(e:Event){


    //local points
    top_left_point_local = new Point(char.top_left.x,char.top_left.y);
    bottom_left_point_local = new Point(char.bottom_left.x,char.bottom_left.y);

    top_right_point_local = new Point(char.top_right.x,char.top_right.y);
    bottom_right_point_local = new Point(char.bottom_right.x,char.bottom_right.y);

    //global points
    top_left_point = new Point(char.localToGlobal(top_left_point_local).x,char.localToGlobal(top_left_point_local).y);
    bottom_left_point = new Point(char.localToGlobal(bottom_left_point_local).x,char.localToGlobal(bottom_left_point_local).y);

    top_right_point = new Point(char.localToGlobal(top_right_point_local).x,char.localToGlobal(top_right_point_local).y);
    bottom_right_point = new Point(char.localToGlobal(bottom_right_point_local).x,char.localToGlobal(bottom_right_point_local).y);


    if(ground.hitTestPoint(top_left_point.x,top_left_point.y,true)){
        char.leftBumping=true;
    }
    if(ground.hitTestPoint(bottom_left_point.x,bottom_left_point.y,true)){
        char.leftBumping=true;
    }


    if(!ground.hitTestPoint(top_left_point.x,top_left_point.y,true)&&!ground.hitTestPoint(bottom_left_point.x,bottom_left_point.y,true)){
        char.leftBumping=false;
    }


    if(ground.hitTestPoint(top_right_point.x,top_right_point.y,true)){
        char.rightBumping=true;
    }
    if(ground.hitTestPoint(bottom_right_point.x,bottom_right_point.y,true)){
        char.rightBumping=true;
    }
    if(!ground.hitTestPoint(top_right_point.x,top_right_point.y,true)&&!ground.hitTestPoint(bottom_right_point.x,bottom_right_point.y,true)){
        char.rightBumping=false;
    }

    if(char.rightBumping){
        if(char.xVel>0){
            char.xVel=0;
            char.speed=0;
        }
    }
    if(char.leftBumping){
        if(char.xVel<0){
            char.xVel=0;
            char.speed=0;
        }
    }


    char.x+=char.xVel;
    char.y+=char.yVel;

}

还有其他人遇到过这个问题吗?任何帮助都将不胜感激。

更新:

这是问题的核心,由于某种原因,即使角色站着不动(左没有被按压),打左墙的角色在这里也是真实的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-22 22:39:06

嗯,经过几个小时的折磨,我终于解决了这个问题。电影的内部定位决定了它的整体位置。我从来不知道。我一直认为电影的内部与电影中心的位置无关。吸取的教训,总是把电影的内部集中到mc的舞台上来简化事情。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25954123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档