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. java TimeZone类

    TimeZone类主要是对时区的操作 下面是一个简单的例子 public static void main(String[] args) { // TODO Auto-generated method ...

  2. python之CSV文件格式

    1.csv文件是以一些以逗号分隔的值 import csv filename = "wenjian.csv" with open(filename) as f: reader = ...

  3. 【更新】用word文档来发布到csdn等博客上边免去一张张上传图片的烦恼

    目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...

  4. 淘宝IP地址库采集器c#

    个人原创.欢迎转载.转载请注明出处.http://www.cnblogs.com/zetee/articles/3482085.html 采集器概貌,如下: 最近做一个项目,功能类似于CNZZ站长统计 ...

  5. 【Linux】Linux各文件夹说明

    转载 /bin/ — 用来贮存普通命令. /sbin/ — 许多系统命令(例如 shutdown)的贮存位置.属于基本的系统命令,如shutdown,reboot,用于启动系统,修复系统./sbin目 ...

  6. VC++中GDI和GDI+ 的坐标系统介绍

    在Windows应用程序中,只要进行绘图,就要使用GDI坐标系统.Windows提供了几种映射方式,每一种映射都对应着一种坐标系.例如,绘制图形时,必须给出图形各个点在客户区的位置,其位置用x 和y两 ...

  7. Lazy<T> 提供对延迟初始化的支持

    延迟初始化  就是在第一次使用的时候在 进行类的初始化 public class Student { public Student() { this.Name = "DefaultName& ...

  8. shiro注解@RequiresPermissions多权限任选一参数用法

    @RequiresPermissions(value={"xxx:xxx","xxx:xxx"},logical=Logical.OR)

  9. map的回调函数

    问题:--js   (['1','2','3']).map(parseInt) 第一眼看到这个题目的时候,脑海跳出的答案是 [1, 2, 3],但是真正的答案是[1, NaN, NaN]. 首先让我们 ...

  10. asp.net—— 基础之截取字符串

    在实际开发中有时难免会遇到需要获取某个字符串中的某些字符串,这里我们可以用到字符串截取的办法. 截取字符串的方法很容易(暂不包含中文字符串),只要稍微有点.net基础的人看了都能看懂. /// < ...