采用xna4.0 来作为学习的框架,采用《xna4.0学习指南》作为教程。
简单记录一下xna学习过程:
时间2:00-5:00
Game1主要对象
GraphicsDeviceManager graphics; 访问图形设备
SpriteBatch spriteBatch; 绘制图形
Game1主要方法:
Initialize 初始化对象
LoadContent 载入图形资源
UnloadContent 卸载
Update 内容数据更新
Draw 画面更新
使用到的对象
GameTime 游戏时间
装载显示图片
通过 内容管道,装载图形声音,其他。
在xxxContent项目中添加文件夹,添加 现有项,
Texture2D apple = Content.Load<Texture2D>(@"images/1");
绘制图形
spriteBatch.Begin();
spriteBatch.Draw(apple, Vector2.Zero, Color.White); 对象,坐标,染色
spriteBatch.End();
获得窗口大小
window.ClientBounds.Width
获得透明的图片
1使用png,增加a值,使用透明背景,2设置颜色为255,0,255这种颜色。
变形
Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth);
对象 左上角位置 绘制图像一部分 染色颜色 旋转角度 旋转中心 缩放比例 垂直水平翻转 层叠次序
遮盖,层叠次序,
spriteBatch.Begin();如果启动需要2个参数
SpriteSortMode. BlendState
Deferred 延迟,默认 AlphaBlend混合
Immediate 最快 NonPremultiplied
Texture 按照纹理来排序
BackToFront
FrontToBack
混合颜色
在学习玩之后,可以实现图片的显示和位置的变化。