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. opencv常用函数备忘

    //显示图片 IplImage * src = cvLoadImage("xx.JPG"); cvNamedWindow(); cvShowImage("show_ima ...

  2. 结构光和ToF

  3. scala学习(idea编译过程https://blog.csdn.net/guiying712/article/details/68947747)

    scala官网 https://www.scala-lang.org/ 菜鸟教程学习 http://www.runoob.com/scala/scala-basic-syntax.html w3sch ...

  4. 创建 ASP.NET Web API的Help Page

    转:创建WEBAPI项目 转:添加测试API中的ASP.NET Web API帮助页面

  5. TestNG+Selenium

    是一个开源自动化测试框架.其实类似于JUnit这种单元测试框架,但进行了一些功能扩展 属于selenium?还是说TestNG是一个测试框架,它用到了selenium的web自动化测试的功能,比如使用 ...

  6. System Workbench for STM32(based on Eclipse)开发环境配置

    导入现有项目 不能有同名项目,即使不是同一目录 编译 根目录的Debug目录是编译时自动生成的.另外如果项目使用了git,那么编译时会自动在根目录生成一个.gitignore文件,把Debug目录排除 ...

  7. Charles弱网测试

    当前APP网络环境比较复杂,网络制式有2G.3G.4G网络,还有越来越多的公共Wi-Fi.不同的网络环境和网络制式的差异,都会对用户使用app造成一定影响.另外,当前app使用场景多变,如进地铁.上公 ...

  8. ubuntu里面如何以root身份使用图形界面管理文件?

    nautilus 是gnome的文件管理器,但是如果不是root账号下,权限受限,我们可以通过以下方式以root权限使用! 一,快捷键“Ctrl+Alt+t”,调出shell. 二,在shell中输入 ...

  9. IO模型《四》多路复用IO

    多路复用IO(IO multiplexing) IO multiplexing这个词可能有点陌生,但是如果我说select/epoll,大概就都能明白了.有些地方也称这种IO方式为事件驱动IO (ev ...

  10. day03.1-函数编程

    python中函数的定义: def test (x,y): "The function definitions" z = x**y return z ""&qu ...