I tried to make some bullets(actually swords/daggers) using FTP FlxWeapon, but some unexpected results was given. This is how I set up the FlxWeapon:
sword = new BasicSword("Sword", player, "x", "y");
sword.makeImageBullet(15, BasicSword.SWORD_GIF,5);
sword.setBulletDirection(FlxWeapon.BULLET_RIGHT, 400);
sword.setPreFireCallback(bulletDirectionCallback);
//load FlxControl
if(FlxG.getPlugin(FlxControl) == null){
FlxG.addPlugin(new FlxControl);
}
FlxControl.player1.setFireButton("X", FlxControlHandler.KEYMODE_PRESSED, 100, sword.fire);
}
/*A callback function, to set a proper direction before we fire the sword*/
public function bulletDirectionCallback():void{
if(player.facing == FlxObject.RIGHT){
sword.setBulletDirection(0, 400); //make the bullet move to the right side with velocity of 400.
}
else{ //if player is facing the left direction.
sword.setBulletDirection(180, 400); //make the bullet move to the left side with the velocity of 400.
}
}
Important notes:
BasicSword.as extends Sword.as and Sword.as extends FlxWeapon.
There's nothing important in BasicSword & Sword , actually Sword has only the constructer and BasicSword has only SWORD_GIF.
-What I think is working:
1-The callback function.
2-some methods and variables, like: setFireRate() and bulletsFired.
3-The fire button(FlxControl.player1.setFireButton).
-What is not working:
1-The sword is not showing up.
I solved my bug by putting this code
FlxG.worldBounds.make(0,0,level.width, level.height);
after the level is loaded itself because earlier(when I had the bug) I put this code after creating the level object BUT before loading it. so the value oflevel.width
andlevel.height
was 0 and 0.