public void SkinBones(XElement skinsData) { foreach (KeyValuePair <string, IBone> kvp in Bones) { kvp.Value.ClearSkin(); } foreach (XElement skin in skinsData.Elements("bone")) { if (Bones.ContainsKey(skin.Attribute("id").Value)) { Vector2 origin = new Vector2((float)skin.Attribute("origin-x"), (float)skin.Attribute("origin-y")); Rectangle frame = new Rectangle((int)skin.Attribute("frame-x"), (int)skin.Attribute("frame-y"), (int)skin.Attribute("frame-width"), (int)skin.Attribute("frame-height")); Bones[skin.Attribute("id").Value].ApplySkin(skin.Attribute("texture-name").Value, origin, frame); if (skin.Element("tint") != null) { Bones[skin.Attribute("id").Value].MasterTint = new Color( (int)skin.Element("tint").Attribute("red"), (int)skin.Element("tint").Attribute("green"), (int)skin.Element("tint").Attribute("blue"), (int)skin.Element("tint").Attribute("alpha")); } } } }
public void SetSkinForBone(string boneID, string skinTextureName, Vector2 originWithinSkinFrame, Rectangle frameAreaWithinSkinTexture) { if (!Bones.ContainsKey(boneID)) { throw new Exception(string.Concat("Cannot apply skin to bone that does not exist! Bone ID: ", boneID)); } else { Bones[boneID].ApplySkin(skinTextureName, originWithinSkinFrame, frameAreaWithinSkinTexture); } }
private void AttemptToAddChildBone(IBone boneToAdd, string parentBoneID) { if (Bones.ContainsKey(boneToAdd.ID)) { throw new Exception(string.Concat("Bone IDs must be unique! ID: ", boneToAdd.ID)); } else if (!Bones.ContainsKey(parentBoneID)) { throw new Exception(string.Concat("Parent does not exist! Child ID: ", boneToAdd.ID, " expected parent ID: ", parentBoneID)); } else { SetBoneStandardValues(boneToAdd); boneToAdd.Parent = Bones[parentBoneID]; Bones.Add(boneToAdd.ID, boneToAdd); Bones[parentBoneID].Children.Add(boneToAdd); } }
public bool HasBone(string boneName) { return(Bones != null && Bones.ContainsKey(boneName)); }