XNA项目基础

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 WindowsGame1

{

public class Game1 : Microsoft.Xna.Framework.Game

{

GraphicsDeviceManager graphics;

SpriteBatch spriteBatch;

SpriteFont FontofTimesNewRoman;

Model model;

Texture2D  texture;

public Game1()

{

graphics = new GraphicsDeviceManager(this);

//屏幕控制

this.graphics.PreferredBackBufferWidth = 1024;

this.graphics.PreferredBackBufferHeight = 768;

this.graphics.IsFullScreen = true;

Content.RootDirectory = "Content";

}

protected override void Initialize()

{

this.IsMouseVisible = true;//鼠标显示

this.Window.AllowUserResizing = true;//允许窗口最大化

base.Initialize();

}

protected override void LoadContent()

{

spriteBatch = new SpriteBatch(GraphicsDevice);

//加载content中的资源

model = Content.Load<Model>("model");

FontofTimesNewRoman = Content.Load<SpriteFont>("FontofTimesNewRoman");

texture = Content.Load<Texture2D>("texture");

}

protected override void UnloadContent()

{

}

protected override void Update(GameTime gameTime)

{

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

this.Exit();

//ESC退出

if (Keyboard.GetState().IsKeyDown(Keys.Escape))

this.Exit();

//键盘控制 退出全屏

KeyboardState keyb = Keyboard.GetState();

if (keyb.IsKeyDown(Keys.A))

{

this.graphics.ToggleFullScreen();

}

//鼠标控制 退出全屏

//Mouse.GetState().LeftButton==ButtonState.Pressed

MouseState mouse = Mouse.GetState();

if (mouse.LeftButton == ButtonState.Pressed)

{

this.graphics.ToggleFullScreen();

}

base.Update(gameTime);

}

protected override void Draw(GameTime gameTime)

{

GraphicsDevice.Clear(Color.CornflowerBlue);

spriteBatch.Begin();

//图片显示

spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);

//字体显示

string str = "times:" + gameTime.TotalGameTime.Seconds.ToString();

Vector2 ms = FontofTimesNewRoman.MeasureString(str);

Vector2 position;

position.X = (this.Window.ClientBounds.Width - ms.X) / 2.0f;

position.Y = (this.Window.ClientBounds.Height - ms.Y) / 2.0f;

spriteBatch.DrawString(FontofTimesNewRoman, str, position, Color.BlueViolet);

spriteBatch.End();

//model显示

Matrix world = Matrix.Identity;

Matrix view = Matrix.CreateLookAt(new Vector3(500, 0, 500), Vector3.One, Vector3.Up);

Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 500f);

model.Draw(world, view, projection);

base.Draw(gameTime);

}

}

}

注:字体,图片,模型需放到content目录下编译成xnb文件才能使用........

