コード例 #1
0
        /// <summary>
        /// loads a texture file (i.e. tga or bmp).
        /// </summary>
        /// <param name="fileName">image file name in the content folder</param>
        /// <returns>resource element</returns>
        public GameResourceTexture2D LoadTexture(string fileName)
        {
            string keyName = Path.GetFileName(fileName);

            //  Find the texture resource from ResourceManager by file name
            GameResourceTexture2D resource = GetTexture2D(keyName);

            //  If can't find stored resource
            if (resource == null)
            {
                LoadContent <Texture2D>(keyName, fileName);

                resource = GetTexture2D(keyName);
            }

            //  Can't get resource If loading failed!
            if (resource == null)
            {
                throw new ArgumentException("Fail to loaded texture : " + fileName);
            }
            else if (resource.Texture2D.IsDisposed)
            {
                throw new InvalidOperationException(
                          "Already disposed texture : " + fileName);
            }

            return(resource);
        }
コード例 #2
0
ファイル: TracerBullet.cs プロジェクト: GodLesZ/svn-dump
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="instanceCount">creating instance count</param>
        /// <param name="textureFileName">texture file name</param>
        public TracerBullets(int id, int instanceCount, string textureFileName, 
                            GameSceneNode sceneParent)
        {
            this.id = id;

            textureResource = FrameworkCore.ResourceManager.LoadTexture(textureFileName);

            bullets = new BulletObject[instanceCount];

            //  Create instance bullets
            for (int i = 0; i < bullets.Length; i++)
            {
                bullets[i] = new BulletObject(i);
            }

            tracerBulletBillboard = new GameBillboard();
            tracerBulletBillboard.Create(instanceCount, textureResource.Texture2D, 
                                        RenderingSpace.World, false);

            tracerBulletBillboard.SourceBlend = Blend.SourceAlpha;
            tracerBulletBillboard.DestinationBlend = Blend.One;
            tracerBulletBillboard.BlendFunction = BlendFunction.Add;
            tracerBulletBillboard.AlphaBlendEnable = true;
            tracerBulletBillboard.DepthBufferEnable = true;
            tracerBulletBillboard.DepthBufferWriteEnable = false;
            tracerBulletBillboard.DepthBufferFunction = CompareFunction.Less;
            tracerBulletBillboard.AlphaFunction = CompareFunction.Greater;
            tracerBulletBillboard.CullMode = CullMode.None;

            sceneParent.AddChild(tracerBulletBillboard);
        }
コード例 #3
0
        /// <summary>
        /// loads a resource file in the content folder.
        /// </summary>
        /// <typeparam name="T">resource type (i.e. Model or Texture2D)</typeparam>
        /// <param name="key">resource key name</param>
        /// <param name="filePath">resource file name</param>
        /// <returns>resource element</returns>
        public GameResourceBase LoadContent <T>(string key, string filePath)
        {
            if (FrameworkCore.Game.GraphicsDevice == null)
            {
                throw new InvalidOperationException("No graphics device.");
            }

            GameResourceBase resource = FindResourceByKey(key);

            if (resource != null)
            {
                return(resource);
            }

            //  loads a resource by content manager
            T obj = contentManager.Load <T>(filePath);

            if (obj == null)
            {
                throw new ArgumentException("Fail to load content (" + key +
                                            " : " + filePath + ")");
            }

            if (obj is Texture2D)
            {
                resource = new GameResourceTexture2D(key, filePath,
                                                     obj as Texture2D);
            }
            else if (obj is Model)
            {
                resource = new GameResourceModel(key, filePath, obj as Model);
            }
            else if (obj is AnimationSequence)
            {
                resource = new GameResourceAnimation(key, filePath,
                                                     obj as AnimationSequence);
            }
            else if (obj is SpriteFont)
            {
                resource = new GameResourceFont(key, filePath, obj as SpriteFont);
            }
            else if (obj is Effect)
            {
                resource = new GameResourceEffect(key, filePath, obj as Effect);
            }
            else
            {
                throw new NotSupportedException("Not supported the resource");
            }

            if (debugTrace)
            {
                System.Diagnostics.Debug.WriteLine(
                    string.Format("Load Resource : {0} ({1})",
                                  filePath, resource.ToString()));
            }

            if (AddResource(resource))
            {
                return(resource);
            }

            return(null);
        }