Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a platform game and I have trouble finding the right way to do the enemy collisions... I am a noob in as3 so I 'm gonna try to explain my situation! I have an enemy, movie clip, and I have written code for it to move right and left and whenever it finds bumps to stop and walk the other way. So far the first movie clip I made did exactly that. I then decided to make my enemy look better so I added 3 frames in his movieclip , those 3 frames are his steps as he walks and they are tweening movieclips inside the original movieclip. Now my enemy does not collide with the bumps and just keeps walking and goes off screen after a while! Any opinions on how to make it collide again while walking? ...thnx in advance!

code:

    // Player and enemy collisions
if (enemyList.length > 0){
    for (var m:int = 0; m < enemyList.length; m++){
    if ( player.hitTestObject(enemyList[m]) ){
            trace("Pl-En collision");
            enemyList[m].removeSelf();
        }
    }
}

//Enemy class
public class Enemy extends MovieClip
{
private var xSpeed:int = 2;
    private var turn:int = 1;

    public function Enemy(xLocation:int, yLocation:int)
    {
        x = xLocation;
        y = yLocation;

        addEventListener(Event.ENTER_FRAME, loop);
    }

    public function loop(e:Event):void {
        if ((turn%2) == 1){
            x += xSpeed;
        } else if((turn%2) == 0){
            x -= xSpeed;
        }
    }

    public function removeSelf():void {
        //trace("remove enemy");
        removeEventListener(Event.ENTER_FRAME, loop);
        this.parent.removeChild(this);
    }

}   

I 'm moving the movieclip with these lines:

     public function loop(e:Event):void {
        if ((turn%2) == 1){
            x += xSpeed;
        } else if((turn%2) == 0){
            x -= xSpeed;
        }

    }

I check player/enemy collision with:

    for (var m:int = 0; m < enemyList.length; m++){
if ( player.hitTestObject(enemyList[m]) ){
        trace("Pl-En collision");
        enemyList[m].removeSelf();
    }
}
share|improve this question
    
Are you sure you are moving the parent and not the local movie clip? –  Sidar May 23 '13 at 0:45
    
How do I see if I move the parent movie clip? :/ –  chrisil May 23 '13 at 1:12
    
Simply by code? You know exactly which clip you transform ( modifying the x and y properties ). –  Sidar May 23 '13 at 14:18
    
I don't "transform" per se my movie clip. It's just this : I have a movie clip attached to my class Enemy and inside the clip I have created 3 keyframes each of which has a different picture. Before I created those 3 keyframes inside my movieclip the enemy collided properly with the environment, after I added the "movement" it stopped colliding. And yes I am using the parent clip because all I do is change the x,y variables that I created in the enemy's constructor. –  chrisil May 23 '13 at 17:45
    
I meant translating, not transforming. There isn't really much anyone can see just from the description, can you add some as3 code? –  Sidar May 23 '13 at 18:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.