XNA项目基础
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项目基础的更多相关文章
- spring+springMVC+mybatis的框架项目基础环境搭建
上一个项目在后台用到spring+springMVC+mybatis的框架,先新项目初步需求也已经下来,不出意外的话,应该也是用这个框架组合. 虽然在之前activiti相关的学习中所用到的框架也是这 ...
- 基于stm32的水质监测系统项目基础部分详细记录
基于stm32的水质监测系统项目基础部分详细记录 软件环境:MDK5 硬件环境:STM32F103ZET6 开发板.颜色传感器.串口屏.串口打印机 搭建工程模板 在进行项目软件的撰写时,首先新建一个基 ...
- SpringBoot学习(一)—— web项目基础搭建
首先我们在浏览器打开这个网站 https://start.spring.io/ 打开后可以看到以下页面 在这里我们可以快速搭建一个SpringBoot基础项目,填写和选择完相应的信息后,我们点击那个绿 ...
- MUI项目基础框架
码云SVN仓库地址:https://gitee.com/lim2018/vx/tree/master MUI项目基础框架,底部导航栏切换 目录结构 index为入口页主体,sub1-4为要切换的子页面 ...
- 关于Linux开源项目基础组件make编译流程
关于Linux开源项目基础组件make编译流程 非常多Linux开源项目都会用到编译出可运行文件的make.这个是有一套流程的. 首先,GNU构建系统:https://en.wikipedia. ...
- vue2.0+webpack+vuerouter+vuex+axios构建项目基础
前言 本文讲解的是vue2.0+webpack+vuerouter+vuex+axios构建项目基础 步骤 1.全局安装webpack,命令 npm install webpack -g 注意,web ...
- 小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计
笔记 4.微服务下电商项目基础模块设计 简介:微服务下电商项目基础模块设计 分离几个模块,课程围绕这个基础项目进行学习 小而精的方式学习微服务 1.用户服务 ...
- 使用eclipse和maven创建activiti项目基础配置
项目组最近的项目使用到了activiti工作流,到处查找了一些资料后,初步完成任务.但是我所做的事只是在搭好的环境中调用接口和方法操作,因此自己尝试着也从搭建环境入手,以下是成功实现以后的记录. 实现 ...
- b2c项目基础架构分析(二)前端框架 以及补漏的第一篇名词解释
继续上篇,上篇里忘记了也很重要的前端部分,今天的网站基本上是以一个启示页,然后少量的整页切换,大量的浏览器后台调用web服务局部.动态更新页面显示状态这种方式在运作的,从若干年前简单的ajax流行起来 ...
随机推荐
- HttpUploader2-queue版本
1.1 2016版本 目标: 1.大幅度优化JS代码,面向开发人员更加友好,逻辑清晰,代码简洁,便于阅读,定制开发,扩展,更加符合企业级应用需求. 2.大幅度使用并发技术来提高上传速度,与HttpUp ...
- Web环境中Spring的启动过程
1.spring不但可以在JavaSE环境中应用,在Web环境中也可以广泛应用,Spring在web环境中应用时,需要在应用的web.xml文件中添加如下的配置: …… <context-par ...
- imagelist用法
1.添加一个Imagelist控件,并双击控件图标如下图 2.点击新增按钮
- wpf Route Event Code Snippet
将下面内容保存为snippet后缀文件,通过vs的代码片段管理工具导入即可,快捷键请按需修改: <?xml version="1.0" encoding="utf- ...
- .Net Core使用OpenXML导出,导入Excel
导出Excel是程序很常用到的功能,.Net Core可以借助Open-XML-SDK来导出Excel. Open-XML-SDK open-xml-sdk是是微软开源的项目.Open XML SDK ...
- C# Winform Label内容根据其宽度自动调整字体大小
C# Winform Label内容根据其宽度自动调整字体大小 项目,有个要求,Label中显示的内容,能够根据其宽度自动调整字体的大小进行显示,刚刚开始的时候,总是想着通过不同的方法来直接测量内容的 ...
- random 随机生成字符串
# import random# for x in range(10):# i = 0# l = []# while i < 10:# ret = chr(random.randint(33, ...
- OCP最新题库收集,新版052考题及答案整理-19
19.Which is true about invalid PL/SQL objects? A) They are automatically recompiled against the new ...
- linux安装redis 完整步骤
原文连接:https://www.cnblogs.com/lauhp/p/8487029.html 安装: 1.获取redis资源 wget http://download.redis.io/rele ...
- python常用模块之OS
os模块偏于文件目录管理 <1>.常用方法 工作目录: os.getcwd() 返回当前工作目录 os.chdir(dir) 更改当前工作目录,相当于cd 目录文件操作: os.mkdir ...