XNA4.0学习指南第五章代码中文注释(AI精灵子类)

1 using System;
2  using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7
8 namespace AnimatedSprites
9 {
10 class AutomatedSprite : Sprite
11 {
12
13 #region ■属性声明______________________________________________________________
14
15 /// <summary>
16 /// 用来让AI的精灵往这个方向移动的属性
17 /// </summary>
18 public override Microsoft.Xna.Framework.Vector2 direction
19 {
20 get
21 {
22 return speed;
23 }
24 }
25
26 #endregion
27
28 #region ■构造方法______________________________________________________________
29
30 // 两个构造方法唯一不同的地方是第二个方法需要一个用来计算动画速度的变量millisecondsPerFrame
31
32 /// <summary>
33 /// 构造方法
34 /// </summary>
35 /// <param name="textureImage">要绘制的精灵或精灵位图</param>
36 /// <param name="position">精灵被绘制的位置</param>
37 /// <param name="frameSize">精灵位图中单帧的尺寸</param>
38 /// <param name="collisionOffset">偏移量用来修改精灵碰撞检测中用到的包围矩形</param>
39 /// <param name="currentFrame">偏移量用来修改精灵碰撞检测中用到的包围矩形</param>
40 /// <param name="sheetSize">精灵位图中的行/列数</param>
41 /// <param name="speed">精灵来在X,Y方向移动的速度</param>
42 public AutomatedSprite(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed)
43 : base(textureImage, position, frameSize, collisionOffset, currentFrame, sheetSize, speed)
44 {
45 }
46
47 /// <summary>
48 /// 构造方法
49 /// </summary>
50 /// <param name="textureImage">要绘制的精灵或精灵位图</param>
51 /// <param name="position">精灵被绘制的位置</param>
52 /// <param name="frameSize">精灵位图中单帧的尺寸</param>
53 /// <param name="collisionOffset">偏移量用来修改精灵碰撞检测中用到的包围矩形</param>
54 /// <param name="currentFrame">偏移量用来修改精灵碰撞检测中用到的包围矩形</param>
55 /// <param name="sheetSize">精灵位图中的行/列数</param>
56 /// <param name="speed">精灵来在X,Y方向移动的速度</param>
57 /// <param name="millisecondsPerFrame">帧间等待的时间(毫秒数)</param>
58 public AutomatedSprite(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed, int millisecondsPerFrame)
59 : base(textureImage, position, frameSize, collisionOffset, currentFrame, sheetSize, speed, millisecondsPerFrame)
60 {
61 }
62
63 #endregion
64
65 #region ■成员方法______________________________________________________________
66
67 /// <summary>
68 /// AI精灵的更新方法
69 /// </summary>
70 /// <param name="gameTime">GameTime</param>
71 /// <param name="clientBounds">代表游戏窗口客户区矩形,用来检测物体何时越过了游戏窗口边缘</param>
72 public override void Update(GameTime gameTime, Rectangle clientBounds)
73 {
74 // 让AI精灵根据指定的方向移动
75 position += direction;
76 // 调用父类的更新方法
77 base.Update(gameTime, clientBounds);
78 }
79
80 #endregion
81 }
82 }

posted on 2011-04-12 12:46  Osiris_Syou  阅读(239)  评论(0编辑  收藏  举报

导航