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