public static NYDIAnimationFrame MakeFrame(JObject json) { NYDIAnimationFrame frame = new NYDIAnimationFrame(); float randomTimeMin = Funcs.jsonGetFloat(json["randomTimeMin"], -1); float randomTimeMax = Funcs.jsonGetFloat(json["randomTimeMax"], -1); float time = Funcs.jsonGetFloat(json["time"], -1); string sprite = Funcs.jsonGetString(json["sprite"], null); frame.sprite = sprite; if (sprite != null && randomTimeMin > 0 && randomTimeMax > 0) { frame.randomTime = true; frame.randomTimeMin = randomTimeMin; frame.randomTimeMax = randomTimeMax; frame.time = 0; } else if (sprite != null && time > 0) { frame.randomTime = false; frame.randomTimeMin = 0; frame.randomTimeMax = 0; frame.time = time; } else { frame = null; } return(frame); }
public bool Set(string name) { if (name == null) { currentAnimation = null; active = false; return(true); } if (animations.ContainsKey(name)) { //if (currentAnimation == null || (currentAnimation != null && currentAnimation.name != name)) { active = true; currentAnimation = animations[name]; index = 0; currentFrame = currentAnimation.frames[index]; currentSprite = currentFrame.sprite; timer = currentFrame.Time; running = true; changed = true; //} return(true); } running = false; currentAnimation = null; active = false; return(false); }
private static void CreateEntityPrototype(JObject json) { Entity proto = new Entity(); proto.name = "prototype"; proto.typeName = Funcs.jsonGetString(json["name"], null); proto.spriteName = Funcs.jsonGetString(json["spriteName"], null); proto.OnUpdate = Funcs.jsonGetString(json["onUpdate"], null); proto.facingSprites = new Dictionary <string, string>(); proto.facingSprites[World.NORTH] = Funcs.jsonGetString(json["spriteNorth"], proto.spriteName); proto.facingSprites[World.EAST] = Funcs.jsonGetString(json["spriteEast"], proto.spriteName); proto.facingSprites[World.SOUTH] = Funcs.jsonGetString(json["spriteSouth"], proto.spriteName); proto.facingSprites[World.WEST] = Funcs.jsonGetString(json["spriteWest"], proto.spriteName); proto.info = new ItemParameters(); float mv = Funcs.jsonGetFloat(json["movement_speed"], 4); proto.info.SetFloat("movement_speed", mv); proto.getNameType = Funcs.jsonGetString(json["getName"], "human"); proto.animations = new Dictionary <string, NYDIAnimation>(); JArray animations = Funcs.jsonGetArray(json, "animations"); if (animations != null) { foreach (JObject anim in animations) { NYDIAnimation animation = new NYDIAnimation(); animation.name = Funcs.jsonGetString(anim["name"], null); JArray frames = Funcs.jsonGetArray(anim, "frames"); List <NYDIAnimationFrame> animFrames = new List <NYDIAnimationFrame>(); if (frames != null) { foreach (JObject frame in frames) { //NYDIAnimationFrame frm = new NYDIAnimationFrame(); //frm.sprite = Funcs.jsonGetString(frame["sprite"], null); //frm.time = Funcs.jsonGetFloat(frame["time"], 0); animFrames.Add(NYDIAnimationFrame.MakeFrame(frame)); } } animation.frames = animFrames.ToArray(); proto.animations[animation.name] = animation; } } prototypes.Add(proto.typeName, proto); }
public void Update(float deltaTime) { changed = false; if (currentAnimation != null) { running = true; changed = true; if (currentFrame == null) { index = 0; currentFrame = currentAnimation.frames[index]; timer = currentFrame.Time; currentSprite = currentFrame.sprite; } timer -= deltaTime; if (timer <= 0) { index = (index + 1) % currentAnimation.frames.Length; currentFrame = currentAnimation.frames[index]; currentSprite = currentFrame.sprite; timer = currentFrame.Time; changed = true; } } else { currentSprite = null; running = false; changed = true; active = false; } }