Weapon's sprite being held flips a bit too late [SOLVED]


(John Andersson) #1

I have a hero. He is holding a weapon he picked up from the ground (it can be any weapon). When he turns, the weapon turns too and changes position so that it is to the left of the hero instead of to the right (platformer).

The weapon flips juuust a bit after, so it looks like the weapon is far away from the hero then snaps back into position. This is because the hitbox is very wide, wider than the actual graphic.

Here is the code:

private var holdingWeapon:Weapons;

    blabla

   				if (weaponCollideSmallSword != null && holdingWeapon == null) holdingWeapon = weaponCollideSmallSword;
			if (weaponCollideMediumSword != null && holdingWeapon == null) holdingWeapon = weaponCollideMediumSword;

                               //Small
				if (holdingWeapon.name == "sword_small")
				{
					//Stamina
					HeroStats.staminaRegenWeaponType = 2;
					
					if (spritemap.flipped)
					{
						holdingWeapon.flipped = true;
						wepHotspotX = x - 80;
					}
					else holdingWeapon.flipped = false;
					
					holdingWeapon.x = wepHotspotX;
					holdingWeapon.y = wepHotspotY + 96;
				}
				
				//Medium
				if (holdingWeapon.name == "sword_medium")
				{
					HeroStats.staminaRegenWeaponType = 1;
					
					if (spritemap.flipped)
					{
						holdingWeapon.flipped = true;
						wepHotspotX = x - 96;
					}
					else holdingWeapon.flipped = false;
					
					holdingWeapon.x = wepHotspotX;
					holdingWeapon.y = wepHotspotY;
				}

And the weapons:

		//Flipped
		if (flipped)
			spritemap.flipped = true;
		else
			spritemap.flipped = false;

They extend base class Weapons.as which has a boolean “flipped”.

How should I go about doing this instead? I could use a command like:

 holdingWeapon.graphic.flipped = true;

But yeah… it doesn’t exist


(Jacob Albano) #2
Spritemap(holdingWeapon.graphic).flipped = true;

(John Andersson) #3

Thank you, it works perfectly. I know I have asked a lot of different questions lately which may seem really obvious to you, but it feels like these commands are hidden until someone tells me or I just magically enter it myself. Is there any good documentation site which has all of these “advanced” commands?


(Jacob Albano) #4

They’re not advanced commands. This is just casting. It’s not a Flashpunk feature, it’s a language element.

The Entity’s graphic property is of type Graphic, which doesn’t have a flipped property. In order for the compiler to accept your code, you need to force it to look at the graphic as a Spritemap.