コード例 #1
0
        /// <summary>
        /// Load background from WzImageProperty
        /// </summary>
        /// <param name="graphicsDevice">The graphics device that the backgroundInfo is to be rendered on (loading spine)</param>
        /// <param name="parentObject"></param>
        /// <param name="spineParentObject"></param>
        /// <param name="bS"></param>
        /// <param name="type"></param>
        /// <param name="no"></param>
        /// <returns></returns>
        private static BackgroundInfo Load(GraphicsDevice graphicsDevice, WzImageProperty parentObject, string bS, BackgroundInfoType type, string no)
        {
            WzCanvasProperty frame0;

            if (type == BackgroundInfoType.Animation)
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            }
            else if (type == BackgroundInfoType.Spine)
            {
                // TODO: make a preview of the spine image ffs
                WzCanvasProperty spineCanvas = (WzCanvasProperty)parentObject["0"];
                if (spineCanvas != null)
                {
                    // Load spine
                    WzSpineAnimationItem wzSpineAnimationItem = null;
                    if (graphicsDevice != null) // graphicsdevice needed to work.. assuming that it is loaded by now before BackgroundPanel
                    {
                        WzImageProperty spineAtlasProp = ((WzSubProperty)parentObject).WzProperties.FirstOrDefault(
                            wzprop => wzprop is WzStringProperty property && property.IsSpineAtlasResources);
                        if (spineAtlasProp != null)
                        {
                            WzStringProperty stringObj = (WzStringProperty)spineAtlasProp;
                            wzSpineAnimationItem = new WzSpineAnimationItem(stringObj);

                            wzSpineAnimationItem.LoadResources(graphicsDevice);
                        }
                    }

                    // Preview Image
                    Bitmap bitmap = spineCanvas.GetLinkedWzCanvasBitmap();

                    // Origin
                    PointF origin__ = spineCanvas.GetCanvasOriginPosition();

                    return(new BackgroundInfo(parentObject, bitmap, WzInfoTools.PointFToSystemPoint(origin__), bS, type, no, parentObject, wzSpineAnimationItem));
                }
                else
                {
                    PointF origin_ = new PointF();
                    return(new BackgroundInfo(parentObject, Properties.Resources.placeholder, WzInfoTools.PointFToSystemPoint(origin_), bS, type, no, parentObject, null));
                }
            }
            else
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject);
            }

            PointF origin = frame0.GetCanvasOriginPosition();

            return(new BackgroundInfo(frame0, frame0.GetLinkedWzCanvasBitmap(), WzInfoTools.PointFToSystemPoint(origin), bS, type, no, parentObject, null));
        }
コード例 #2
0
        /// <summary>
        /// Load spine related assets and contents
        /// </summary>
        protected override void LoadContent()
        {
            // Font
            spriteBatch = new SpriteBatch(GraphicsDevice);


            // Spine
            spineAnimationItem.LoadResources(graphicsDeviceMgr.GraphicsDevice);             //  load spine resources (this must happen after window is loaded)
            this.skeleton = new Skeleton(spineAnimationItem.SkeletonData);

            skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = spineAnimationItem.PremultipliedAlpha;

            // Skin
            foreach (Skin skin in spineAnimationItem.SkeletonData.Skins)
            {
                this.skeleton.SetSkin(skin.Name);                 // just set the first skin
                break;
            }

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

            state = new AnimationState(stateData);

            int i = 0;

            foreach (Animation animation in spineAnimationItem.SkeletonData.Animations)
            {
                state.SetAnimation(i++, animation.Name, true);
            }

            /*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 = 800;
            skeleton.Y = 600;
            skeleton.UpdateWorldTransform();
        }