public void SetState(string key, bool value) { if (!value && AnimationStates.Contains(key)) { AnimationStates = AnimationStates.Where(each => each != key).ToArray(); } else if (value && !AnimationStates.Contains(key)) { AnimationStates = AnimationStates.Add(key); } GetAnimator().SetBool(key, value); }
public void SetState(string key, float value) { if (value == 0 && AnimationStates.Contains(key)) { AnimationStates = AnimationStates.Where(each => each != key).ToArray(); } else if (value != 0 && !AnimationStates.Contains(key)) { AnimationStates = AnimationStates.Add(key); } GetAnimator().SetFloat(key, value); }
//Todo encapsulate this further down as components -- AnimatedSpriteState, AnimatedSpriteStateDirection public void LoadSprites(AnimationCollection collection, IResourceManager resourceManager) { float x = 0, y = 0, h = 0, w = 0; int t = 0; foreach (var info in collection.Animations) { _sprites.Add(info.Name, new Dictionary <Direction, SFML.Graphics.Sprite[]>()); //Because we have a shitload of frames, we're going to store the average size as the AABB for each direction and each animation _averageAABBs.Add(info.Name, new Dictionary <Direction, FloatRect>()); var sprites = _sprites[info.Name]; var averageAABBs = _averageAABBs[info.Name]; AnimationStates.Add(info.Name, new AnimationState(info)); foreach (var dir in Enum.GetValues(typeof(Direction)).Cast <Direction>()) { sprites.Add(dir, new SFML.Graphics.Sprite[info.Frames]); var thisDirSprites = sprites[dir]; for (var i = 0; i < info.Frames; i++) { var spritename = collection.Name.ToLowerInvariant() + "_" + info.Name.ToLowerInvariant() + "_" + DirectionToUriComponent(dir) + "_" + i; thisDirSprites[i] = resourceManager.GetSprite(spritename); var bounds = thisDirSprites[i].GetLocalBounds(); x += bounds.Left; y += bounds.Top; w += bounds.Width; h += bounds.Height; t++; } averageAABBs.Add(dir, new FloatRect(x / t, y / t, w / t, h / t)); t = 0; x = 0; y = 0; w = 0; h = 0; } } }