Exemplo n.º 1
0
        private void _queueAnimation(object[] args)
        { // queueAnimation(string partyMemberSelector, string animationName, [Script onStartCallback], [Script onFinishCallback])
            string partyMemberSelector = (string)args[0];
            string animationName       = (string)args[1];
            Script onStartCallback     = args.Length <= 2 ? null : (Script)args[2];
            Script onFinishCallback    = args.Length <= 3 ? null : (Script)args[3];

            PartyMember    partyMember    = getPartyMemberFromSelector(partyMemberSelector);
            AnimationState animationState = partyMember.BattleEntity.AnimationState;
            Animation      animation      = animationState.Data.SkeletonData.FindAnimation(animationName);

            if (animation == null)
            {
                throw new Exception("Animation '" + animationName + "' could not be found");
            }

            float animationStateTime        = animationState.Time;
            float timeToCurrentAnimationEnd = animationState.Animation.Duration - (animationStateTime % animationState.Animation.Duration);

            animationState.AddAnimation(animation, false, animationStateTime + timeToCurrentAnimationEnd);
            animationState.AddAnimation(partyMember.GetBattleEntityIdleAnimationName(), true);

            if (onStartCallback != null)
            {
                addNestedScriptRunner(onStartCallback, timeToCurrentAnimationEnd);
            }
            if (onFinishCallback != null)
            {
                addNestedScriptRunner(onFinishCallback, timeToCurrentAnimationEnd + animation.Duration);
            }
        }
Exemplo n.º 2
0
        public void AddAnimation(string animationName, Action animationEnded, float delay = 0,
                                 int trackIndex = 0)
        {
            TrackEntry entry = state.AddAnimation(trackIndex, animationName, false, delay);

            if (animationEnded != null)
            {
                entry.End += (sender, eventArgs) => animationEnded();
            }
        }
Exemplo n.º 3
0
        protected void LoadContent(GraphicsDevice gD)
        {
            graphics         = gD;
            skeletonRenderer = new SkeletonRenderer(gD);
            skeletonRenderer.PremultipliedAlpha = true;

            String name = "spineboy"; // "goblins";

            Atlas        atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(gD));
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json"));
            if (name == "goblins")
            {
                skeleton.SetSkin("goblingirl");
            }
            skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            // Define mixing between animations.
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            if (name == "spineboy")
            {
                stateData.SetMix("walk", "jump", 0.2f);
                stateData.SetMix("jump", "walk", 0.4f);
            }

            state = new AnimationState(stateData);

            if (false)
            {
                // Event handling for all animations.
                state.Start    += Start;
                state.End      += End;
                state.Complete += Complete;
                state.Event    += Event;

                state.SetAnimation(0, "drawOrder", true);
            }
            else
            {
                state.SetAnimation(0, "walk", false);
                TrackEntry entry = state.AddAnimation(0, "jump", false, 0);
                entry.End += new EventHandler <StartEndArgs>(End); // Event handling for queued animations.
                state.AddAnimation(0, "walk", true, 0);
            }

            skeleton.X = 600;
            skeleton.Y = 600;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Exemplo n.º 4
0
    /// <summary>
    /// 播放动画
    /// </summary>
    public float PlayQueue(string name, bool isLoop, float delay = 0, int layer = 1, float MixDuration = 0.2f)
    {
        if (Contains(name, true))
        {
            var track = AnimationState.AddAnimation(layer, name, isLoop, delay);
            track.MixDuration = MixDuration;
            track.timeScale   = 1;
            track.TrackTime   = 0;
            return(track.Animation.Duration);
        }

        return(0);
    }
Exemplo n.º 5
0
        private void _playAnimation(object[] args)
        { // playAnimation(string partyMemberSelector, string animationName, [Script onFinishCallback])
            string partyMemberSelector = (string)args[0];
            string animationName       = (string)args[1];
            Script onFinishCallback    = args.Length <= 2 ? null : (Script)args[2];

            PartyMember    partyMember    = getPartyMemberFromSelector(partyMemberSelector);
            AnimationState animationState = partyMember.BattleEntity.AnimationState;
            Animation      animation      = animationState.Data.SkeletonData.FindAnimation(animationName);

            if (animation == null)
            {
                throw new Exception("Animation '" + animationName + "' could not be found");
            }

            animationState.SetAnimation(animation, false);
            animationState.AddAnimation(partyMember.GetBattleEntityIdleAnimationName(), true);

            if (onFinishCallback != null)
            {
                addNestedScriptRunner(onFinishCallback, animation.Duration);
            }
        }
