ReadSkeletonData() public method

public ReadSkeletonData ( String path ) : SkeletonData
path String
return SkeletonData
    /*
     */
    private void MakeSkeletonAndAnimationData()
    {
        if(sprites == null) {
            Debug.LogWarning("Sprite collection not set for skeleton data asset: " + name,this);
            return;
        }

        if(skeletonJSON == null) {
            Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name,this);
            return;
        }

        SkeletonJson json = new SkeletonJson(new tk2dSpineAttachmentLoader(sprites.spriteCollection));
        json.Scale = scale;

        try {
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
        } catch (Exception ex) {
            Debug.Log("Error reading skeleton JSON file for skeleton data asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace,this);
            return;
        }

        stateData = new AnimationStateData(skeletonData);
        for(int i = 0, n = fromAnimation.Length; i < n; i++) {
            if(fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
            stateData.SetMix(fromAnimation[i],toAnimation[i],duration[i]);
        }
    }
示例#2
0
        public Animation(string AnimationFile)
        {
            skeletonRenderer = new SkeletonRenderer();

            String name = AnimationFile;

            Atlas atlas = new Atlas("Data/" + name + ".atlas", new GLImpTextureLoader());
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("Data/" + name + ".json"));
            skeleton.SetSlotsToSetupPose();

            // Define mixing between animations.
            stateData = new AnimationStateData(skeleton.Data);
            state = new AnimationState(stateData);
            //state.SetAnimation("idle", true);

            skeleton.X = 0;
            skeleton.Y = 0.1f;
            skeleton.UpdateWorldTransform();

            drawtime = new Stopwatch();
            drawtime.Start();

            Program.MiddleDrawQueue += Draw;
        }
示例#3
0
    void OnCurLoadFinish()
    {//先临时验证一下代码构造spine动画,两个atlas的设计问题较多,必须要休整一下播放组件
        GameObject curObj = new GameObject();

        curObj.name = "spine-cur";
        SkeletonAnimationCL ani = curObj.AddComponent <SkeletonAnimationCL>();
        //AtlasAsset assAtlas = new AtlasAsset();
        //assAtlas.materials = new Material[1];
        //assAtlas.materials[0] = new Material(Shader.Find("Spine/Skeleton"));
        //assAtlas.materials[0].mainTexture = curAtlasTex;
        Dictionary <string, Texture2D> texs = new Dictionary <string, Texture2D>();

        texs["cur.png"] = curAtlasTex;
        var atlas = new Spine.Atlas(new System.IO.StringReader(curAtlas), "", new TextureLoad(texs));

        atlas.FlipV();
        //assAtlas.SetAtlas(atlas);

        Spine.SkeletonJson sjson = new Spine.SkeletonJson(atlas);
        sjson.Scale = 1.0f / 64.0f;
        var data = sjson.ReadSkeletonData(new System.IO.StringReader(curSK));

        ani.skeleton = new Spine.Skeleton(data);
        ani.Reset();
        ani.state.SetAnimation(0, "idle", true);
    }
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

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

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

            skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json"));
            if (name == "goblins")
            {
                skeleton.SetSkin("goblingirl");
            }
            skeleton.SetSlotsToBindPose();             // 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);
            state.SetAnimation("walk", false);
            state.AddAnimation("jump", false);
            state.AddAnimation("walk", true);

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
示例#5
0
        public TankScreen(Example game) : base(game)
        {
            // Instantiate and configure the two color tinting effect and
            // assign it to the skeleton renderer
            var twoColorTintEffect = game.Content.Load <Effect>("Content\\SpineEffect");

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

            // The remaining code loads the atlas and skeleton data as in the raptor screen
            atlas = new Atlas("data/tank.atlas", new XnaTextureLoader(game.GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.25f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/tank-pro.json");

            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            skeleton.X = game.GraphicsDevice.Viewport.Width / 2 + 200;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            state.SetAnimation(0, "shoot", true);
        }
示例#6
0
		private Skeleton CreateSkeleton(string atlasName, string skeletonName)
		{
			var atlasData = ContentLoader.Load<AtlasData>(atlasName);
			atlas = new Atlas(atlasData.TextReader, "Content", MaterialLoader);
			var skeletonJson = new SkeletonJson(atlas);
			var spineSkeletonData = ContentLoader.Load<SpineSkeletonData>(skeletonName);
			SkeletonData = skeletonJson.ReadSkeletonData(spineSkeletonData.TextReader);
			return new Skeleton(SkeletonData);
		}
示例#7
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = true;

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

            Atlas        atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json  = new SkeletonJson(atlas);

            if (name == "spineboy")
            {
                json.Scale = 0.6f;
            }
            skeleton = new Skeleton(json.ReadSkeletonData(assetsFolder + name + ".json"));
            if (name == "goblins-ffd")
            {
                skeleton.SetSkin("goblin");
            }

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

            state = new AnimationState(stateData);

            if (name == "spineboy")
            {
                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, "test", false);
                TrackEntry entry = state.AddAnimation(0, "jump", false, 0);
                entry.End += End;                 // Event handling for queued animations.
                state.AddAnimation(0, "run", true, 0);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400;
            skeleton.Y = 590;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
示例#8
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = true;

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

            Atlas        atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            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 (true)
            {
                // 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 += End;                 // Event handling for queued animations.
                state.AddAnimation(0, "walk", true, 0);
            }

            skeleton.X = 320;
            skeleton.Y = 440;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            this.skeletonRenderer = new SkeletonRegionRenderer(GraphicsDevice);

            var atlas = new Atlas(@"Assets\crab.atlas", new XnaTextureLoader(GraphicsDevice));
            var json = new SkeletonJson(atlas);

            this.skeleton = new Skeleton(json.ReadSkeletonData(@"Assets\skeleton.json"));
            this.animation = this.skeleton.Data.FindAnimation("Walk");

            this.skeleton.X = 750;
            this.skeleton.Y = 700;
        }
示例#10
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Atlas        atlas = new Atlas("data/goblins.atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose();             // Without this the skin attachments won't be attached. See SetSkin.
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
示例#11
0
        public SpinePlayer(string atlasPath, string jsonPath)
        {
            Name = jsonPath;

            _skeletonRenderer = new SkeletonRenderer(Render.Device);

            var atlas = new Atlas(atlasPath, new XnaTextureLoader(Render.Device));
            var json = new SkeletonJson(atlas);

            Skeleton = new Skeleton(json.ReadSkeletonData(jsonPath));
            Skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            var stateData = new AnimationStateData(Skeleton.Data);
            State = new AnimationState(stateData);
            IsVisible = true;
        }
示例#12
0
	public SkeletonData GetSkeletonData (bool quiet) {
		if (atlasAsset == null) {
			if (!quiet)
				Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
			Reset();
			return null;
		}

		// if (skeletonJSON == null) {
        if (string.IsNullOrEmpty(skeletonJsonStr)) {
			if (!quiet)
				Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
			Reset();
			return null;
		}

		Atlas atlas = atlasAsset.GetAtlas();
		if (atlas == null) {
			Reset();
			return null;
		}

		if (skeletonData != null)
			return skeletonData;

		SkeletonJson json = new SkeletonJson(atlas);
		json.Scale = scale;
		try {
            // skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJsonStr));
        }
        catch (Exception ex)
        {
			if (!quiet)
				Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
			return null;
		}

		stateData = new AnimationStateData(skeletonData);
		stateData.DefaultMix = defaultMix;
		for (int i = 0, n = fromAnimation.Length; i < n; i++) {
			if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
			stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
		}

		return skeletonData;
	}
示例#13
0
		protected override void LoadContent () {
			skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
			skeletonRenderer.PremultipliedAlpha = true;

			// String name = "spineboy";
			// String name = "goblins-ffd";
			String name = "raptor";

			Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
			SkeletonJson json = new SkeletonJson(atlas);
			if (name == "spineboy") json.Scale = 0.6f;
			if (name == "raptor") json.Scale = 0.5f;
			skeleton = new Skeleton(json.ReadSkeletonData(assetsFolder + name + ".json"));
			if (name == "goblins-ffd") skeleton.SetSkin("goblin");

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

			if (name == "spineboy") {
				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, "test", 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") {
				state.SetAnimation(0, "walk", true);
				state.SetAnimation(1, "empty", false);
				state.AddAnimation(1, "gungrab", false, 2);
			} else {
				state.SetAnimation(0, "walk", true);
			}

			skeleton.X = 400;
			skeleton.Y = 590;
			skeleton.UpdateWorldTransform();

			headSlot = skeleton.FindSlot("head");
		}
示例#14
0
        public Avatar(string AnimationFile)
        {
            SkeletonRenderer = new SkeletonRenderer(Vector3.UnitY, Vector3.UnitZ);

            String name = AnimationFile;

            Atlas atlas = new Atlas(name + ".atlas", new OpenTKTextureLoader());
            SkeletonJson json = new SkeletonJson(atlas);
            Skeleton = new Skeleton(json.ReadSkeletonData(name + ".json"));
            Skeleton.SetSlotsToSetupPose();

            // Define mixing between animations.
            StateData = new AnimationStateData(Skeleton.Data);
            State = new AnimationState(StateData);

            Skeleton.X = 0;
            Skeleton.Y = 0;
            Skeleton.UpdateWorldTransform();
        }
示例#15
0
        protected override SkeletonData Read(ContentReader input, SkeletonData existingInstance)
        {
            string atlasAssetName   = input.ReadString();
            string skeletonDataName = input.ReadString();
            string skeletonJsonText = input.ReadString();

            Atlas        atlas        = input.ContentManager.Load <Atlas>(atlasAssetName);
            SkeletonJson skeletonJson = new SkeletonJson(atlas);

            SkeletonData skeletonData;

            using (TextReader textReader = new StringReader(skeletonJsonText))
            {
                skeletonData = skeletonJson.ReadSkeletonData(textReader);
            }

            skeletonData.Name = skeletonDataName;
            return(skeletonData);
        }
示例#16
0
    public SkeletonData GetSkeletonData(bool quiet)
    {
        if (atlasAsset == null) {
            if (!quiet)
                Debug.LogWarning("Atlas not set for skeleton data asset: " + name, this);
            Clear();
            return null;
        }

        if (skeletonJSON == null) {
            if (!quiet)
                Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name, this);
            Clear();
            return null;
        }

        Atlas atlas = atlasAsset.GetAtlas();
        if (atlas == null) {
            Clear();
            return null;
        }

        if (skeletonData != null)
            return skeletonData;

        SkeletonJson json = new SkeletonJson(atlas);
        json.Scale = scale;
        try {
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
        } catch (Exception) {
            if (!quiet)
                Debug.LogException(new Exception("Error reading skeleton JSON file for skeleton data asset: " + name), this);
            return null;
        }

        stateData = new AnimationStateData(skeletonData);
        for (int i = 0, n = fromAnimation.Length; i < n; i++)
            stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);

        return skeletonData;
    }
	public SkeletonData GetSkeletonData (bool quiet) {
		if (spriteCollection == null) {
			if (!quiet)
				Debug.LogWarning("Sprite collection not set for skeleton data asset: " + name, this);
			Clear();
			return null;
		}

		if (skeletonJSON == null) {
			if (!quiet)
				Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name, this);
			Clear();
			return null;
		}

		if (skeletonData != null)
			return skeletonData;

		SkeletonJson json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection));
		json.Scale = 1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale;

		try {
			skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
		} catch (Exception ex) {
			Debug.Log("Error reading skeleton JSON file for skeleton data asset: " + name + "\n" +
				ex.Message + "\n" + ex.StackTrace, this);
			return null;
		}

		stateData = new AnimationStateData(skeletonData);
		for (int i = 0, n = fromAnimation.Length; i < n; i++) {
			if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0)
				continue;
			stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
		}

		return skeletonData;
	}
    // this actually loads the spine json file into a skeletondata object, then adds it to the dictionary
    public static void LoadSpine(string name, string jsonPath)
    {
        if(!DoesContainSkeleton(name)){

            TextAsset dataAsset = Resources.Load(jsonPath + Futile.resourceSuffix, typeof(TextAsset)) as TextAsset;
            if(dataAsset == null){
                Debug.Log("Could not load Skeleton, file " + jsonPath + Futile.resourceSuffix + " not found.");
                return;
            }

            SkeletonJson json = new SkeletonJson(_attachmentLoader);
            TextReader reader = new StringReader(dataAsset.text);
            SkeletonData skeletonData = json.ReadSkeletonData(reader);

            if(skeletonData != null){
                _skeletons.Add(name, skeletonData);
            }else{
                Debug.Log("Could not load Skeleton Data");
            }
        }else{
            Debug.Log("Skeleton already exists for name [" + name + "]");
        }
    }
