源代码:(还有一堆没用的,没贴)
namespace Sprite_Demo
{
public partial class Form1 : Form
{
private bool p_gameOver = false;
private int p_startTime = 0;
private int p_currentTime = 0;
public Game game;
public Bitmap dragonImage;
public Sprite dragonSprite;
public Bitmap grass;
public int frameCount = 0;
public int frameTimer = 0;
public float frameRate = 0;
public PointF velocity;
public int direction = 2;
private void Form1_Load(object sender, EventArgs e)
{
Main();
}
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
Game_KeyPressed(e.KeyCode);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Shutdown();
}
public void Main()
{
Form form = (Form)this;
game = new Game(ref form, 800, 600);
//load and initialize game assets
Game_Init();
while (!p_gameOver)
{
//update timer
p_currentTime = Environment.TickCount;
//let gameplay code update
Game_Update(p_currentTime - p_startTime);
//refresh at 60 FPS
if (p_currentTime > p_startTime + 16)
{
//update timing
p_startTime = p_currentTime;
//let gameplay code draw
Game_Draw();
//give the form some cycles
Application.DoEvents();
//let the game object update
game.Update();
}
frameCount += 1;
if (p_currentTime > frameTimer + 1000)
{
frameTimer = p_currentTime;
frameRate = frameCount;
frameCount = 0;
}
}
//free memory and shut down
Game_End();
Application.Exit();
} }
}
namespace Sprite_Demo
{
public partial class Form1 : Form
{
private bool p_gameOver = false;
private int p_startTime = 0;
private int p_currentTime = 0;
public Game game;
public Bitmap dragonImage;
public Sprite dragonSprite;
public Bitmap grass;
public int frameCount = 0;
public int frameTimer = 0;
public float frameRate = 0;
public PointF velocity;
public int direction = 2;
private void Form1_Load(object sender, EventArgs e)
{
Main();
}
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
Game_KeyPressed(e.KeyCode);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Shutdown();
}
public void Main()
{
Form form = (Form)this;
game = new Game(ref form, 800, 600);
//load and initialize game assets
Game_Init();
while (!p_gameOver)
{
//update timer
p_currentTime = Environment.TickCount;
//let gameplay code update
Game_Update(p_currentTime - p_startTime);
//refresh at 60 FPS
if (p_currentTime > p_startTime + 16)
{
//update timing
p_startTime = p_currentTime;
//let gameplay code draw
Game_Draw();
//give the form some cycles
Application.DoEvents();
//let the game object update
game.Update();
}
frameCount += 1;
if (p_currentTime > frameTimer + 1000)
{
frameTimer = p_currentTime;
frameRate = frameCount;
frameCount = 0;
}
}
//free memory and shut down
Game_End();
Application.Exit();
} }
}
解决方案 »
- C#使用权举时定义两个类出现问题(上下文不存在名称:XX)
- 这段deflate解压缩代码有何问题,为什么不能读出数据
- 关于treeview的问题
- 串口通讯中的定时保存串口数据问题?我用的是serialport类.
- 关于发送消息点击弹出对话框的[确定]按钮问题,在线急等,解决就结贴!
- 求正则表达式! 以8和9开头的6位数字
- 连载,LINQ兵法十四章,3(1of1)
- C#新手问个泛型的问题
- 【求助】大家给看看,这个错误提示是什么意思?如何解决?
- 有关ListView 控件的问题?
- c# 传字符串到 标准dll 程序退出时崩溃
- 应届生写一个小程序(c#)[论坛灌水机],大家帮忙看下.帮顶者皆有分的啊!!
MSDN上面是这样说明的:此方法由公共方法 Dispose 和 Finalize 方法调用。Dispose 调用 disposing 参数设置为 true 的受保护方法 Dispose(Boolean)。Finalize 调用 disposing 设置为 false 的 Dispose 的方法。当 disposing 参数为 true 时,此方法释放该 Form 引用的、由任何托管对象持有的全部资源。此方法调用每个引用对象的 Dispose 方法。给继承者的说明 Dispose 可以由其他对象多次调用。重写 Dispose(Boolean) 时,请注意不要引用在以前调用 Dispose 时已释放的对象。你看看你的Shutdown(),Game_End()函数有没有做特殊处理。
你可以试作把一些代码屏蔽,逐步缩小范围,直至最后确定问题点!