The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 8 of 8

Thread: Very simple question? hitTest()

  1. #1

    Problems.....please try and help!! (i need help fast)

    1)I have a animated mc, and i want it to react only when a particular area of it has been hit. How to achieve this? (I have solved this one)

    2)How do i check collision for a dynamically attached mc?? I also need to check, which parent mc, that mc is a instance of....

    3)How do i change the depth of a mc?

    4)i am generating movieclips with random speed, but sometimes, the speed becomes the same, and thus two clips overlap, how do i prevent this?
    Last edited by bluemagica; May 2nd, 2008 at 12:29 PM.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  2. #2
    207
    posts
    Registered User
    2) Same as for regular mc. I don't see what the problem is. as2: ??? / as3: if (frank is Number)
    3) as2: swapdepth / as3:addChildAt

  3. #3
    well, rrh, in normal scenario i can do mc1.hitTest(mc2), but in this case i dont exactly know the name of mc2, it can be anything, mc2_45 , mc2_1000. and if i run a for loop, it will make things very slow, since the collision will have to check values that changes very fast, and a long for loop might miss this check..... And how do i know from what actual movieclip is this child attached? means if i collide with mc2_1000, how do i check that is belongs to mc2?

    I want only as2 answers, anyway, swapDepths is used to swap depth with a target mc, but in this case, as stated earlier, i dont exactly know the name of the other clips, so how do i change the depth of a mc?
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  4. #4
    with the depth are you talking bout the depth when duplicating movie clips?

  5. #5
    umm....yes that is the depth, but i am talking of it not only when duplicating, but at all times....
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  6. #6
    for (var i:Number = 0; i<5; i++) {
    _root.attachMovie("thingy","thingy"+i,getNextHighestDepth(),{_x:Math.random()*Stage.width, _y:Math.random()*Stage.height});
    _root["thingy"+i].onEnterFrame = function():Void {
    if (this.hitTest(_root.mc1)) {
    trace("Hitting "+this);
    }
    };
    }


    This any help? just wrote it up on here so something might be wrong, but pretty sure it's fine. If you're hittesting two attached movieclips then it gets a little more complicated.
    Last edited by Mr beef; May 3rd, 2008 at 06:27 AM.

  7. #7
    yes both are attached, and i cant know there name exactly, cause as i said, there can be over hundred instances, and it wont be always 0<i<100 cause instances will be destroyed.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  8. #8
    Quote Originally Posted by bluemagica View Post
    1)I have a animated mc, and i want it to react only when a particular area of it has been hit. How to achieve this? (I have solved this one)

    2)How do i check collision for a dynamically attached mc?? I also need to check, which parent mc, that mc is a instance of....

    3)How do i change the depth of a mc?

    4)i am generating movieclips with random speed, but sometimes, the speed becomes the same, and thus two clips overlap, how do i prevent this?
    2. If you've got arbitrary names on the clips, punch them into a array when you create them, if one is removed, shift the array *. If you need to check the collisions, just loop through it the array when doing the checks, I think you could improve performance if you put a 'range check' on that aswell, so that it only checks for collisions within a certain radius around the affected MovieClip.

    * = By shifting the array you'd be making the array smaller, saving CPU ticks when looping through it. If you just removed the clip, the array spot would be left, but with a null value.

    3.
    Code:
     MovieClip.swapDepth(instance / depth);

    4.
    I couldn't answer this without seeing the code used for generating the clips, and setting the speed.

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