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


下面是与问题相关的脚本:
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;
}还有其他人遇到过这个问题吗?任何帮助都将不胜感激。
更新:
这是问题的核心,由于某种原因,即使角色站着不动(左没有被按压),打左墙的角色在这里也是真实的。

发布于 2014-09-22 22:39:06
嗯,经过几个小时的折磨,我终于解决了这个问题。电影的内部定位决定了它的整体位置。我从来不知道。我一直认为电影的内部与电影中心的位置无关。吸取的教训,总是把电影的内部集中到mc的舞台上来简化事情。
https://stackoverflow.com/questions/25954123
复制相似问题