Author Topic: Bullets not spawning when player leaves area  (Read 848 times)

caladan21ph

  • Member
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Hi! I'm having the problem that when the player leaves a certain area of the map bullets stop spawning. I'm using Flxweapon from the photonstorm plugin. What could be the cause of this problem? Heres the code for my player class. Thanks!

{
   import org.flixel.*;
   import org.flixel.plugin.photonstorm.*;
   import org.flixel.plugin.photonstorm.FlxControl;
   /**
    * ...
    * @author
    */
   public class Player extends FlxSprite
   {
      
      public var weapon:FlxWeapon;
      
      
      public function Player(X:Number,Y:Number):void
      {
         super(X, Y);
         loadRotatedGraphic(GFX.playerPNG, 360, -1, true,true);
         elasticity = 1;
         
         
         
         weapon = new FlxWeapon("lazer", this, "x", "y");
         weapon.makeImageBullet(40, GFX.bulletImage, 8, 2, true, 360, -1, true, true);
         weapon.setBulletSpeed(200);
         
         
         
         
         
         
         
         if (FlxG.getPlugin(FlxControl) == null)
         {
            FlxG.addPlugin(new FlxControl);
         }
         
         FlxControl.create(this, FlxControlHandler.MOVEMENT_INSTANT, FlxControlHandler.STOPPING_INSTANT,1,false,true);
         FlxControl.player1.setRotationKeys(true, false);
         FlxControl.player1.setRotationSpeed(400, 400, 200,400);
         FlxControl.player1.setThrust("UP", 200);
         FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 250, weapon.fireFromParentAngle);
         
         
         
         
      }
      
   }

}
Check out my game journal: http://alternatdev.wordpress.com

pWEN

  • Cicadomorph
  • Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
    • Portfolio
Re: Bullets not spawning when player leaves area
« Reply #1 on: Mon, Mar 5, 2012 »
test84 just helped me with this issue, actually. Try adding bounds for your bullets.

Code: [Select]
weapon.setBulletBounds(new FlxRect(0, 0, 4000, 4000));   //change 4000x4000 to whatever your level's width/height is

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Bullets not spawning when player leaves area
« Reply #2 on: Mon, Mar 5, 2012 »
call this on your weapon:
setBulletBounds(new FlxRect(0, 0, 4000, 4000));
blog, twitter, Check out my award winning game, Rot Gut: