A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [MX] Bullet/Laser Problem

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    391

    [MX] Bullet/Laser Problem

    I just want to do the simple press space and he shoots bullets thing. I have always done it where the codes will be in the guy and bullet movieclips. I recently learned to write codes on the main timeline. Right now the problem is when I press space, the visual bullet appears but it doesn't move up.
    PHP Code:
    bulletcounter=1;
    player_bullet._visible=false;
    player_bullet._x=player._x;
    player_bullet._y=player._y;
    bullet_speed=5;
    onEnterFrame = function() {
        
    player_bullet._y-=bullet_speed;
        if (
    key.isdown(key.space)) {
            
    bulletcounter++;
            
    player_bullet.duplicateMovieClip("bullet"+bulletcounterbulletcounter);
            [
    "bullet"+bulletcounter]._visible=true;
        }

    The guy is called guy. The bullet is called player_bullet.

  2. #2
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    you'll need a little more code than that. We'll make another function for the bullet, an onEnterFrame, that will move the bullet and then remove it when it goes off stage so that it doesn't eat up precious processor power.

    PHP Code:
    onEnterFrame = function() {
        
    player_bullet._y-=bullet_speed;
        if (
    key.isdown(key.space)) {
            
    bulletcounter++;
            
    bar bull:MovieClip player_bullet.duplicateMovieClip("bullet"+bulletcounterbulletcounter);
            
    bull._visible=true;
            
    bull.onEnterFrame FIRE;
        }

    function 
    FIRE(){
        
    this._y -= bullet_speed;
        if(
    this._y <= -50){
            
    this.removeMovieClip();
            
    delete this.onEnterFrame;
        }

    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

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