WP7小问题,此代码用Windows就没问题

parcool 2011-06-04 04:08:23
这是WP7的代码,一运行就自动关了,书上的源码,但是如果项目是windows game的话能正常。求解答!
Game1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace WPGameTest1
{

public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

Camera camera;//

VertexPositionTexture[] verts;////
VertexBuffer vertexBuffer;//

BasicEffect effect;//
Matrix worldTranslation = Matrix.Identity;//
Matrix worldRotation = Matrix.Identity;//
List<String> btnArr = new List<String>();//这是定义MessageBox.Show()的按钮数组
Texture2D texture;


public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
TargetElapsedTime = TimeSpan.FromTicks(333333);
}


protected override void Initialize()
{

camera = new Camera(this, new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);//
Components.Add(camera);//

base.Initialize();
}

protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = Content.Load<Texture2D>(@"Textures\Trees");
verts = new VertexPositionTexture[4];
verts[0] = new VertexPositionTexture(
new Vector3(-1, 1, 0), new Vector2(0, 0));
verts[1] = new VertexPositionTexture(
new Vector3(1, 1, 0), new Vector2(1, 0));
verts[2] = new VertexPositionTexture(
new Vector3(-1, -1, 0), new Vector2(0, 1));
verts[3] = new VertexPositionTexture(
new Vector3(1, -1, 0), new Vector2(1, 1));

//设置数据 到VertexBuffer
vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture),
verts.Length, BufferUsage.None);////
vertexBuffer.SetData(verts);//

// Initialize the BasicEffect
effect = new BasicEffect(GraphicsDevice);//

btnArr.Add("确定");//
btnArr.Add("取消");//
RasterizerState rs = new RasterizerState();
rs.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rs;

}

protected override void UnloadContent()
{

}


protected override void Update(GameTime gameTime)
{

if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();


worldTranslation *= Matrix.CreateTranslation(-0.002f, 0, 0);
worldRotation *= Matrix.CreateFromYawPitchRoll(MathHelper.PiOver4 / 60,0,0);

base.Update(gameTime);
}


protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

GraphicsDevice.SetVertexBuffer(vertexBuffer);//

effect.World = worldRotation * worldTranslation;
effect.View = camera.view;
effect.Projection = camera.projection;
effect.Texture = texture;
effect.TextureEnabled = true;

// Begin effect and draw for each pass
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
(PrimitiveType.TriangleStrip, verts, 0, 2);
}

base.Draw(gameTime);
}

}
}


Camera.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace WPGameTest1
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class Camera : Microsoft.Xna.Framework.GameComponent
{
public Matrix view { get; protected set; }
public Matrix projection { get; protected set; }

public Camera(Game game, Vector3 pos, Vector3 target, Vector3 up)
: base(game)
{
view = Matrix.CreateLookAt(pos, target, up);//摄像机的:坐标 目标 朝向
projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.PiOver4,
(float)Game.Window.ClientBounds.Width /
(float)Game.Window.ClientBounds.Height,
1, 100);//摄像机的:视角弧度,通常是45度或者π/4 摄像机长宽比,通常使用屏幕宽度除以屏幕高度 最近看清距离 最远看清距离
}

/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization code here

base.Initialize();
}

/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here

base.Update(gameTime);
}
}
}
...全文
102 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
beyondma 2011-06-04
  • 打赏
  • 举报
回复
这是WP7的代码,一运行就自动关了,书上的源码,但是如果项目是windows game的话能正常。求解答!
什么意思这是?这不就是XNA的代码吗?一运行就自动关了说的是什么意思?加断点了吗,到哪关的?
parcool 2011-06-04
  • 打赏
  • 举报
回复
不会吧,看来我也得去javaeye了。。。
parcool 2011-06-04
  • 打赏
  • 举报
回复
..没人能分析下么?

567

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