XNA game studio LoadContent

江枫思渺然 提交于 2019-12-25 05:33:23

问题


I found a code to load multiple objects in XNA game stuido but can't call load contect method, what do I need to do? Do I need to call it another class besides Game1 or calling in game1 is just fine?

public override void LoadContent()
{
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);

    //Dictionary<string, Model> models = new Dictionary<string, Model>;

    mymodel = Content.Load<Model>("Models\\tableBasse2");

    aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

    backgroundTexture = Content.Load<Texture2D>("123");
    screenWidth = this.Window.ClientBounds.Width;
    screenHeight = this.Window.ClientBounds.Height;
}

//__http://stackoverflow.com/questions/4052532/xna-get-an-array-list-of-resources
public static Dictionary<string,Model> LoadContent

This load content not called in this line. I write this generally to show I call this LoadContent.


回答1:


To use Content you need to be in a class that inherits from GameComponent or DrawableGameComponent, because only Game class has it.

And then you can call it as:

Game.Content.Load<..>("path");


来源:https://stackoverflow.com/questions/20088331/xna-game-studio-loadcontent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!