A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] [Help]Getting bullet to disappear when it hits something and reappear later

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

    [RESOLVED] [Help]Getting bullet to disappear when it hits something and reappear later

    Hi, I need help with my game. First of all, I use Flash MX 2004 and ActionScript 2.0. The game I am making is Asteroids USING CLASSES. I have the ship moving and the asteroids moving, the ship firing the bullets in the direction the ship is facing, and the asteroids getting removed and smaller ones attaching when my bullet hits the asteroid. I have a problem though. The bullet doesn’t remove when it hits the asteroid so it has the ability to hit the first asteroid, then destroy both smaller ones when they appear as it goes right through the first and keeps on going. I would like the bullet to be placed somewhere off the stage and stop moving until I shoot that same bullet again. You should know that my bullets are in an array (as well as my asteroids) and that the speed is constantly being added to the x and y of the bullet so they never stop moving (which makes sense). I would appreciate help on this matter as I have tried many times to fix this with no success. I’ve tried making a check to see if the bullet hits the asteroid then not allowing the bullet to move unless the check is false, as well as making a check to not allow the bullet to move until the spacebar is pressed again but nothing works. If you need my .fla file or my .as files just ask and I will post them. Hope I can get some help.

    smart_guy07

  2. #2
    Death to anime
    Join Date
    Mar 2006
    Location
    Holland, MI
    Posts
    32
    Why do you want to move the bullets off screen and then back on, can't you just use attachMovie? If you used that, you could simply removeMovieClip() and splice from the array. An fla might be helpful.
    Code:
    onClipEvent(load){
    trace("I am a geek")
    }

  3. #3
    Senior Member barrax's Avatar
    Join Date
    Jun 2000
    Location
    Southampton, UK
    Posts
    113
    while your bullet is flying i guess youre looping through an array of asteroids to see if it hits one. If it does then just break or return out of the loop and call the hitAsteroid function to initialise the explosion/splitting of the roid.

  4. #4
    Junior Member
    Join Date
    May 2006
    Posts
    2
    Ok, while at school today, with the help of a friend, we fixed the problem and now it works great. I just changed my bullets from an array to seperate movie clips and attached movie clips when I clicked spacebar. I have a variable to name them that would go up every time I pressed space, and then when it got to a certain number it would return to 0 and replace the existing movie clips. Now when they hit an asteroid they remove and another bullet will attach later when that bullet number is called. Thanks for the input anyways!

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