Exemplo n.º 6
0
        public Pack LoadSkeleton(string jsonFile, string atlasFile, string animation, string skin, float scale, float x, float y)
        {
            Atlas atlas = new Atlas(assetsFolder + atlasFile + ".atlas", new LoveTextureLoader());
            var   json  = new SkeletonJson(atlas);

            json.Scale = scale;
            var skeletonData = json.ReadSkeletonData(assetsFolder + jsonFile + ".json");
            var skeleton     = new Skeleton(skeletonData);

            skeleton.X      = x;
            skeleton.Y      = y;
            skeleton.ScaleY = -1;
            if (skin != null)
            {
                skeleton.SetSkin(skin);
            }
            skeleton.SetToSetupPose();
            var stateData = new AnimationStateData(skeletonData);
            var state     = new AnimationState(stateData);


            state.SetAnimation(0, animation, true);
            if (jsonFile == "spineboy-ess")
            {
                stateData.SetMix("walk", "jump", 0.5f);
                stateData.SetMix("jump", "run", 0.5f);
                state.AddAnimation(0, "jump", false, 3);
                state.AddAnimation(0, "run", true, 0);
            }

            if (jsonFile == "raptor-pro")
            {
                swirl.CenterY = -200;
                //skeleton.VertexEffect = swirl;
            }

            if (jsonFile == "mix-and-match-pro")
            {
                // Create a new skin, by mixing and matching other skins
                // that fit together. Items making up the girl are individual
                // skins. Using the skin API, a new skin is created which is
                // a combination of all these individual item skins.
                var lskin = new Skin("mix-and-match");
                lskin.AddSkin(skeletonData.FindSkin("skin-base"));
                lskin.AddSkin(skeletonData.FindSkin("nose/short"));
                lskin.AddSkin(skeletonData.FindSkin("eyelids/girly"));
                lskin.AddSkin(skeletonData.FindSkin("eyes/violet"));
                lskin.AddSkin(skeletonData.FindSkin("hair/brown"));
                lskin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange"));
                lskin.AddSkin(skeletonData.FindSkin("legs/pants-jeans"));
                lskin.AddSkin(skeletonData.FindSkin("accessories/bag"));
                lskin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow"));
                skeleton.SetSkin(lskin);
            }

            // set some event callbacks
            state.Start     += (entry) => Console.WriteLine(entry.TrackIndex + " start: " + entry.Animation.Name);
            state.Interrupt += (entry) => Console.WriteLine(entry.TrackIndex + " interrupt: " + entry.Animation.Name);
            state.End       += (entry) => Console.WriteLine(entry.TrackIndex + " end: " + entry.Animation.Name);
            state.Complete  += (entry) => Console.WriteLine(entry.TrackIndex + " complete: " + entry.Animation.Name);
            state.Dispose   += (entry) => Console.WriteLine(entry.TrackIndex + " dispose: " + entry.Animation.Name);
            state.Event     += (entry, e) => Console.WriteLine(
                entry.TrackIndex +
                " event: " +
                entry.Animation.Name +
                ", " +
                e.Data.Name +
                ", " +
                e.Int +
                ", " +
                e.Float +
                ", '" +
                e.String +
                "'" +
                ", " +
                e.Volume +
                ", " +
                e.Balance
                );

            state.Update(0.5f);
            state.Apply(skeleton);

            return(new Pack(skeleton, state));
        }
