Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: hitTest on duplicated MovieClips

  1. #1
    3
    posts
    Registered User

    hitTest on duplicated MovieClips

    In my as2 game i have an enemy on stage called "Enemy0", my script duplicates this enemys' actions and spawns a var number of enemies called "Enemy". However when i play the game my "Enemy0" hits the wall I made while my "Enemy" ignores the hitTest and goes through it.

    How do i make it so that my "Enemy0" and my duplicated enemy, "Enemy", hit the wall? I can upload my flash or show my code if need be.

    Plz help and thanks in advance for any help.
    Last edited by Acon; May 1st, 2012 at 11:47 AM.

  2. #2
    3
    posts
    Registered User
    Plz help me.

    this problem is driving me insane

  3. #3
    you need to post your code

    you have a scope issue

  4. #4
    3
    posts
    Registered User
    the following code is to copy my "enemy0";

    var nrEnemies = 2;
    for(i=1; i<nrEnemies; i++)
    {
    _root.Enemy0.duplicateMovieClip("Enemy" +i, _root.getNextHighestDepth());
    }

    the following is my code for my "enemy0"

    onClipEvent(load)
    {
    function reset()
    {
    var timer = 12;
    this._y = Math.random() * 300
    this._x = 1000
    mySpeed = Math.ceil(Math.random() * 6) + 6;
    }
    reset();
    }

    onClipEvent(enterFrame)
    {
    //in every frame the enemy move left in the speed defined in the reset function.
    this._x -= mySpeed;
    if (this._x < -10)
    {
    //if the enemy is not on the screen, we reset it.
    reset();
    }
    //if our timer is bigger than 12 we get a new
    if (timer >= 12)
    {
    //direction to the Ship.
    var dir = Math.ceil(Math.random() * 2)
    //We get a random number, 1 or 2. 1 is up, 2 is down.
    //Then we set timer to 0, so we only get a new dir when timer is bigger than 12
    timer = 0;
    }
    if (dir == 1)
    {
    //if dir = 1, we move the ship up.
    this._y -= 3;
    } else if(dir == 2)
    {
    //if dir = 2, we move the ship down.
    this._y += 3;
    }
    //increase timer by 1, so the timer gets equal to 12 and we get a new direction.
    timer++
    }

    onClipEvent(enterFrame)
    {
    if (_root.lives <= 0)
    {
    this.removeMovieClip();
    }
    }

    and the following is the code for my wall

    onClipEvent(enterFrame)
    {
    if(this.hitTest(_root.Ship))
    {
    _root.Ship._y += 10;
    }
    }

    onClipEvent(enterFrame)
    {
    if(this.hitTest(_root.Enemy0))
    {
    _root.Enemy0._y += 10;
    }
    }

  5. #5
    Hi..
    need some help in flash
    in as2
    i want to play movie clips as per the time
    ex .
    1mc = 9.00 to 11.00
    2mc = 12.00 to 16.00


    and so..




    plzzzzz
    i hav written some code this not working prpoerly


    some help would be gr8 for me thks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012