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 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