Author Topic: FlxWeapon Problems  (Read 1130 times)

EtchMisfire

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
FlxWeapon Problems
« on: Wed, Dec 14, 2011 »
Slightly new to Flixel, still learnign the ropes. After some cursory searching Ic ould not find the answer to this quagmire I've gotten myself into. After creating an enemy character with its own finite state machine, I wanted to add a weapon. Using PhotonStorm's magnificent power tools, I have made a weapon in my playstate that is triggered by the enemy. The logic seems fine, and the game runs. However, my enemy doesn't shoot anything. I've checked to see if it has a problem entering the attack state, and the enemy doesn't seem to have any problems doing that, so I have deduced that there is something wrong with how I wrote the code in my playState.

In my create() function I have this:
Code: [Select]

                        SMG = new FlxWeapon("SMG", Registry.soldier, "x","y");
SMG.makePixelBullet(50, 5, 5, 0x000000);
SMG.setFireRate(100);
SMG.setBulletRandomFactor(0, 100, new FlxPoint(8, 8));


add(map);
add(SMG.group);
add(Registry.soldier);
add(Registry.player);

and in the update I have this:

Code: [Select]
             
                        super.update();

if (Registry.soldier.State == "Attack")
{
SMG.setBulletDirection(Registry.soldier.aimCalc, 300);
SMG.fire();
}

Any and all help in this matter would be greatly appreciated
-Etch

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: FlxWeapon Problems
« Reply #1 on: Wed, Dec 14, 2011 »
Your pixel bullet colour needs to be in the format 0xAARRGGBB - as it stands now it'd be invisible as it's missing the alpha section.

Try bright red (or white 0xFFFFFFFF) just to see if you can see anything.

If you still can't, check the bulletBounds setting in FlxWeapon. And throw a trace into the fire block to be sure it's firing (it if definitely is then remove the bullet direction call, just to see what happens)

If you've done all of the above and it still doesn't work then my next guess would be the bullets could be colliding with the player sprite / map before you get a chance to see them.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

EtchMisfire

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: FlxWeapon Problems
« Reply #2 on: Thu, Dec 15, 2011 »
Wow, it was the color. Thanks a lot Photonstorm. Out of curiosity, how do I change the point at which the bullets emanate? I've tried messing with the "x" and "y" string variable but they aren't accepting my variables.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: FlxWeapon Problems
« Reply #3 on: Thu, Dec 15, 2011 »
Use FlxWeapon.setParent() to lock it onto a parent object and set the offset etc.

The x/y vars it needs must be publicly accessible. So in your case if Registry.soldier is an FlxSprite then you can just use "x" and "y". It those vars aren't visible you'll need to expose them.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius