我正在创建简单的 Flash 游戏。我有问题,在我使用 gotoAndStop() 之后动画永远循环,并且在动画过程中如果角色与地面或任何舞台发生碰撞(如果在空中飞行的角色没有任何滞后),我会出现滞后
这是碰撞列表:
var myCollisionList:CollisionList = new CollisionList(Hero);
myCollisionList.addItem(ground);
myCollisionList.addItem(ground3);
myCollisionList.addItem(ground5);
myCollisionList.addItem(ground4);
这是我用动画跳跃的代码部分。
if(Hero.y_speed>0 && myCollisionList.checkCollisions().length > 0 )
{
Hero.y_speed=0;
Hero.x_speed=0;
if(space)
{
if (ground.hitTestPoint(Hero.x + 28, Hero.y+20, true))
{
Hero.gotoAndStop("attack");
stop();
Hero.y_speed = -20;
}
}
}
更新: 地图截图:
更新 2:
这是将字符移动到左侧(右侧相同)的部分代码,我知道它很糟糕,但我不知道如何让它变得更好。
pakopos - CollisionList 的名称
fonas - 背景
var pakopos:CollisionList = new CollisionList(Hero);
pakopos.addItem(ground);
pakopos.addItem(ground3);
pakopos.addItem(ground5);
pakopos.addItem(ground4);
if(left){
Hero.x_speed = -walkspeed;
setDirection(1);
if(pakopos.checkCollisions().length > 0) {
if (ground5.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
trace("Touching left side - ground5");
ground5.x += 0;
ground4.x += 0;
ground3.x += 0;
fonas.x += 0;
Enemy.x += 0;
}
else if (Enemy.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
trace("Touching Enemy");
ground5.x += 0;
ground4.x += 0;
ground3.x += 0;
fonas.x += 0;
Enemy.x += 0;
}
else if (ground3.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
trace("Touching left side - ground3");
ground5.x += 0;
ground4.x += 0;
ground3.x += 0;
fonas.x += 0;
Enemy.x += 0;
}
else if (ground4.hitTestPoint(Hero.x - 26, Hero.y-120, true)) {
trace("Touching left side - ground4");
ground5.x += 0;
ground4.x += 0;
ground3.x += 0;
fonas.x += 0;
Enemy.x += 0;
}else
{
Hero.x_speed = 0;
ground5.x += 4;
ground4.x += 4;
ground3.x += 4;
fonas.x += 4;
Enemy.x += 4;
}}
else {
ground5.x += 4;
ground4.x += 4;
ground3.x += 4;
fonas.x += 4;
Enemy.x += 4;
}}