示例#19
0
        public RaptorScreen(Example game) : base(game)
        {
            // Load the texture atlas
            atlas = new Atlas("data/raptor.atlas", new XnaTextureLoader(game.GraphicsDevice));

            // Load the .json file using a scale of 0.5
            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.5f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/raptor-pro.json");

            // Create the skeleton and animation state
            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            // Center within the viewport
            skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            // Set the "walk" animation on track one and let it loop forever
            state.SetAnimation(0, "walk", true);
        }
示例#20
0
        public MixAndMatchScreen(Example game) : base(game)
        {
            atlas = new Atlas("data/mix-and-match.atlas", new XnaTextureLoader(game.GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.5f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/mix-and-match-pro.json");

            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            state.SetAnimation(0, "dance", true);

            // 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 mixAndMatchSkin = new Spine.Skin("custom-girl");

            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("skin-base"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("nose/short"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyelids/girly"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyes/violet"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("hair/brown"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("legs/pants-jeans"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/bag"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow"));
            skeleton.SetSkin(mixAndMatchSkin);
        }
示例#21
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Texture2D texture = Util.LoadTexture(GraphicsDevice, "data/goblins.png");
            Atlas atlas = new Atlas("data/goblins.atlas", texture, texture.Width, texture.Height);
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin.
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
示例#22
0
        /// <summary>
        /// Refresh the animation
        /// </summary>
        private void RefreshAnimation()
        {
            if (this.SkeletalData.Atlas == null
             || !this.animationRefreshFlag)
            {
                return;
            }

            if (this.Skeleton != null)
            {
                this.Skeleton = null;
            }

            if (this.State != null)
            {
                this.state.Event -= this.OnEventAnimation;
                this.state.End -= this.OnEndAnimation;
                this.state = null;
            }

            try
            {
                if (!string.IsNullOrEmpty(this.animationPath))
                {
                    using (var fileStream = WaveServices.Storage.OpenContentFile(this.animationPath))
                    {
                        SkeletonData skeletonData = null;
                        var pathExtension = Path.GetExtension(this.animationPath.ToLowerInvariant());

                        if (pathExtension == ".skel")
                        {
                            SkeletonBinary binary = new SkeletonBinary(this.SkeletalData.Atlas);
                            skeletonData = binary.ReadSkeletonData(fileStream);
                        }
                        else
                        {
                            using (var streamReader = new StreamReader(fileStream))
                            {
                                SkeletonJson json = new SkeletonJson(this.SkeletalData.Atlas);
                                skeletonData = json.ReadSkeletonData(streamReader);
                            }
                        }

                        this.Skeleton = new Skeleton(skeletonData);
                    }

                    if (string.IsNullOrEmpty(this.currentAnimation)
                     || !this.AnimationNames.Any(animation => animation == this.currentAnimation))
                    {
                        this.currentAnimation = string.Empty;
                    }

                    if (string.IsNullOrEmpty(this.currentSkin)
                     || !this.SkinNames.Any(skin => skin == this.currentSkin))
                    {
                        this.currentSkin = this.Skeleton.Data.DefaultSkin.Name;
                    }

                    this.Skeleton.SetSkin(this.currentSkin);

                    if (this.OnAnimationRefresh != null)
                    {
                        this.OnAnimationRefresh(this, EventArgs.Empty);
                    }

                    AnimationStateData stateData = new AnimationStateData(this.Skeleton.Data);
                    this.state = new AnimationState(stateData);
                    this.state.Event += this.OnEventAnimation;
                    this.state.End += this.OnEndAnimation;

                    this.Update(TimeSpan.Zero);
                    this.animationRefreshFlag = false;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("The atlas file is not valid: " + e.Message);
                this.Skeleton = null;
                this.state = null;
            }
        }
示例#23
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = true;

            // String name = "spineboy";
            // String name = "goblins-mesh";
            // String name = "raptor";
            String name = "tank";
            // String name = "star";
            bool binaryData = true;

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

            float scale = 1;

            if (name == "spineboy")
            {
                scale = 0.6f;
            }
            if (name == "raptor")
            {
                scale = 0.5f;
            }
            if (name == "tank")
            {
                scale = 0.3f;
            }

            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-mesh")
            {
                skeleton.SetSkin("goblin");
            }

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

            state = new AnimationState(stateData);

            if (name == "spineboy")
            {
                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, "test", 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")
            {
                state.SetAnimation(0, "walk", true);
                state.AddAnimation(1, "gungrab", false, 2);
            }
            else if (name == "star")
            {
                // no animation in star
            }
            else if (name == "tank")
            {
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400 + (name == "tank" ? 300: 0);
            skeleton.Y = 580;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
        /// <summary>
        /// Performs further custom initialization for this instance.
        /// </summary>
        /// <remarks>
        /// By default this method does nothing.
        /// </remarks>
        protected override void Initialize()
        {
            base.Initialize();

            SkeletonJson json = new SkeletonJson(this.SkeletalData.Atlas);
            this.Skeleton = new Skeleton(json.ReadSkeletonData(this.animationPath));

            if (string.IsNullOrEmpty(this.currentSkin))
            {
                this.Skeleton.SetSkin(this.Skeleton.Data.DefaultSkin);
            }
            else
            {
                this.Skeleton.SetSkin(this.currentSkin);
            }

            AnimationStateData stateData = new AnimationStateData(this.Skeleton.Data);
            this.state = new AnimationState(stateData);
            this.state.End += this.OnEndAnimation;
        }
示例#25
0
        protected override void LoadContent()
        {
            bool   useNormalmapShader = false;
            Effect spineEffect;

            if (!useNormalmapShader)
            {
                // Two color tint effect. Note that you can also use the default BasicEffect instead.
                spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffect");
            }
            else
            {
                spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffectNormalmap");
                spineEffect.Parameters["Light0_Direction"].SetValue(new Vector3(-0.5265408f, 0.5735765f, -0.6275069f));
                spineEffect.Parameters["Light0_Diffuse"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f));
                spineEffect.Parameters["Light0_Specular"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f));
                spineEffect.Parameters["Light0_SpecularExponent"].SetValue(2.0f);
            }
            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;

            skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice);
            skeletonDebugRenderer.DisableAll();
            skeletonDebugRenderer.DrawClipping = true;

            // String name = "spineboy-pro";
            String name = "raptor-pro";

            // String name = "tank-pro";
            //String name = "coin-pro";
            if (useNormalmapShader)
            {
                name = "raptor-pro";                 // we only have normalmaps for raptor
            }
            String atlasName = name.Replace("-pro", "").Replace("-ess", "");

            bool binaryData = false;

            Atlas atlas;

            if (!useNormalmapShader)
            {
                atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice));
            }
            else
            {
                atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice,
                                                                                            loadMultipleTextureLayers: true, textureSuffixes: new string[] { "", "_normals" }));
            }
            float scale = 1;

            if (name == "spineboy-pro")
            {
                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-pro")
            {
                skeleton.SetAttachment("head-bb", "head");

                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, "run", true);
                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, "animation", true);
            }
            else if (name == "tank-pro")
            {
                skeleton.X += 300;
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X += 400;
            skeleton.Y += GraphicsDevice.Viewport.Height;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
    public SkeletonData GetSkeletonData(bool quiet)
    {
        if (atlasAssets == null) {
            atlasAssets = new AtlasAsset[0];
            if (!quiet)
                Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
            Reset();
            return null;
        }

        if (skeletonJSON == null) {
            if (!quiet)
                Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
            Reset();
            return null;
        }

        if (atlasAssets.Length == 0) {
            Reset();
            return null;
        }

        Atlas[] atlasArr = new Atlas[atlasAssets.Length];
        for (int i = 0; i < atlasAssets.Length; i++) {
            if (atlasAssets[i] == null) {
                Reset();
                return null;
            }
            atlasArr[i] = atlasAssets[i].GetAtlas();
            if (atlasArr[i] == null) {
                Reset();
                return null;
            }
        }

        if (skeletonData != null)
            return skeletonData;

        SkeletonJson json = new SkeletonJson(atlasArr);
        json.Scale = scale;
        try {
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
        } catch (Exception ex) {
            if (!quiet)
                Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
            return null;
        }

        stateData = new AnimationStateData(skeletonData);
        FillStateData();

        return skeletonData;
    }
        AnimationStateTests(string testJsonFilePath)
        {
            skeletonData = json.ReadSkeletonData(testJsonFilePath);

            TrackEntry entry;

            Setup("0.1 time step",                   // 1
                  Expect(0, "start", 0, 0),          //
                  Expect(0, "event 0", 0, 0),        //
                  Expect(0, "event 14", 0.5f, 0.5f), //
                  Expect(0, "event 30", 1, 1),       //
                  Expect(0, "complete", 1, 1),       //
                  Expect(0, "end", 1, 1.1f),         //
                  Expect(0, "dispose", 1, 1.1f)      //
                  );
            state.SetAnimation(0, "events0", false).TrackEnd = 1;
            Run(0.1f, 1000, null);

            Setup("1/60 time step, dispose queued",     // 2
                  Expect(0, "start", 0, 0),             //
                  Expect(0, "interrupt", 0, 0),         //
                  Expect(0, "end", 0, 0),               //
                  Expect(0, "dispose", 0, 0),           //
                  Expect(1, "dispose", 0, 0),           //
                  Expect(0, "dispose", 0, 0),           //
                  Expect(1, "dispose", 0, 0),           //

                  Note("First 2 set/addAnimation calls are done."),

                  Expect(0, "start", 0, 0),               //
                  Expect(0, "event 0", 0, 0),             //
                  Expect(0, "event 14", 0.483f, 0.483f),  //
                  Expect(0, "event 30", 1, 1),            //
                  Expect(0, "complete", 1, 1),            //
                  Expect(0, "end", 1, 1.017f),            //
                  Expect(0, "dispose", 1, 1.017f)         //
                  );
            state.SetAnimation(0, "events0", false);
            state.AddAnimation(0, "events1", false, 0);
            state.AddAnimation(0, "events0", false, 0);
            state.AddAnimation(0, "events1", false, 0);
            state.SetAnimation(0, "events0", false).TrackEnd = 1;
            Run(1 / 60f, 1000, null);

            Setup("30 time step",                // 3
                  Expect(0, "start", 0, 0),      //
                  Expect(0, "event 0", 0, 0),    //
                  Expect(0, "event 14", 30, 30), //
                  Expect(0, "event 30", 30, 30), //
                  Expect(0, "complete", 30, 30), //
                  Expect(0, "end", 30, 60),      //
                  Expect(0, "dispose", 30, 60)   //
                  );
            state.SetAnimation(0, "events0", false).TrackEnd = 1;
            Run(30, 1000, null);

            Setup("1 time step",               // 4
                  Expect(0, "start", 0, 0),    //
                  Expect(0, "event 0", 0, 0),  //
                  Expect(0, "event 14", 1, 1), //
                  Expect(0, "event 30", 1, 1), //
                  Expect(0, "complete", 1, 1), //
                  Expect(0, "end", 1, 2),      //
                  Expect(0, "dispose", 1, 2)   //
                  );
            state.SetAnimation(0, "events0", false).TrackEnd = 1;
            Run(1, 1.01f, null);

            Setup("interrupt",                        // 5
                  Expect(0, "start", 0, 0),           //
                  Expect(0, "event 0", 0, 0),         //
                  Expect(0, "event 14", 0.5f, 0.5f),  //
                  Expect(0, "event 30", 1, 1),        //
                  Expect(0, "complete", 1, 1),        //
                  Expect(0, "interrupt", 1.1f, 1.1f), //

                  Expect(1, "start", 0.1f, 1.1f),     //
                  Expect(1, "event 0", 0.1f, 1.1f),   //

                  Expect(0, "end", 1.1f, 1.2f),       //
                  Expect(0, "dispose", 1.1f, 1.2f),   //

                  Expect(1, "event 14", 0.5f, 1.5f),  //
                  Expect(1, "event 30", 1, 2),        //
                  Expect(1, "complete", 1, 2),        //
                  Expect(1, "interrupt", 1.1f, 2.1f), //

                  Expect(0, "start", 0.1f, 2.1f),     //
                  Expect(0, "event 0", 0.1f, 2.1f),   //

                  Expect(1, "end", 1.1f, 2.2f),       //
                  Expect(1, "dispose", 1.1f, 2.2f),   //

                  Expect(0, "event 14", 0.5f, 2.5f),  //
                  Expect(0, "event 30", 1, 3),        //
                  Expect(0, "complete", 1, 3),        //
                  Expect(0, "end", 1, 3.1f),          //
                  Expect(0, "dispose", 1, 3.1f)       //
                  );
            state.SetAnimation(0, "events0", false);
            state.AddAnimation(0, "events1", false, 0);
            state.AddAnimation(0, "events0", false, 0).TrackEnd = 1;
            Run(0.1f, 4f, null);

            Setup("interrupt with delay",             // 6
                  Expect(0, "start", 0, 0),           //
                  Expect(0, "event 0", 0, 0),         //
                  Expect(0, "event 14", 0.5f, 0.5f),  //
                  Expect(0, "interrupt", 0.6f, 0.6f), //

                  Expect(1, "start", 0.1f, 0.6f),     //
                  Expect(1, "event 0", 0.1f, 0.6f),   //

                  Expect(0, "end", 0.6f, 0.7f),       //
                  Expect(0, "dispose", 0.6f, 0.7f),   //

                  Expect(1, "event 14", 0.5f, 1.0f),  //
                  Expect(1, "event 30", 1, 1.5f),     //
                  Expect(1, "complete", 1, 1.5f),     //
                  Expect(1, "end", 1, 1.6f),          //
                  Expect(1, "dispose", 1, 1.6f)       //
                  );
            state.SetAnimation(0, "events0", false);
            state.AddAnimation(0, "events1", false, 0.5f).TrackEnd = 1;
            Run(0.1f, 1000, null);

            Setup("interrupt with delay and mix time",  // 7
                  Expect(0, "start", 0, 0),             //
                  Expect(0, "event 0", 0, 0),           //
                  Expect(0, "event 14", 0.5f, 0.5f),    //
                  Expect(0, "interrupt", 1, 1),         //

                  Expect(1, "start", 0.1f, 1),          //

                  Expect(0, "complete", 1, 1),          //

                  Expect(1, "event 0", 0.1f, 1),        //
                  Expect(1, "event 14", 0.5f, 1.4f),    //

                  Expect(0, "end", 1.6f, 1.7f),         //
                  Expect(0, "dispose", 1.6f, 1.7f),     //

                  Expect(1, "event 30", 1, 1.9f),       //
                  Expect(1, "complete", 1, 1.9f),       //
                  Expect(1, "end", 1, 2),               //
                  Expect(1, "dispose", 1, 2)            //
                  );
            stateData.SetMix("events0", "events1", 0.7f);
            state.SetAnimation(0, "events0", true);
            state.AddAnimation(0, "events1", false, 0.9f).TrackEnd = 1;
            Run(0.1f, 1000, null);

            Setup("animation 0 events do not fire during mix", // 8
                  Expect(0, "start", 0, 0),                    //
                  Expect(0, "event 0", 0, 0),                  //
                  Expect(0, "interrupt", 0.5f, 0.5f),          //

                  Expect(1, "start", 0.1f, 0.5f),              //
                  Expect(1, "event 0", 0.1f, 0.5f),            //
                  Expect(1, "event 14", 0.5f, 0.9f),           //

                  Expect(0, "complete", 1, 1),                 //
                  Expect(0, "end", 1.1f, 1.2f),                //
                  Expect(0, "dispose", 1.1f, 1.2f),            //

                  Expect(1, "event 30", 1, 1.4f),              //
                  Expect(1, "complete", 1, 1.4f),              //
                  Expect(1, "end", 1, 1.5f),                   //
                  Expect(1, "dispose", 1, 1.5f)                //
                  );
            stateData.DefaultMix = 0.7f;
            state.SetAnimation(0, "events0", false);
            state.AddAnimation(0, "events1", false, 0.4f).TrackEnd = 1;
            Run(0.1f, 1000, null);

            Setup("event threshold, some animation 0 events fire during mix", // 9
                  Expect(0, "start", 0, 0),                                   //
                  Expect(0, "event 0", 0, 0),                                 //
                  Expect(0, "interrupt", 0.5f, 0.5f),                         //

                  Expect(1, "start", 0.1f, 0.5f),                             //

                  Expect(0, "event 14", 0.5f, 0.5f),                          //

                  Expect(1, "event 0", 0.1f, 0.5f),                           //
                  Expect(1, "event 14", 0.5f, 0.9f),                          //

                  Expect(0, "complete", 1, 1),                                //
                  Expect(0, "end", 1.1f, 1.2f),                               //
                  Expect(0, "dispose", 1.1f, 1.2f),                           //

                  Expect(1, "event 30", 1, 1.4f),                             //
                  Expect(1, "complete", 1, 1.4f),                             //
                  Expect(1, "end", 1, 1.5f),                                  //
                  Expect(1, "dispose", 1, 1.5f)                               //
                  );
            stateData.SetMix("events0", "events1", 0.7f);
            state.SetAnimation(0, "events0", false).EventThreshold = 0.5f;
            state.AddAnimation(0, "events1", false, 0.4f).TrackEnd = 1;
            Run(0.1f, 1000, null);

            Setup("event threshold, all animation 0 events fire during mix", // 10
                  Expect(0, "start", 0, 0),                                  //
                  Expect(0, "event 0", 0, 0),                                //
                  Expect(0, "event 14", 0.5f, 0.5f),                         //
                  Expect(0, "interrupt", 0.9f, 0.9f),                        //

                  Expect(1, "start", 0.1f, 0.9f),                            //
                  Expect(1, "event 0", 0.1f, 0.9f),                          //

                  Expect(0, "event 30", 1, 1),                               //
                  Expect(0, "complete", 1, 1),                               //
                  Expect(0, "event 0", 1, 1),                                //

                  Expect(1, "event 14", 0.5f, 1.3f),                         //

                  Expect(0, "end", 1.5f, 1.6f),                              //
                  Expect(0, "dispose", 1.5f, 1.6f),                          //

                  Expect(1, "event 30", 1, 1.8f),                            //
                  Expect(1, "complete", 1, 1.8f),                            //
                  Expect(1, "end", 1, 1.9f),                                 //
                  Expect(1, "dispose", 1, 1.9f)                              //
                  );
            state.SetAnimation(0, "events0", true).EventThreshold = 1;
            entry             = state.AddAnimation(0, "events1", false, 0.8f);
            entry.MixDuration = 0.7f;
            entry.TrackEnd    = 1;
            Run(0.1f, 1000, null);

            Setup("looping",                         // 11
                  Expect(0, "start", 0, 0),          //
                  Expect(0, "event 0", 0, 0),        //
                  Expect(0, "event 14", 0.5f, 0.5f), //
                  Expect(0, "event 30", 1, 1),       //
                  Expect(0, "complete", 1, 1),       //
                  Expect(0, "event 0", 1, 1),        //
                  Expect(0, "event 14", 1.5f, 1.5f), //
                  Expect(0, "event 30", 2, 2),       //
                  Expect(0, "complete", 2, 2),       //
                  Expect(0, "event 0", 2, 2),        //
                  Expect(0, "event 14", 2.5f, 2.5f), //
                  Expect(0, "event 30", 3, 3),       //
                  Expect(0, "complete", 3, 3),       //
                  Expect(0, "event 0", 3, 3),        //
                  Expect(0, "event 14", 3.5f, 3.5f), //
                  Expect(0, "event 30", 4, 4),       //
                  Expect(0, "complete", 4, 4),       //
                  Expect(0, "event 0", 4, 4),        //
                  Expect(0, "end", 4.1f, 4.1f),      //
                  Expect(0, "dispose", 4.1f, 4.1f)   //
                  );
            state.SetAnimation(0, "events0", true);
            Run(0.1f, 4, null);

            Setup("not looping, track end past animation 0 duration", // 12
                  Expect(0, "start", 0, 0),                           //
                  Expect(0, "event 0", 0, 0),                         //
                  Expect(0, "event 14", 0.5f, 0.5f),                  //
                  Expect(0, "event 30", 1, 1),                        //
                  Expect(0, "complete", 1, 1),                        //
                  Expect(0, "interrupt", 2.1f, 2.1f),                 //

                  Expect(1, "start", 0.1f, 2.1f),                     //
                  Expect(1, "event 0", 0.1f, 2.1f),                   //

                  Expect(0, "end", 2.1f, 2.2f),                       //
                  Expect(0, "dispose", 2.1f, 2.2f),                   //

                  Expect(1, "event 14", 0.5f, 2.5f),                  //
                  Expect(1, "event 30", 1, 3),                        //
                  Expect(1, "complete", 1, 3),                        //
                  Expect(1, "end", 1, 3.1f),                          //
                  Expect(1, "dispose", 1, 3.1f)                       //
                  );
            state.SetAnimation(0, "events0", false);
            state.AddAnimation(0, "events1", false, 2).TrackEnd = 1;
            Run(0.1f, 4f, null);


            Setup("interrupt animation after first loop complete", // 13
                  Expect(0, "start", 0, 0),                        //
                  Expect(0, "event 0", 0, 0),                      //
                  Expect(0, "event 14", 0.5f, 0.5f),               //
                  Expect(0, "event 30", 1, 1),                     //
                  Expect(0, "complete", 1, 1),                     //
                  Expect(0, "event 0", 1, 1),                      //
                  Expect(0, "event 14", 1.5f, 1.5f),               //
                  Expect(0, "event 30", 2, 2),                     //
                  Expect(0, "complete", 2, 2),                     //
                  Expect(0, "event 0", 2, 2),                      //
                  Expect(0, "interrupt", 2.1f, 2.1f),              //

                  Expect(1, "start", 0.1f, 2.1f),                  //
                  Expect(1, "event 0", 0.1f, 2.1f),                //

                  Expect(0, "end", 2.1f, 2.2f),                    //
                  Expect(0, "dispose", 2.1f, 2.2f),                //

                  Expect(1, "event 14", 0.5f, 2.5f),               //
                  Expect(1, "event 30", 1, 3),                     //
                  Expect(1, "complete", 1, 3),                     //
                  Expect(1, "end", 1, 3.1f),                       //
                  Expect(1, "dispose", 1, 3.1f)                    //
                  );
            state.SetAnimation(0, "events0", true);
            Run(0.1f, 6, new TestListener(
                    (time) => {
                if (IsEqual(time, 1.4f))
                {
                    state.AddAnimation(0, "events1", false, 0).TrackEnd = 1;
                }
            }));

            Setup("add animation on empty track",         // 14
                  Expect(0, "start", 0, 0),               //
                  Expect(0, "event 0", 0, 0),             //
                  Expect(0, "event 14", 0.5f, 0.5f),      //
                  Expect(0, "event 30", 1, 1),            //
                  Expect(0, "complete", 1, 1),            //
                  Expect(0, "end", 1, 1.1f),              //
                  Expect(0, "dispose", 1, 1.1f)           //
                  );
            state.AddAnimation(0, "events0", false, 0).TrackEnd = 1;
            Run(0.1f, 1.9f, null);

            Setup("end time beyond non-looping animation duration", // 15
                  Expect(0, "start", 0, 0),                         //
                  Expect(0, "event 0", 0, 0),                       //
                  Expect(0, "event 14", 0.5f, 0.5f),                //
                  Expect(0, "event 30", 1, 1),                      //
                  Expect(0, "complete", 1, 1),                      //
                  Expect(0, "end", 9f, 9.1f),                       //
                  Expect(0, "dispose", 9f, 9.1f)                    //
                  );
            state.SetAnimation(0, "events0", false).TrackEnd = 9;
            Run(0.1f, 10, null);

            Setup("looping with animation start",         // 16
                  Expect(0, "start", 0, 0),               //
                  Expect(0, "event 30", 0.4f, 0.4f),      //
                  Expect(0, "complete", 0.4f, 0.4f),      //
                  Expect(0, "event 30", 0.8f, 0.8f),      //
                  Expect(0, "complete", 0.8f, 0.8f),      //
                  Expect(0, "event 30", 1.2f, 1.2f),      //
                  Expect(0, "complete", 1.2f, 1.2f),      //
                  Expect(0, "end", 1.4f, 1.4f),           //
                  Expect(0, "dispose", 1.4f, 1.4f)        //
                  );
            entry = state.SetAnimation(0, "events0", true);
            entry.AnimationLast  = 0.6f;
            entry.AnimationStart = 0.6f;
            Run(0.1f, 1.4f, null);

            Setup("looping with animation start and end", // 17
                  Expect(0, "start", 0, 0),               //
                  Expect(0, "event 14", 0.3f, 0.3f),      //
                  Expect(0, "complete", 0.6f, 0.6f),      //
                  Expect(0, "event 14", 0.9f, 0.9f),      //
                  Expect(0, "complete", 1.2f, 1.2f),      //
                  Expect(0, "event 14", 1.5f, 1.5f),      //
                  Expect(0, "end", 1.8f, 1.8f),           //
                  Expect(0, "dispose", 1.8f, 1.8f)        //
                  );
            entry = state.SetAnimation(0, "events0", true);
            entry.AnimationStart = 0.2f;
            entry.AnimationLast  = 0.2f;
            entry.AnimationEnd   = 0.8f;
            Run(0.1f, 1.8f, null);

            Setup("non-looping with animation start and end", // 18
                  Expect(0, "start", 0, 0),                   //
                  Expect(0, "event 14", 0.3f, 0.3f),          //
                  Expect(0, "complete", 0.6f, 0.6f),          //
                  Expect(0, "end", 1, 1.1f),                  //
                  Expect(0, "dispose", 1, 1.1f)               //
                  );
            entry = state.SetAnimation(0, "events0", false);
            entry.AnimationStart = 0.2f;
            entry.AnimationLast  = 0.2f;
            entry.AnimationEnd   = 0.8f;
            entry.TrackEnd       = 1;
            Run(0.1f, 1.8f, null);

            Setup("mix out looping with animation start and end", // 19
                  Expect(0, "start", 0, 0),                       //
                  Expect(0, "event 14", 0.3f, 0.3f),              //
                  Expect(0, "complete", 0.6f, 0.6f),              //
                  Expect(0, "interrupt", 0.8f, 0.8f),             //

                  Expect(1, "start", 0.1f, 0.8f),                 //
                  Expect(1, "event 0", 0.1f, 0.8f),               //

                  Expect(0, "event 14", 0.9f, 0.9f),              //
                  Expect(0, "complete", 1.2f, 1.2f),              //

                  Expect(1, "event 14", 0.5f, 1.2f),              //

                  Expect(0, "end", 1.4f, 1.5f),                   //
                  Expect(0, "dispose", 1.4f, 1.5f),               //

                  Expect(1, "event 30", 1, 1.7f),                 //
                  Expect(1, "complete", 1, 1.7f),                 //
                  Expect(1, "end", 1, 1.8f),                      //
                  Expect(1, "dispose", 1, 1.8f)                   //
                  );
            entry = state.SetAnimation(0, "events0", true);
            entry.AnimationStart = (0.2f);
            entry.AnimationLast  = (0.2f);
            entry.AnimationEnd   = (0.8f);
            entry.EventThreshold = 1;
            entry             = state.AddAnimation(0, "events1", false, 0.7f);
            entry.MixDuration = (0.7f);
            entry.TrackEnd    = 1;
            Run(0.1f, 20, null);

            Setup("setAnimation with track entry mix",    // 20
                  Expect(0, "start", 0, 0),               //
                  Expect(0, "event 0", 0, 0),             //
                  Expect(0, "event 14", 0.5f, 0.5f),      //
                  Expect(0, "event 30", 1, 1),            //
                  Expect(0, "complete", 1, 1),            //
                  Expect(0, "event 0", 1, 1),             //
                  Expect(0, "interrupt", 1, 1),           //

                  Expect(1, "start", 0, 1),               //

                  Expect(1, "event 0", 0.1f, 1.1f),       //
                  Expect(1, "event 14", 0.5f, 1.5f),      //

                  Expect(0, "end", 1.7f, 1.8f),           //
                  Expect(0, "dispose", 1.7f, 1.8f),       //

                  Expect(1, "event 30", 1, 2),            //
                  Expect(1, "complete", 1, 2),            //
                  Expect(1, "end", 1, 2.1f),              //
                  Expect(1, "dispose", 1, 2.1f)           //
                  );
            state.SetAnimation(0, "events0", true);
            Run(0.1f, 1000, new TestListener(
                    (time) => {
                if (IsEqual(time, 1f))
                {
                    TrackEntry ent  = state.SetAnimation(0, "events1", false);
                    ent.MixDuration = (0.7f);
                    ent.TrackEnd    = 1;
                }
            }));

            Setup("setAnimation twice",              // 21
                  Expect(0, "start", 0, 0),          //
                  Expect(0, "interrupt", 0, 0),      //
                  Expect(0, "end", 0, 0),            //
                  Expect(0, "dispose", 0, 0),        //

                  Expect(1, "start", 0, 0),          //
                  Expect(1, "event 0", 0, 0),        //
                  Expect(1, "event 14", 0.5f, 0.5f), //

                  Note("First 2 setAnimation calls are done."),

                  Expect(1, "interrupt", 0.8f, 0.8f),      //

                  Expect(0, "start", 0, 0.8f),             //
                  Expect(0, "interrupt", 0, 0.8f),         //
                  Expect(0, "end", 0, 0.8f),               //
                  Expect(0, "dispose", 0, 0.8f),           //

                  Expect(2, "start", 0, 0.8f),             //
                  Expect(2, "event 0", 0.1f, 0.9f),        //

                  Expect(1, "end", 0.9f, 1),               //
                  Expect(1, "dispose", 0.9f, 1),           //

                  Expect(2, "event 14", 0.5f, 1.3f),       //
                  Expect(2, "event 30", 1, 1.8f),          //
                  Expect(2, "complete", 1, 1.8f),          //
                  Expect(2, "end", 1, 1.9f),               //
                  Expect(2, "dispose", 1, 1.9f)            //
                  );
            state.SetAnimation(0, "events0", false);       // First should be ignored.
            state.SetAnimation(0, "events1", false);
            Run(0.1f, 1000, new TestListener(
                    (time) => {
                if (IsEqual(time, 0.8f))
                {
                    state.SetAnimation(0, "events0", false);                             // First should be ignored.
                    state.SetAnimation(0, "events2", false).TrackEnd = 1;
                }
            }));

            Setup("setAnimation twice with multiple mixing", // 22
                  Expect(0, "start", 0, 0),                  //
                  Expect(0, "interrupt", 0, 0),              //
                  Expect(0, "end", 0, 0),                    //
                  Expect(0, "dispose", 0, 0),                //

                  Expect(1, "start", 0, 0),                  //
                  Expect(1, "event 0", 0, 0),                //

                  Note("First 2 setAnimation calls are done."),

                  Expect(1, "interrupt", 0.2f, 0.2f),      //

                  Expect(0, "start", 0, 0.2f),             //
                  Expect(0, "interrupt", 0, 0.2f),         //
                  Expect(0, "end", 0, 0.2f),               //
                  Expect(0, "dispose", 0, 0.2f),           //

                  Expect(2, "start", 0, 0.2f),             //
                  Expect(2, "event 0", 0.1f, 0.3f),        //

                  Note("Second 2 setAnimation calls are done."),

                  Expect(2, "interrupt", 0.2f, 0.4f),      //

                  Expect(1, "start", 0, 0.4f),             //
                  Expect(1, "interrupt", 0, 0.4f),         //
                  Expect(1, "end", 0, 0.4f),               //
                  Expect(1, "dispose", 0, 0.4f),           //

                  Expect(0, "start", 0, 0.4f),             //
                  Expect(0, "event 0", 0.1f, 0.5f),        //

                  Expect(1, "end", 0.8f, 0.9f),            //
                  Expect(1, "dispose", 0.8f, 0.9f),        //

                  Expect(0, "event 14", 0.5f, 0.9f),       //

                  Expect(2, "end", 0.8f, 1.1f),            //
                  Expect(2, "dispose", 0.8f, 1.1f),        //

                  Expect(0, "event 30", 1, 1.4f),          //
                  Expect(0, "complete", 1, 1.4f),          //
                  Expect(0, "end", 1, 1.5f),               //
                  Expect(0, "dispose", 1, 1.5f)            //
                  );
            stateData.DefaultMix = 0.6f;
            state.SetAnimation(0, "events0", false);             // First should be ignored.
            state.SetAnimation(0, "events1", false);
            Run(0.1f, 1000, new TestListener(
                    (time) => {
                if (IsEqual(time, 0.2f))
                {
                    state.SetAnimation(0, "events0", false);                             // First should be ignored.
                    state.SetAnimation(0, "events2", false);
                }
                if (IsEqual(time, 0.4f))
                {
                    state.SetAnimation(0, "events1", false);                             // First should be ignored.
                    state.SetAnimation(0, "events0", false).TrackEnd = 1;
                }
            }));

            Setup("addAnimation with delay on empty track", // 23
                  Expect(0, "start", 0, 0),                 //
                  Expect(0, "event 0", 0, 5),               //
                  Expect(0, "event 14", 0.5f, 5.5f),        //
                  Expect(0, "event 30", 1, 6),              //
                  Expect(0, "complete", 1, 6),              //
                  Expect(0, "end", 1, 6.1f),                //
                  Expect(0, "dispose", 1, 6.1f)             //
                  );
            state.AddAnimation(0, "events0", false, 5).TrackEnd = 1;
            Run(0.1f, 10, null);

            Setup("setAnimation during AnimationStateListener");             // 24
            state.Start += (trackEntry) => {
                if (trackEntry.Animation.Name.Equals("events0"))
                {
                    state.SetAnimation(1, "events1", false);
                }
            };
            state.Interrupt += (trackEntry) => {
                state.AddAnimation(3, "events1", false, 0);
            };
            state.End += (trackEntry) => {
                if (trackEntry.Animation.Name.Equals("events0"))
                {
                    state.SetAnimation(0, "events1", false);
                }
            };
            state.Dispose += (trackEntry) => {
                if (trackEntry.Animation.Name.Equals("events0"))
                {
                    state.SetAnimation(1, "events1", false);
                }
            };
            state.Complete += (trackEntry) => {
                if (trackEntry.Animation.Name.Equals("events0"))
                {
                    state.SetAnimation(1, "events1", false);
                }
            };
            state.Event += (trackEntry, ev) => {
                if (trackEntry.TrackIndex != 2)
                {
                    state.SetAnimation(2, "events1", false);
                }
            };
            state.AddAnimation(0, "events0", false, 0);
            state.AddAnimation(0, "events1", false, 0);
            state.SetAnimation(1, "events1", false).TrackEnd = 1;
            Run(0.1f, 10, null);

            Setup("clearTrack",                      // 25
                  Expect(0, "start", 0, 0),          //
                  Expect(0, "event 0", 0, 0),        //
                  Expect(0, "event 14", 0.5f, 0.5f), //
                  Expect(0, "end", 0.7f, 0.7f),      //
                  Expect(0, "dispose", 0.7f, 0.7f)   //
                  );
            state.AddAnimation(0, "events0", false, 0).TrackEnd = 1;
            Run(0.1f, 10, new TestListener(
                    (time) => {
                if (IsEqual(time, 0.7f))
                {
                    state.ClearTrack(0);
                }
            }));

            Setup("setEmptyAnimation",                // 26
                  Expect(0, "start", 0, 0),           //
                  Expect(0, "event 0", 0, 0),         //
                  Expect(0, "event 14", 0.5f, 0.5f),  //
                  Expect(0, "interrupt", 0.7f, 0.7f), //

                  Expect(-1, "start", 0, 0.7f),       //
                  Expect(-1, "complete", 0.1f, 0.8f), //

                  Expect(0, "end", 0.8f, 0.9f),       //
                  Expect(0, "dispose", 0.8f, 0.9f),   //

                  Expect(-1, "end", 0.2f, 1),         //
                  Expect(-1, "dispose", 0.2f, 1)      //
                  );
            state.AddAnimation(0, "events0", false, 0).TrackEnd = 1;
            Run(0.1f, 10, new TestListener(
                    (time) => {
                if (IsEqual(time, 0.7f))
                {
                    state.SetEmptyAnimation(0, 0);
                }
            }));

            Setup("TrackEntry listener");             // 27
            int counter = 0;

            entry        = state.AddAnimation(0, "events0", false, 0);
            entry.Start += (trackEntry) => {
                Interlocked.Add(ref counter, 1 << 1);
            };
            entry.Interrupt += (trackEntry) => {
                Interlocked.Add(ref counter, 1 << 5);
            };
            entry.End += (trackEntry) => {
                Interlocked.Add(ref counter, 1 << 9);
            };
            entry.Dispose += (trackEntry) => {
                Interlocked.Add(ref counter, 1 << 13);
            };
            entry.Complete += (trackEntry) => {
                Interlocked.Add(ref counter, 1 << 17);
            };
            entry.Event += (trackEntry, ev) => {
                Interlocked.Add(ref counter, 1 << 21);
            };
            state.AddAnimation(0, "events0", false, 0);
            state.AddAnimation(0, "events1", false, 0);
            state.SetAnimation(1, "events1", false).TrackEnd = 1;
            Run(0.1f, 10, null);
            if (counter != 15082016)
            {
                string message = "TEST 27 FAILED! " + counter;
                Log(message);
                FailTestRun(message);
            }

#if RUN_ADDITIONAL_FORUM_RELATED_TEST
            Setup("0.1 time step, start and add",         // 2
                  Expect(0, "start", 0, 0),               //
                  Expect(0, "event 0", 0, 0),             //
                  Expect(0, "event 14", 0.5f, 0.5f),      //
                  Expect(0, "event 30", 1, 1),            //
                  Expect(0, "complete", 1, 1),            //
                  Expect(0, "interrupt", 1.1f, 1.1f),     //
                  Expect(1, "start", 0.1f, 1.1f),         //
                  Expect(1, "event 0", 0.1f, 1.1f),       //
                  Expect(0, "end", 1.3f, 1.4f),           //
                  Expect(0, "dispose", 1.3f, 1.4f),       //
                  Expect(1, "event 14", 0.5f, 1.5f),      //
                  Expect(1, "event 30", 1, 2),            //
                  Expect(1, "complete", 1, 2),            //
                  Expect(1, "end", 1, 2.1f),              //
                  Expect(1, "dispose", 1, 2.1f)           //
                  );
            state.SetAnimation(0, "events0", false);
            var entry1 = state.AddAnimation(0, "events1", false, 0);
            entry1.MixDuration = 0.25f;
            entry1.TrackEnd    = 1.0f;
            Run(0.1f, 1000, null);
#endif // RUN_ADDITIONAL_FORUM_RELATED_TEST

            Log("AnimationState tests passed.");
        }
示例#28
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Atlas atlas = new Atlas("data/goblins.atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin.
            skeleton.SetAttachment("left hand item", "spear");
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
示例#29
0
        protected override void LoadContent()
        {
            // Two color tint effect, comment line 80 to disable
            var spineEffect = Content.Load <Effect>("spine-xna-example-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;

            skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice);
            skeletonDebugRenderer.DisableAll();
            skeletonDebugRenderer.DrawClipping = true;

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

            if (name == "goblins-pro")
            {
                atlasName = "goblins-mesh";
            }
            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")
            {
                skeleton.SetAttachment("head-bb", "head");

                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, "run", true);
                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, "animation", true);
            }
            else if (name == "tank-pro")
            {
                skeleton.X += 300;
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X += 400;
            skeleton.Y += GraphicsDevice.Viewport.Height;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
示例#30
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

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

            Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            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 (true) {
                // Event handling for all animations.
                state.Start += new EventHandler(Start);
                state.End += new EventHandler(End);
                state.Complete += new EventHandler<CompleteArgs>(Complete);
                state.Event += new EventHandler<EventTriggeredArgs>(Event);

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

            skeleton.X = 320;
            skeleton.Y = 440;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
示例#31
0
        private SpatialTypeRecord Load(GraphicsDevice device, string contentPath)
        {
            SpatialTypeRecord record = new SpatialTypeRecord();

            using (Stream contentStream = TitleContainer.OpenStream(contentPath)) {
                using (XmlReader reader = XmlReader.Create(contentStream)) {
                    XmlSkeletonDefElement xmldef = new XmlSkeletonDefElement();
                    xmldef.ReadXml(reader);

                    Atlas atlas = new Atlas(xmldef.Atlas.Source, new XnaTextureLoader(device));
                    SkeletonJson json = new SkeletonJson(atlas);

                    record.Data = json.ReadSkeletonData(xmldef.Skeleton.Source);
                    record.DefaultAnimationMap = xmldef.BuildDefaultAnimationMap();
                    record.DirectedAnimationMap = xmldef.BuildDirectedAnimationMap();
                    record.ActivityMap = xmldef.BuildActivityMap();
                    record.DefaultAnimation = xmldef.ActivityMap.DefaultAnimation;
                }
            }

            _registered[contentPath] = record;
            return record;
        }
示例#32
0
    public SkeletonData GetSkeletonData(bool quiet)
    {
        if (atlasAssets == null) {
            atlasAssets = new AtlasAsset[0];
            if (!quiet)
                Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
            Reset();
            return null;
        }

        if (skeletonJSON == null) {
            if (!quiet)
                Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
            Reset();
            return null;
        }

        #if !SPINE_TK2D
        if (atlasAssets.Length == 0) {
            Reset();
            return null;
        }
        #else
        if (atlasAssets.Length == 0 && spriteCollection == null) {
            Reset();
            return null;
        }
        #endif

        Atlas[] atlasArr = new Atlas[atlasAssets.Length];
        for (int i = 0; i < atlasAssets.Length; i++) {
            if (atlasAssets[i] == null) {
                Reset();
                return null;
            }
            atlasArr[i] = atlasAssets[i].GetAtlas();
            if (atlasArr[i] == null) {
                Reset();
                return null;
            }
        }

        if (skeletonData != null)
            return skeletonData;

        AttachmentLoader attachmentLoader;
        float skeletonDataScale;

        #if !SPINE_TK2D
        attachmentLoader = new AtlasAttachmentLoader(atlasArr);
        skeletonDataScale = scale;
        #else
        if (spriteCollection != null) {
            attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection);
            skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale);
        } else {
            if (atlasArr.Length == 0) {
                Reset();
                if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
                return null;
            }
            attachmentLoader = new AtlasAttachmentLoader(atlasArr);
            skeletonDataScale = scale;
        }
        #endif

        try {
            //var stopwatch = new System.Diagnostics.Stopwatch();
            if (skeletonJSON.name.ToLower().Contains(".skel")) {
                var input = new MemoryStream(skeletonJSON.bytes);
                var binary = new SkeletonBinary(attachmentLoader);
                binary.Scale = skeletonDataScale;
                //stopwatch.Start();
                skeletonData = binary.ReadSkeletonData(input);
            } else {
                var input = new StringReader(skeletonJSON.text);
                var json = new SkeletonJson(attachmentLoader);
                json.Scale = skeletonDataScale;
                //stopwatch.Start();
                skeletonData = json.ReadSkeletonData(input);
            }
            //stopwatch.Stop();
            //Debug.Log(stopwatch.Elapsed);
        } catch (Exception ex) {
            if (!quiet)
                Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
            return null;
        }

        stateData = new AnimationStateData(skeletonData);
        FillStateData();

        return skeletonData;
    }
示例#33
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

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

            Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json"));
            if (name == "goblins") skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // 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);
            state.SetAnimation("walk", false);
            state.AddAnimation("jump", false);
            state.AddAnimation("walk", true);

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
示例#34
0
    void OnCurLoadFinish()
    {
        //先临时验证一下代码构造spine动画,两个atlas的设计问题较多,必须要休整一下播放组件
        GameObject curObj=new GameObject();
        curObj.name="spine-cur";
        SkeletonAnimationCL ani = curObj.AddComponent<SkeletonAnimationCL>();
        //AtlasAsset assAtlas = new AtlasAsset();
        //assAtlas.materials = new Material[1];
        //assAtlas.materials[0] = new Material(Shader.Find("Spine/Skeleton"));
        //assAtlas.materials[0].mainTexture = curAtlasTex;
        Dictionary<string, Texture2D> texs = new Dictionary<string, Texture2D>();
        texs["cur.png"] = curAtlasTex;
        var atlas = new Spine.Atlas(new System.IO.StringReader(curAtlas), "", new TextureLoad(texs));
        atlas.FlipV();
        //assAtlas.SetAtlas(atlas);

        Spine.SkeletonJson sjson = new Spine.SkeletonJson(atlas);
        sjson.Scale = 1.0f/64.0f;
        var data=sjson.ReadSkeletonData(new System.IO.StringReader(curSK));

        ani.skeleton = new Spine.Skeleton(data);
        ani.Reset();
        ani.state.SetAnimation(0, "idle", true);
    }
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            this.atlas = new Atlas("Content/crab.atlas", new XnaTextureLoader(GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);
            this.skeleton = new Skeleton(json.ReadSkeletonData("Content/crab-skeleton.json"));
            this.animationWalk = skeleton.Data.FindAnimation ("WalkLeft");
            this.animationJump = skeleton.Data.FindAnimation ("Jump");

            this.skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            this.animation = 0;
            this.SetSkeletonStartPosition ();

            // used for debugging - draw the bones
            this.lineTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            this.lineTexture.SetData(new[]{Color.White});
            this.textureMaps.Add(lineTexture);

            base.LoadContent ();
        }
		internal static SkeletonData ReadSkeletonData (string text, AttachmentLoader attachmentLoader, float scale) {
			var input = new StringReader(text);
			var json = new SkeletonJson(attachmentLoader) {
				Scale = scale
			};
			return json.ReadSkeletonData(input);
		}
示例#37
0
        protected override void LoadContent()
        {
            // Two color tint effect, comment line 76 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 = true;
            skeletonRenderer.Effect             = spineEffect;

            // String name = "spineboy";
            // String name = "goblins-mesh";
            // String name = "raptor";
            // String name = "tank";
            // String name = "coin";
            String name       = "TwoColorTest";
            bool   binaryData = true;

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

            float scale = 1;

            if (name == "spineboy")
            {
                scale = 0.6f;
            }
            if (name == "raptor")
            {
                scale = 0.5f;
            }
            if (name == "tank")
            {
                scale = 0.3f;
            }
            if (name == "TwoColorTest")
            {
                scale = 0.5f;
            }

            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-mesh")
            {
                skeleton.SetSkin("goblin");
            }

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

            state = new AnimationState(stateData);

            if (name == "spineboy")
            {
                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, "test", 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")
            {
                state.SetAnimation(0, "walk", true);
                state.AddAnimation(1, "gungrab", false, 2);
            }
            else if (name == "coin")
            {
                state.SetAnimation(0, "rotate", true);
            }
            else if (name == "tank")
            {
                state.SetAnimation(0, "drive", true);
            }
            else if (name == "TwoColorTest")
            {
                state.SetAnimation(0, "animation", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400 + (name == "tank" ? 300: 0);
            skeleton.Y = 580 + (name == "TwoColorTest" ? -300 : 0);
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
示例#38
0
        public CCSkeleton(string skeletonDataFile, string atlasFile, float scale = 0)
        {

            Initialize();

            using (StreamReader atlasStream = new StreamReader(CCFileUtils.GetFileStream(atlasFile)))
            {
                atlas = new Atlas(atlasStream, "", new CocosSharpTextureLoader());
            }

            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = scale == 0 ? (1 / Director.ContentScaleFactor) : scale;

            using (StreamReader skeletonDataStream = new StreamReader(CCFileUtils.GetFileStream(skeletonDataFile)))
            {
                SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataStream);
                skeletonData.Name = skeletonDataFile;
                SetSkeletonData(skeletonData, true);
            }
        }
示例#39
0
        public CCSkeleton(string skeletonDataFile, Atlas atlas, float scale = 0)
        {
            var json = new SkeletonJson(atlas);
			json.Scale = scale == 0 ? (1 / Director.ContentScaleFactor) : scale;
            SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataFile);
            SetSkeletonData(skeletonData, true);
        }
示例#40
0
        public CCSkeleton(string skeletonDataFile, string atlasFile, float scale = 0)
        {
            initialize();

            atlas = new Atlas(atlasFile, new MonoTextureLoader(CCDrawManager.GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = scale == 0 ? (1 / CCDirector.SharedDirector.ContentScaleFactor) : scale;

            SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataFile);
            setSkeletonData(skeletonData, true);
        }