コード例 #1
0
        /// <summary>
        /// Load a DrawableAnimated XML file.
        /// </summary>
        /// <param name="name">Name of XML file</param>
        /// <returns>Newly loaded DrawableAnimated</returns>
        public DrawableAnimated loadDrawableAnimated(String name)
        {
            // Verify this DrawableAnimated has not already been loaded
            if (_objects.ContainsKey(name))
            {
                return(_objects[name] as DrawableAnimated);
            }

#if DEBUG
            Console.WriteLine("Loading DrawableAnimated: " + name);
#endif

            // Load data
            DrawableAnimatedData data = _contentMgr.Load <DrawableAnimatedData>(DIR_DRAWABLES + name);

            // Extract animation data
            int         animCount  = data.Animations.Count();
            Animation[] animations = new Animation[animCount];
            for (int i = 0; i < animCount; i++)
            {
                AnimationData animData = data.Animations[i];
                Animation     anim     = new Animation(
                    animData.Name,
                    animData.StartFrame,
                    animData.EndFrame,
                    animData.FrameTime,
                    animData.Looping);
                animations[i] = anim;
            }

            // Load new DrawableAnimated
            DrawableAnimated drawable = new DrawableAnimated(
                name,
                loadTexture(data.TextureName),
                data.Origin,
                data.FrameWidth,
                data.FrameHeight,
                data.FrameRows,
                data.FrameCols,
                animations);

            // Add to ContentManager
            addContentObject(drawable);
            return(drawable);
        }
コード例 #2
0
        /// <summary>
        /// Load a DrawableAnimated XML file.
        /// </summary>
        /// <param name="name">Name of XML file</param>
        /// <returns>Newly loaded DrawableAnimated</returns>
        public DrawableAnimated loadDrawableAnimated(String name)
        {
            // Verify this DrawableAnimated has not already been loaded
            if (_objects.ContainsKey(name))
                return _objects[name] as DrawableAnimated;

            #if DEBUG
            Console.WriteLine("Loading DrawableAnimated: " + name);
            #endif

            // Load data
            DrawableAnimatedData data = _contentMgr.Load<DrawableAnimatedData>(DIR_DRAWABLES + name);

            // Extract animation data
            int animCount = data.Animations.Count();
            Animation[] animations = new Animation[animCount];
            for (int i = 0; i < animCount; i++)
            {
                AnimationData animData = data.Animations[i];
                Animation anim = new Animation(
                    animData.Name,
                    animData.StartFrame,
                    animData.EndFrame,
                    animData.FrameTime,
                    animData.Looping);
                animations[i] = anim;
            }

            // Load new DrawableAnimated
            DrawableAnimated drawable = new DrawableAnimated(
                name,
                loadTexture(data.TextureName),
                data.Origin,
                data.FrameWidth,
                data.FrameHeight,
                data.FrameRows,
                data.FrameCols,
                animations);

            // Add to ContentManager
            addContentObject(drawable);
            return drawable;
        }