Search code examples
actionscript-3flashactionscriptstage

Action Script 3. Multiple stages are like 1


I'm creating a simple flash game, where characters move on the groundwith some stages to jump over.

The problem is all the stages are acting as 1 object, which can make the character appear like it's flying in the air:

on air

All stages are called: ground3 Here is part of code where the character jumps and stay on the ground:

if(Hero.y_speed>0 && Hero.hitTestObject(ground3)){
    Hero.y_speed=0;
    if(space){
        trace("You clicked SPACE");
        Hero.y -= 80;
    }

Have you any ideas how to fix this?


Solution

  • Use external libraries for your purposes, like this one.

    Here is described, how to use it (you can find there also other useful informations).

    import com.coreyoneil.collision.CollisionList;
    
    var myCollisionList:CollisionList = new CollisionList(hero);
    
    //add all stages separately
    myCollisionList.addItem(stage[1...n]);
    
    if(myCollisionList.checkCollisions().length > 0) {
         //colision detected
    }