Author Topic: 20 or more weapons animations  (Read 1702 times)


  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
20 or more weapons animations
« on: Thu, Jan 12, 2012 »
i want my game to have 20 or more weapons but i dont know how to do this.

i could have a class weapon extends from FlxSprite and inside that class have 20 FlxSprites with the png-sprite-animation of the weapons attack, and then call the animation with

Code: [Select]

this.currentWeapon = "sword_1";//in the construct

//then when the player change the weapon call this function
public function changeCurrentWeapon(weaponName:String):void{
    this.currentWeapon = weaponName;

public function attack():void{;

in the players class.

Thanks for reading.


  • happens to be a
  • Active Member
  • ***
  • Posts: 112
  • Karma: +0/-0
  • Howdy
    • View Profile
    • twitter
Re: 20 or more weapons animations
« Reply #1 on: Mon, Jan 16, 2012 »
I think that would work fine, I think you would have to make sure the weapon is positioned correctly relative to the player when attacking/not attacking....then when switching weapons just call loadGraphic() with the different weapon class to load the picture, change animations if necessary? I think what you have more or less should work fine, but maybe someone with more experience can weigh in.

making anodyne, a zelda-like (with flixel!)

Wing Eraser

  • Guest
Re: 20 or more weapons animations
« Reply #2 on: Thu, Jan 19, 2012 »
Wrong board? |-I

You can create all weapons in one FlxSprite, but you'll have to know it's a kinda messy. Doing if-else/case switch and setting the x,y correctly. If you add more weapons you'll have to write another line of code in the if-else statement. Or removing a weapon and to be sure nothing will break.

If you do extend for all the weapons. Inherit WeaponAbstract class. In the constructor create a parameter for x,y,img.
Use Factory Pattern. WeaponFactory class. WeaponFactory.createShotgun():return WeaponAbstract.

In WeaponAbstract you write the behavior: switchWeapon(), reload(), empty(), powerUp(), etc.
So in every weapon class, you can set the frame, width, height, for the different weapons. If there is unique thing in the weapon, you can override the methods in the parent class.

Anyway, that's how I approach.


  • Contributor
  • ****
  • Posts: 268
  • Karma: +0/-0
    • View Profile
Re: 20 or more weapons animations
« Reply #3 on: Thu, Jan 19, 2012 »
I'd do the same as Wing Eraser, except I'd forget about the factory class and make a mess just as well :-X Thanks for teaching me that! ;D


  • Aspiring Indie Game Developer, Prototype Musician, Lame Pixel Artist
  • Member
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
    • Need songs? :3
Re: 20 or more weapons animations
« Reply #4 on: Mon, Jan 30, 2012 »
Also Check out FlxWeapon on Flixel Power Tools plugin by Photonstorm :3

Makes your life WAAAAAAAY easier :D
Waiting is wasting