所以我不知道如何表达这个问题 - 如果有人有更好的想法,请随意:)
但本质上,我的横向卷轴的碰撞行为很奇怪。我_boundaries
在开始位置的左侧有一个“边框”框 ( ),以防止字符在开始时向左移动。以前,它工作正常(但是其他东西坏了)。在修复了许多其他碰撞问题(IE 从地板上掉下来、卡在地板上、重力表现异常)之后,左侧碰撞大部分时间都停止了工作。
如果您从超过 5-10 像素处撞到墙上,您将不会被阻挡/阻止移动,而是会“传送”到墙的顶部并继续前进。如果您接近 5-10 像素并开始移动,您将被阻挡。我已经为布局提供了一张图片(通过链接)。
但是如何修复我的横向卷轴代码,以便墙总是阻塞(没有一个可笑的巨大碰撞框/区域)。或者,有没有更好的方法来处理我所有的碰撞?
http://i.imgur.com/orvErfQ.png
碰撞代码:
private function processCollisions():void
{
//Respawn if fell off stage
if(_player.y > stage.stageHeight)
{
_player.x = _startMarker.x;
_player.y = _startMarker.y;
_boundaries.x = 0;
_boundaries.y = 0;
_vy = 0;
}
//Otherwise process collisions with boundaries
else
{
var testX = _player.x
var testY = _player.y - (_player.height / 2);
var vCollision:Boolean = false;
if(moveLeft){
testX -= horizMove;
if(_boundaries.hitTestPoint((testX - _player.width / 2), _player.y-5, true))
{
moveLeft = false;
trace("PING");
}
}
if(moveRight){
testX += horizMove;
if(_boundaries.hitTestPoint((testX + _player.width / 2), _player.y-5, true))
{
moveRight = false;
trace("PONG");
}
}
if(jump){
testY += vertMove;
if(_boundaries.hitTestPoint(_player.x, (testY - _player.height / 2), true))
{
jump = false;
trace("PANG");
}
}
//if(_vy > 0){
testY += _vy;
if(_boundaries.hitTestPoint(_player.x, (testY + _player.height / 2), true))
{
vCollision = true;
}
if(vCollision)
{
while(vCollision)
{
_player.y -= 0.1;
vCollision = false;
if(_boundaries.hitTestPoint(_player.x, _player.y, true))
{
vCollision = true;
}
}
_vy = 0;
}
}
movement();
}
运动代码:
private function movement():void
{
if(moveLeft)
{
_vx = -5;
faceLeft = true;
faceRight = false;
}
else if(moveRight)
{
_vx = 5;
faceLeft = false;
faceRight = true;
}
else if(jump)
{
//_player.y += vertMove;
_vy = -15;
}
}
它被使用的地方:
private function enterFrameHandler(e:Event):void
{
//Upon entering a frame;
//Gravitate Player
_vy += 1.75;
//Move Player
_player.x += _vx;
_player.y += _vy;
//Process Collisions for Player
processCollisions();
//Scroll map
scrollStage();
}