Beispiel #1
0
        public PiecePrefab(RenderContext context, Collision name, string assetFile, float scaleX = 1.0f, float scaleY = 1.0f)
        {
            //Set Name
            Name    = name;
            Scale.X = scaleX;
            Scale.Y = scaleY;

            //Set Model
            if (m_Model == null)
            {
                if (!File.Exists("Content/Model/m_" + assetFile + ".xnb"))
                {
                    m_Model = context.Content.Load <Model>("Model/Default");
                    Console.WriteLine("Failed to load model " + assetFile);
                }
                else
                {
                    m_Model = context.Content.Load <Model>("Model/m_" + assetFile);
                }
            }

            //Create RigidBody
            if (m_Body == null)
            {
                var collisionTexture = context.Content.Load <Texture2D>("Textures/Collision/c_" + assetFile);
                BodyFromTexture.CreateBodyFromImage(ref m_Body, context.Game, context.World, collisionTexture, scaleX, scaleY);
                Size            = new Vector2(collisionTexture.Width, collisionTexture.Height);
                m_Body.UserData = this;
                m_Body.BodyType = BodyType.Static;
                m_Body.Enabled  = false;
            }

            if (!File.Exists("Content/Textures/Models/D_" + assetFile + ".xnb"))
            {
                Console.WriteLine("GroundPrefab:: Missing Textures for " + assetFile);
            }
            else
            {
                TextureData.Diffuse = context.Content.Load <Texture2D>("Textures/Models/D_" + assetFile);
            }
        }
Beispiel #2
0
        public GroundPrefab(RenderContext context, Collision name, string modelFile, string collisionFile)
        {
            Name = name;

            if (m_Model == null)
            {
                m_Model = context.Content.Load <Model>(modelFile);
                Console.WriteLine("Load Model");
            }

            if (m_Body == null)
            {
                //Load the texture
                m_Texture = context.Content.Load <Texture2D>(collisionFile);
                BodyFromTexture.CreateBodyFromImage(ref m_Body, context.Game, context.World, m_Texture);
                m_Body.UserData = new Vector2(m_Texture.Width, m_Texture.Height);
                m_Body.BodyType = BodyType.Static;
                m_Body.Enabled  = false;
                Console.WriteLine("Load Collision Body of Ground");
            }
        }