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

Thread: I need help programming bullets!

  1. #1

    I need help programming bullets!

    Below is skeleton code for bullets/various other things that are created in multiples

    Code:
    var i:Number = 0;
    var goTime:Boolean = true;
    
    function newThingy(){
    	if(goTime == true){
    		attachMovie("thingy", "thingy" +i, i);
    		thingy = _root["thingy" +i];
    		thingy._x = 100;
    		thingy._y = 200;
    		goTime = false;
    		i++;
    	}
    	thingy._x += 5;
    	if(thingy._x > 550){
    		removeMovieClip(this);
    	}
    }
    function timer(){
    	goTime = true;
    }
    
    setInterval(timer, 500);
    this.onEnterFrame = function(){
    	newThingy();
    }
    Ok, so whenever I run this code, the "thingy" that was created last stops wherever it is when the next "thingy" is created. How do I make them behave like I want them to, and go all the way to the end of the screen?

  2. #2
    this is AS2 yes?
    Basically what you want to do is have a copy of the bullet off screen which you duplicate to make new bullets.

    An example of how to do this: (the attached file)
    I made this ages ago so its not exactly the most clearly written code, PM if you have any further questions.

    Hope this helps.
    Attached Files Attached Files

  3. #3
    It works beautifully! Thanks a ton

  4. #4
    207
    posts
    Registered User
    The crucial point isn't whether you use attachMovie or duplicateMovie. The crucial point is that there is one and only one thingy.
    Consider this:

    Code:
    function newThingy(){
    if(goTime == true){
    attachMovie("thingy", "thingy" +i, i);
    thingy = _root["thingy" +i];
    thingy._x = 100;
    thingy._y = 200;
    goTime = false;
    i++;
    thingy.onEnterFrame= function () {
    this._x += 5;
    if(this._x > 550){
    removeMovieClip(this);
    }
    
    }
    }
    }


    Another solution would be to push thingy to an array, and then every frame, you would loop through the array and move each item in the array.
    Last edited by rrh; July 2nd, 2008 at 02:44 PM.

  5. #5
    If you don't want to use arrays ( kind of slow in as2, i think ), and you're running an onenterframe for each thingy, just make sure you're attaching your thingies in a place where they're easy to get rid of. Example, your code "attachMovie" will attach the thingy to the _root if that's what the code's scope is. maybe have a container clip for your thingies...

    Code:
    _root.createEmptyMovieClip( "thingies", _root.getNextHighestDepth() );
    // Then, later...
    thingies.attachMovie( "thingy", "thingy" + i, i );
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  6. #6
    Thanks everyone! The code itself is working fine. Now I just have to figure out why it's not firing properly

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