我正在尝试在 XNA 中构建 3d 菜单,它显示 NotImplementedException 错误。一个有四个按钮可供选择的菜单。我错过了这个项目中的任何内容吗?我是 XNA 的新手。代码如下。提前致谢。
//ModelMenuGame.cs
public class ModelMenuGame : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
Model menuItemModel;
Vector3 cameraPosition;
Matrix view;
Matrix projection;
List<ModelMenuItem> Menu;
int TotalMenuItems = 4;
Rectangle LeftRegion;
Rectangle RightRegion;
int currentIndex = 0;
public event EventHandler OnTap;
public ModelMenuGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
TargetElapsedTime = TimeSpan.FromTicks(333333);
InactiveSleepTime = TimeSpan.FromSeconds(1);
}
protected override void Initialize()
{
cameraPosition = new Vector3(-40, 10, 40);
view = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1.0f, 1000.0f);
Menu = new List<ModelMenuItem>();
LeftRegion = new Rectangle(0, 0, GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height);
RightRegion = new Rectangle(GraphicsDevice.Viewport.Width / 2, 0, GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height);
OnTap = new EventHandler(Item_OnTap);
currentIndex = currentIndex % TotalMenuItems;
if (currentIndex < 0)
{
currentIndex = TotalMenuItems - 1;
}
else if(currentIndex > TotalMenuItems - 1)
{
currentIndex = 0;
}
foreach (ModelMenuItem item in Menu)
{
if (item.Index == currentIndex)
{
item.Selected = true;
}
else
{
item.Selected = false;
}
}
menuItemModel = Content.Load<Model>("ModelMenuItem3D");
font = Content.Load<SpriteFont>("gameFont");
for (int i = 0; i < TotalMenuItems; i++ )
{
int X = -20;
ModelMenuItem item = new ModelMenuItem(this, menuItemModel, view, projection);
item.Translation = new Vector3(X + (i * 20), 0, 0);
item.Index = i;
Menu.Add(item);
}
Menu[0].Selected = true;
base.Initialize();
}
private void Item_OnTap(object sender, EventArgs e)
{
throw new NotImplementedException();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
Vector2 tapPosition = new Vector2();
TouchCollection touches = TouchPanel.GetState();
if (touches.Count > 0 && touches[0].State == TouchLocationState.Pressed)
{
tapPosition = touches[0].Position;
Point point = new Point((int)tapPosition.X, (int)tapPosition.Y);
if (LeftRegion.Contains(point))
{
--currentIndex;
OnTap(this, null);
}
else if (RightRegion.Contains(point))
{
++currentIndex;
OnTap(this, null);
}
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.BlendState = BlendState.AlphaBlend;
foreach (ModelMenuItem item in Menu)
{
item.Draw();
}
spriteBatch.Begin();
spriteBatch.DrawString(font , "Current Index :" + currentIndex.ToString(),new Vector2(0, 0), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}