A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [MX04] Collision detection between instances

Hybrid View

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    2

    [MX04] Collision detection between instances

    Help! I've been all over this site, and the forum, and I'm completely stuck. I don't normally ask for help but I'm getting a bit despirate now!

    I'm making a falling-block game, similar to connect four/four in a row, and I'm trying to figure out how to do collision detection between each of the boxes I'm using so that once one hits the block below it it stops. They're all instances of one movie clip (box_mc). Once a block has fallen, the player then controls the next block and so on (this bit works fine), so the code has to go in the actions layer.

    I'm not very good at Flash yet...so if someone could give me an idea on what I need to do for this, or a tutorial I can use (the one on here is very good, but confused me to no end and I couldn't get it working), I'll be very grateful!

    Thanks for looking.

    EDIT: this is what I'm trying;

    targetBox = _root["box"+_root.currentBox];
    multipleHit = function() {
    boxNum = targetBox.length;
    for (i=0; i>boxNum; i++) {
    _root["box"+_root.currentBox] = targetBox[i];
    for (j=0; j<targetBox; j++) {
    boxCollision = targetBox[j];
    _root["box"+_root.currentBox] = eval(_root["box"+_root.currentBox]);
    boxCollision = eval(boxCollision);
    if (_root["box"+_root.currentBox].hitTest(boxCollision)) {
    _root["box"+_root.currentBox].stop();
    Last edited by NekoMalik; 05-24-2007 at 05:43 AM.

  2. #2
    Style Through Simplicity alillm's Avatar
    Join Date
    Mar 2004
    Location
    Wales
    Posts
    1,988
    Your code doesn't really make sense.

    Code:
    targetBox = _root["box"+_root.currentBox];
    What is _root["box"+_root.currentBox] ? Is it an array or an instance of a movie clip because you are then trying to get its length with

    Code:
    boxNum = targetBox.length;
    Which doesn't make sense if its a movie clip.
    You are then using targetBox as a number which I assume it isn't

    Code:
    for (j=0; j<targetBox; j++) {
    It seems you have quite a few errors there. Could you please explain what you are trying to do?

    Ali

  3. #3
    Junior Member
    Join Date
    May 2007
    Posts
    2
    Sorry, that's just me trying to adapt current tutorials to my game, but without the necessary knowledge of Flash to do so.

    _root["box"+_root.currentBox] is the movie clip...I'm just not very good at this, sorry I just don't know what to try any more.

    so here's what I'm trying to do;

    user controls block (this works)
    block drops down grid (works too)
    hits base and stops (and this)
    user controls next block (yup)
    next block hits top of first block and stops (here's my problem)

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center