I'm creating simple flash game. I have problem, animation loop forever after I user gotoAndStop() and I have lag when during animation if character have collision with ground or any stage (if character flying on the air don't have any lags)
Here is collision list:
var myCollisionList:CollisionList = new CollisionList(Hero);
myCollisionList.addItem(ground);
myCollisionList.addItem(ground3);
myCollisionList.addItem(ground5);
myCollisionList.addItem(ground4);
And here is my part of code where jumping with animation.
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;
}
}
}
UPDATE: Screenshot of the map:
UPDATE 2:
Here is part of code for move character to left (to right side the same) side, I know Its terrible, but I don't know how to make It better.
pakopos - name of CollisionList
fonas - background
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;
}}