0
我剛開始使用Monogame,我正在嘗試製作一個簡單的雪碧,後來就是一個按鈕。我搜索了所有內容並完成了幾個教程,但是我無法完成它。我只是不斷得到空白的藍屏。這裏是我的代碼:使用Monogame繪製雪碧
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
namespace Test_Game
{
class Main_Menu
{
//setting the variables
public Texture2D button1;
public Vector2 button1Pos;
public GraphicsDevice graphicsDevice;
GraphicsDeviceManager graphics;
public void initialize(Texture2D texture, Vector2 position, ContentManager Content)
{
//Getting the initialized stuff
button1 = Content.Load<Texture2D>("button_temp");
button1Pos.X = 30;
button1Pos.Y = 30;
}
public void Draw(SpriteBatch spriteBatch)
{
graphics.GraphicsDevice.Clear(Color.Black);
spriteBatch = new SpriteBatch(graphicsDevice);
//Just drawing the Sprite
spriteBatch.Begin();
spriteBatch.Draw(button1, new Rectangle(30, 30, 214, 101), Color.White);
spriteBatch.End();
}
}
}
希望你能找到答案。
空白藍屏 - 然後在您的畫圖中將其設置爲黑色。你是否從你的主要「game1」類中調用了你的繪製方法? – harag