Exemplo n.º 7
0
        protected override void LoadContent()
        {
            // Two color tint effect, comment line 80 to disable
            var spineEffect = Content.Load <Effect>("Content\\SpineEffect");

            spineEffect.Parameters["World"].SetValue(Matrix.Identity);
            spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up));

            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = false;
            skeletonRenderer.Effect             = spineEffect;

            // String name = "spineboy-ess";
            // String name = "goblins-pro";
            // String name = "raptor-pro";
            // String name = "tank-pro";
            String name       = "raptor-pro";
            String atlasName  = name.Replace("-pro", "").Replace("-ess", "");
            bool   binaryData = false;

            Atlas atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice));

            float scale = 1;

            if (name == "spineboy-ess")
            {
                scale = 0.6f;
            }
            if (name == "raptor-pro")
            {
                scale = 0.5f;
            }
            if (name == "tank-pro")
            {
                scale = 0.3f;
            }
            if (name == "coin-pro")
            {
                scale = 1;
            }

            SkeletonData skeletonData;

            if (binaryData)
            {
                SkeletonBinary binary = new SkeletonBinary(atlas);
                binary.Scale = scale;
                skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel");
            }
            else
            {
                SkeletonJson json = new SkeletonJson(atlas);
                json.Scale   = scale;
                skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json");
            }
            skeleton = new Skeleton(skeletonData);
            if (name == "goblins-pro")
            {
                skeleton.SetSkin("goblin");
            }

            // Define mixing between animations.
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            if (name == "spineboy-ess")
            {
                stateData.SetMix("run", "jump", 0.2f);
                stateData.SetMix("jump", "run", 0.4f);

                // Event handling for all animations.
                state.Start    += Start;
                state.End      += End;
                state.Complete += Complete;
                state.Event    += Event;

                state.SetAnimation(0, "walk", false);
                TrackEntry entry = state.AddAnimation(0, "jump", false, 0);
                entry.End += End; // Event handling for queued animations.
                state.AddAnimation(0, "run", true, 0);
            }
            else if (name == "raptor-pro")
            {
                state.SetAnimation(0, "walk", true);
                state.AddAnimation(1, "gun-grab", false, 2);
            }
            else if (name == "coin-pro")
            {
                state.SetAnimation(0, "rotate", true);
            }
            else if (name == "tank-pro")
            {
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400 + (name == "tank-pro" ? 300 : 0);
            skeleton.Y = GraphicsDevice.Viewport.Height;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Exemplo n.º 8
0
        private void ParseObject(object o)
        {
            string s;

            Dictionary <string, FieldInfo> fields = new Dictionary <string, FieldInfo>();

            //get all class variables
            foreach (var prop in o.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                fields.Add(prop.Name, prop);
            }
            do
            {
                ParseLine();
                s = getString();
                if (o.GetType() == typeof(LoadSubsystem))
                {
                    LoadSubsystem ls = (LoadSubsystem)o;
                    switch (s)
                    {
                    case "InitFile":
                        ls.AddInitFile(getString());
                        break;

                    case "InitFileDebug":
                        ls.AddInitFileDebug(getString());
                        break;

                    case "InitPath":
                        ls.AddInitPath(getString());
                        break;

                    case "IncludePathCinematics":
                        ls.AddIncludePathCinematics(getString());
                        break;

                    case "ExcludePath":
                        ls.AddExcludePath(getString());
                        break;
                    }
                }
                else if (o.GetType() == typeof(AnimationState))
                {
                    AnimationState state = (AnimationState)o;
                    string         name;
                    switch (s)
                    {
                    case "Animation":
                        Animation anim = new Animation();
                        ParseObject(anim);
                        state.AddAnimation(anim);
                        break;

                    case "BeginScript":
                        string line = getLine();
                        while (!line.Equals("EndScript"))
                        {
                            state.AddScriptLine(line);
                            line = getLine();
                        }
                        break;

                    case "ParticleSysBone":
                        name = getString();
                        state.AddParticleSysBone(name, ParseParticleSysBone());
                        break;
                    }
                }
                else if (o.GetType() == typeof(Armor))
                {
                    Armor ar = (Armor)o;
                    switch (s)
                    {
                    case "Armor":
                        ar.AddType(getString(), getFloat());
                        break;
                    }
                }
                else if (o.GetType() == typeof(AudioEvent))
                {
                    AudioEvent ae = (AudioEvent)o;
                    switch (s)
                    {
                    case "Sounds":
                        string   val    = getStrings();
                        string[] sounds = val.Split(' ');
                        foreach (string sound in sounds)
                        {
                            MusicTrack mt;
                            if (INIManager.TryGetMusicTrack(sound, out mt))
                            {
                                ae.AddMusicTrack(mt);
                            }
                            //else
                            //    PrintError(" no such MusicTrack found: " + sound);
                        }
                        break;
                    }
                }
                else if (o.GetType() == typeof(Draw))
                {
                    Draw   dr = (Draw)o;
                    string name;
                    switch (s)
                    {
                    case "AnimationState":
                        AnimationState astate = new AnimationState();
                        name = getString();
                        ParseObject(astate);
                        dr.AddAnimationState(name, astate);
                        break;

                    case "DefaultModelConditionState":
                        ModelConditionState defMod = new ModelConditionState();
                        ParseObject(defMod);
                        dr.DefaultModelConditionState = defMod;
                        break;

                    case "IdleAnimationState":
                        AnimationState iastate = new AnimationState();
                        ParseObject(iastate);
                        dr.IdleAnimationState = iastate;
                        break;

                    case "ModelConditionState":
                        ModelConditionState mcs = new ModelConditionState();
                        name = getString();
                        ParseObject(mcs);
                        dr.AddModelConditionState(name, mcs);
                        break;
                    }
                }
                else if (o.GetType() == typeof(FXList))
                {
                    FXList fx = (FXList)o;
                    switch (s)
                    {
                    case "BuffNugget":
                        BuffNugget bn = new BuffNugget();
                        ParseObject(bn);
                        fx.buffNugget = bn;
                        break;

                    case "CameraShakerVolume":
                        CameraShakerVolume cs = new CameraShakerVolume();
                        ParseObject(cs);
                        fx.cameraShakerVolume = cs;
                        break;

                    case "DynamicDecal":
                        DynamicDecal dc = new DynamicDecal();
                        ParseObject(dc);
                        fx.AddDynamicDecal(dc);
                        break;

                    case "ParticleSystem":
                        ParticleSystem ps = new ParticleSystem();
                        ParseObject(ps);
                        fx.AddParticleSystem(ps);
                        break;

                    case "Sound":
                        Sound so = new Sound();
                        ParseObject(so);
                        fx.AddSound(so);
                        break;

                    case "TerrainScorch":
                        TerrainScorch ts = new TerrainScorch();
                        ParseObject(ts);
                        fx.AddTerrainScorch(ts);
                        break;

                    case "TintDrawable":
                        TintDrawable td = new TintDrawable();
                        ParseObject(td);
                        fx.tintDrawable = td;
                        break;

                    case "ViewShake":
                        ViewShake vs = new ViewShake();
                        ParseObject(vs);
                        fx.viewShake = vs;
                        break;
                    }
                }
                else if (o.GetType() == typeof(GameData))
                {
                    GameData gd = (GameData)o;
                    switch (s)
                    {
                    case "StandardPublicBone":
                        gd.AddStandardPublicBone(getString());
                        break;

                    case "WeaponBonus":
                        gd.AddWeaponBonus(getString(), getString(), getInt());
                        break;
                    }
                }
                else if (o.GetType() == typeof(ModelConditionState))
                {
                    ModelConditionState mstate = (ModelConditionState)o;
                    string name;
                    switch (s)
                    {
                    case "ParticleSysBone":
                        name = getString();
                        mstate.AddParticleSysBone(name, ParseParticleSysBone());
                        break;
                    }
                }
                else if (o.GetType() == typeof(ModifierList))
                {
                    ModifierList ml = (ModifierList)o;
                    switch (s)
                    {
                    case "Modifier":
                        ml.AddModifier(getString(), getStrings());
                        break;
                    }
                }
                else if (o.GetType() == typeof(Multisound))
                {
                    Multisound ms = (Multisound)o;
                    switch (s)
                    {
                    case "Subsounds":
                        string   val    = getStrings();
                        string[] sounds = val.Split(' ');
                        foreach (string sound in sounds)
                        {
                            MusicTrack mt;
                            if (INIManager.TryGetMusicTrack(sound, out mt))
                            {
                                ms.AddMusicTrack(mt);
                            }
                            //else
                            //   PrintError(" no such MusicTrack found: " + sound);
                        }
                        break;
                    }
                }
                else if (o.GetType() == typeof(INI.Object))
                {
                    INI.Object obj = (INI.Object)o;
                    string     name;
                    switch (s)
                    {
                    case "ArmorSet":
                        ArmorSet set = new ArmorSet();
                        ParseObject(set);
                        obj.AddArmorSet(set);
                        break;

                    case "Behaviour":
                        Behaviour b = new Behaviour();
                        name = getString();
                        ParseObject(b);
                        obj.AddBehaviour(name, b);
                        break;

                    case "Body":
                        Body bo = new Body();
                        name = getString();
                        ParseObject(bo);
                        obj.AddBody(name, bo);
                        break;

                    case "Draw":
                        Draw d = new Draw();
                        name = getString();
                        ParseObject(d);
                        obj.AddDraw(name, d);
                        break;
                    }
                }
                else if (o.GetType() == typeof(Weapon))
                {
                    Weapon w = (Weapon)o;
                    switch (s)
                    {
                    case "AttributeModifierNugget":
                        AttributeModifierNugget amn = new AttributeModifierNugget();
                        ParseObject(amn);
                        w.attributeModifierNugget = amn;
                        break;

                    case "DamageContainedNugget":
                        DamageContainedNugget dcn = new DamageContainedNugget();
                        ParseObject(dcn);
                        w.damageContainedNugget = dcn;
                        break;

                    case "DamageFieldNugget":
                        DamageFieldNugget dfn = new DamageFieldNugget();
                        ParseObject(dfn);
                        w.damageFieldNugget = dfn;
                        break;

                    case "DamageNugget":
                        DamageNugget dn = new DamageNugget();
                        ParseObject(dn);
                        w.damageNugget = dn;
                        break;

                    case "DOTNugget":
                        DOTNugget don = new DOTNugget();
                        ParseObject(don);
                        w.dotNugget = don;
                        break;

                    case "FireLogicNugget":
                        FireLogicNugget fln = new FireLogicNugget();
                        ParseObject(fln);
                        w.fireLogicNugget = fln;
                        break;

                    case "HordeAttackNugget":
                        HordeAttackNugget han = new HordeAttackNugget();
                        ParseObject(han);
                        w.hordeAttackNugget = han;
                        break;

                    case "LuaEventNugget":
                        LuaEventNugget len = new LuaEventNugget();
                        ParseObject(len);
                        w.luaEventNugget = len;
                        break;

                    case "MetaImpactNugget":
                        MetaImpactNugget min = new MetaImpactNugget();
                        ParseObject(min);
                        w.metaImpactNugget = min;
                        break;

                    case "OpenGateNugget":
                        OpenGateNugget ogn = new OpenGateNugget();
                        ParseObject(ogn);
                        w.openGateNugget = ogn;
                        break;

                    case "ParalyzeNugget":
                        ParalyzeNugget pan = new ParalyzeNugget();
                        ParseObject(pan);
                        w.paralyzeNugget = pan;
                        break;

                    case "ProjectileNugget":
                        ProjectileNugget pn = new ProjectileNugget();
                        ParseObject(pn);
                        w.AddProjectileNugget(pn);
                        break;

                    case "SlaveAttackNugget":
                        SlaveAttackNugget san = new SlaveAttackNugget();
                        ParseObject(san);
                        w.slaveAttackNugget = san;
                        break;

                    case "StealMoneyNugget":
                        StealMoneyNugget smn = new StealMoneyNugget();
                        ParseObject(smn);
                        w.stealMoneyNugget = smn;
                        break;

                    case "WeaponOCLNugget":
                        WeaponOCLNugget won = new WeaponOCLNugget();
                        ParseObject(won);
                        w.weaponOCLNugget = won;
                        break;
                    }
                }

                else if (fields.ContainsKey(s))
                {
                    Type type = fields[s].FieldType;
                    if (type == typeof(string))
                    {
                        fields[s].SetValue(o, getString());
                    }
                    else if (type == typeof(int))
                    {
                        fields[s].SetValue(o, getInt());
                    }
                    else if (type == typeof(int[]))
                    {
                        fields[s].SetValue(o, getInts());
                    }
                    else if (type == typeof(float))
                    {
                        fields[s].SetValue(o, getFloat());
                    }
                    else if (type == typeof(float[]))
                    {
                        fields[s].SetValue(o, getFloats());
                    }
                    else if (type == typeof(bool))
                    {
                        fields[s].SetValue(o, getBool());
                    }
                    else if (type == typeof(OpenTK.Vector2))
                    {
                        fields[s].SetValue(o, getVec2());
                    }
                    else if (type == typeof(OpenTK.Vector3))
                    {
                        fields[s].SetValue(o, getVec3());
                    }
                    else
                    {
                        PrintError("invalid type: " + type);
                    }
                }
                else
                {
                    if (!s.Equals("End") && !s.Equals("END"))
                    {
                        PrintError("invalid parameter in " + o.GetType() + " class: " + s);
                    }
                }
            }while (!s.Equals("End") && !s.Equals("END"));
        }