XNA项目基础的更多相关文章

  1. spring+springMVC+mybatis的框架项目基础环境搭建

    上一个项目在后台用到spring+springMVC+mybatis的框架,先新项目初步需求也已经下来,不出意外的话,应该也是用这个框架组合. 虽然在之前activiti相关的学习中所用到的框架也是这 ...

  2. 基于stm32的水质监测系统项目基础部分详细记录

    基于stm32的水质监测系统项目基础部分详细记录 软件环境:MDK5 硬件环境:STM32F103ZET6 开发板.颜色传感器.串口屏.串口打印机 搭建工程模板 在进行项目软件的撰写时,首先新建一个基 ...

  3. SpringBoot学习(一)—— web项目基础搭建

    首先我们在浏览器打开这个网站 https://start.spring.io/ 打开后可以看到以下页面 在这里我们可以快速搭建一个SpringBoot基础项目,填写和选择完相应的信息后,我们点击那个绿 ...

  4. MUI项目基础框架

    码云SVN仓库地址:https://gitee.com/lim2018/vx/tree/master MUI项目基础框架,底部导航栏切换 目录结构 index为入口页主体,sub1-4为要切换的子页面 ...

  5. 关于Linux开源项目基础组件make编译流程

     关于Linux开源项目基础组件make编译流程 非常多Linux开源项目都会用到编译出可运行文件的make.这个是有一套流程的. 首先,GNU构建系统:https://en.wikipedia. ...

  6. vue2.0+webpack+vuerouter+vuex+axios构建项目基础

    前言 本文讲解的是vue2.0+webpack+vuerouter+vuex+axios构建项目基础 步骤 1.全局安装webpack,命令 npm install webpack -g 注意,web ...

  7. 小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计

    笔记 4.微服务下电商项目基础模块设计     简介:微服务下电商项目基础模块设计 分离几个模块,课程围绕这个基础项目进行学习             小而精的方式学习微服务 1.用户服务       ...

  8. 使用eclipse和maven创建activiti项目基础配置

    项目组最近的项目使用到了activiti工作流,到处查找了一些资料后,初步完成任务.但是我所做的事只是在搭好的环境中调用接口和方法操作,因此自己尝试着也从搭建环境入手,以下是成功实现以后的记录. 实现 ...

  9. b2c项目基础架构分析(二)前端框架 以及补漏的第一篇名词解释

    继续上篇,上篇里忘记了也很重要的前端部分,今天的网站基本上是以一个启示页,然后少量的整页切换,大量的浏览器后台调用web服务局部.动态更新页面显示状态这种方式在运作的,从若干年前简单的ajax流行起来 ...

随机推荐

  1. Hadoop有点难

    从看<Hadoop权威指南>第一眼开始,我一直觉得Hadoop很难,很难.....看着这本书,我觉得好像是文言文,我是真的看不懂,我的一腔热血瞬间冷了下来!很幸运,但是也不幸运,我来到了一 ...

  2. spring 整合 mybatis (不含物理分页)

    http://www.mybatis.org/spring/mappers.html http://www.mybatis.org/spring/zh/mappers.html <?xml ve ...

  3. Matlab图像处理教程

    虽然典型算法的开发是基于理论支持的,但这些算法的实现几乎总是要求参数估计,并常常进行算法修正与候选求解方案的比较. MATLAB由LINPACK和EISPACK项目开发,最初用于矩阵处理.今天,MAT ...

  4. crontab基本操作部分

    一.cron服务 cron是一个linux下 的定时执行工具,可以在无需人工干预的情况下运行作业. service crond start    //启动服务 service crond stop  ...

  5. XJOI 3363 树4/ Codeforces 739B Alyona and a tree(树上差分+路径倍增)

    D. Alyona and a tree time limit per test  2 seconds memory limit per test  256 megabytes input  stan ...

  6. vs项目属性中的包含目录和库目录以及附加依赖项全都配置正确了,却还是提示:无法解析的外部符号

    这种情况下,很大可能是lib文件有问题 我是用vs编译下载的源代码文件得到的lib出现了如题的情况, 后来去网站上直接下载了lib文件,竟然解决了!-.-

  7. Linq实战 之 DataSet操作详解

    Linq实战 之 DataSet操作详解  一:linq to Ado.Net 1. linq为什么要扩展ado.net,原因在于给既有代码增加福利.FCL中在ado.net上扩展了一些方法. 简单一 ...

  8. 使用 dlv 调试go 程序

    目录 使用 dlv 调试smartraiden 一 正常启动 smartraiden 二 dlv 调试 三 dlv attach 使用 dlv 调试smartraiden by 白振轩 使用 dlv ...

  9. 关于C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF中微信可用的 全新修订

    在上一篇文章的代码 对于微信已失效 重新更新一边 效果图: 源代码 using System; using System.Runtime.InteropServices; using System.T ...

  10. cisco和h3c网络设备中一次性打印全部配置信息

    cisco的是全页打印配置信息的命令: #terminal length 0 #show run 华为和h3c的是: >screen-length 0 temporary >display ...