Results 1 to 6 of 6

Thread: AS3 HitTest

  1. #1

    Fla Script AS3 HitTest

    Can someone please explain to me how to hitTest multiple objects which are all from the same movieclip. In this case bullets.
    I know that the hitTest always effects the newest bullet created, but I don't now how to make it effect the "old" bullets aswell. I heard you have to use arrays, but I know nothing about them Plus all the tutorials I find about this are for AS2.

    So I would be truely greatful if someone gives me an example from how make an array for the bullets correctly to hitTesting, or give me a link to a tutorial.

    Thanks in advance

  2. #2
    131
    posts
    Registered User
    Quote Originally Posted by BenP321 View Post
    Can someone please explain to me how to hitTest multiple objects which are all from the same movieclip. In this case bullets.
    I know that the hitTest always effects the newest bullet created, but I don't now how to make it effect the "old" bullets aswell. I heard you have to use arrays, but I know nothing about them Plus all the tutorials I find about this are for AS2.

    So I would be truely greatful if someone gives me an example from how make an array for the bullets correctly to hitTesting, or give me a link to a tutorial.

    Thanks in advance
    Ill try. It might be too big so i might have to send it through email.

  3. #3
    ...it should be that big

    alright what you do is you create a function that pushes newly created bullets's (name all different but systematically ie bul_1, bul_2) then when the bullet leaves the stage take it out of the array, or when it gets blown up. then in a ENTER_FRAME event, you loop thur the array and check hit test for each bullet, this way if you have a fast gun and stuff there should only be like 10 hittest a frame, this method is very easy to implement and very functional

  4. #4
    Quote Originally Posted by ajcates View Post
    ...it should be that big

    alright what you do is you create a function that pushes newly created bullets's (name all different but systematically ie bul_1, bul_2) then when the bullet leaves the stage take it out of the array, or when it gets blown up. then in a ENTER_FRAME event, you loop thur the array and check hit test for each bullet, this way if you have a fast gun and stuff there should only be like 10 hittest a frame, this method is very easy to implement and very functional
    Firstly, how do you make the bullet names automaticly create a number after their name systematic 1,2,3,4....
    Secondly, how do you hitTest an array, is it like so:
    (bullets is an array in the GameEngine package)
    (This if statement is also in the Enemy01 package)
    if (this.hitTestObject(GameEngine.bullets[bullet01]))
    {
    trace("ouch")
    }

  5. #5
    Don't worry, someone on another forum gave me the code that I needed to figure it out:

    var bulletArray:Array = new Array();
    var bullet = new bullet();
    bulletArray.push(bullet);
    ...
    for(var i=0; i<bulletArray.length; i++) {
    if(someThing.hitTestObject(bulletArray[i ]) {
    //do something;
    }
    }

    Thank you ajcates and Enix591 anyway.

  6. #6
    ok i had code that systematically named objects, i lost it tho, if i find it ill post it. but till then that code will work great

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