怎么做2D的rpg小游戏的显示部分啊 比如 一张地图的图片,我按方向键,图片向反方向移动,刷新屏幕实现滚动用什么方法啊?计时器?循环?。大侠们帮帮忙啊,给个简单代码启发下我啊,我才学几天 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用Microsoft XNA可以做2D游戏,这也是C#呀,有很多现成例子可以参考。唯一缺点就是对显卡要求高了点 一般是移动摄像头,摄像头附在人上,地图是静止不动。但C#本就不是用来开发游戏的,也不是游戏引擎,一句话不适合。你真要做,那就把地图做成一张大的bitmap,存在内存,然后以人物所在位置为中心,计算出需要在屏幕上显示出来的那一部分地图。直接在这个方法中计算 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); }或是新建个线程控制帧数来显示都行。 using System;using System.Drawing;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); // 设置DoubleBuffer使得Form刷新时不会闪烁 this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); // 初始化背景图片 m_BackgroundImage = new Bitmap(@"C:\1.jpg"); // 初始化背景图片位置 m_Point = new Point(this.Width / 2 - m_BackgroundImage.Width / 2, this.Height / 2 - m_BackgroundImage.Height / 2); // 初始化每按一下移动的长度 m_Step = 2; } protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); switch (e.KeyCode) { // 按下左键,背景图右移一个step,并重绘背景 case Keys.Left: if (m_Point.X < 0) { m_Point = new Point(m_Point.X + m_Step, m_Point.Y); Invalidate(); } break; // 按下右键,背景图左移一个step,并重绘背景 case Keys.Right: if (m_Point.X > (this.Width - m_BackgroundImage.Width)) { m_Point = new Point(m_Point.X - m_Step, m_Point.Y); Invalidate(); } break; // 按下上键,背景图下移一个step,并重绘背景 case Keys.Up: if (m_Point.Y < 0) { m_Point = new Point(m_Point.X, m_Point.Y + m_Step); Invalidate(); } break; // 按下下键,背景图上移一个step,并重绘背景 case Keys.Down: if (m_Point.Y > (this.Height - m_BackgroundImage.Height)) { m_Point = new Point(m_Point.X, m_Point.Y - m_Step); Invalidate(); } break; default: break; } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // 画背景 DrawBackground(e); } private void DrawBackground(PaintEventArgs e) { e.Graphics.DrawImage(m_BackgroundImage, new Rectangle(m_Point.X, m_Point.Y, m_BackgroundImage.Width, m_BackgroundImage.Height), new Rectangle(0, 0, m_BackgroundImage.Width, m_BackgroundImage.Height), GraphicsUnit.Pixel); } // 背景图片 private Bitmap m_BackgroundImage; // 背景图片位置 private Point m_Point; // 每按一下移动的长度 private Int32 m_Step; }} 想找个Jquery.ui.datetimepicker下载 MDI子窗体的显示问题 怎么实现横轴(时间轴)的无限延伸 新手询问创建文件功能 各路朋友看过来?怎么得到Ctrl字串? 如何从dll中 提取公共函数以及参数 ?(在线等候,立即结帖!) C#写了一个程序,系统占用惊人,如何解决? C#如何访问Oracle存储过程传入传出参数,过程参数为自定义类型? 急!(高分求助+在线等待:) C#WINDOWS程序MDI的问题 如何把程序中的参数传给SQL语句? 如何把多个byte[]数组放到一个中去 怎么由IP获得计算机 ?
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
或是新建个线程控制帧数来显示都行。
using System;
using System.Drawing;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); // 设置DoubleBuffer使得Form刷新时不会闪烁
this.SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.UserPaint
| ControlStyles.ResizeRedraw,
true);
} protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// 初始化背景图片
m_BackgroundImage = new Bitmap(@"C:\1.jpg"); // 初始化背景图片位置
m_Point = new Point(this.Width / 2 - m_BackgroundImage.Width / 2, this.Height / 2 - m_BackgroundImage.Height / 2); // 初始化每按一下移动的长度
m_Step = 2;
} protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
switch (e.KeyCode)
{
// 按下左键,背景图右移一个step,并重绘背景
case Keys.Left:
if (m_Point.X < 0)
{
m_Point = new Point(m_Point.X + m_Step, m_Point.Y);
Invalidate();
}
break;
// 按下右键,背景图左移一个step,并重绘背景
case Keys.Right:
if (m_Point.X > (this.Width - m_BackgroundImage.Width))
{
m_Point = new Point(m_Point.X - m_Step, m_Point.Y);
Invalidate();
}
break;
// 按下上键,背景图下移一个step,并重绘背景
case Keys.Up:
if (m_Point.Y < 0)
{
m_Point = new Point(m_Point.X, m_Point.Y + m_Step);
Invalidate();
}
break;
// 按下下键,背景图上移一个step,并重绘背景
case Keys.Down:
if (m_Point.Y > (this.Height - m_BackgroundImage.Height))
{
m_Point = new Point(m_Point.X, m_Point.Y - m_Step);
Invalidate();
}
break;
default:
break;
}
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e); // 画背景
DrawBackground(e);
} private void DrawBackground(PaintEventArgs e)
{
e.Graphics.DrawImage(m_BackgroundImage,
new Rectangle(m_Point.X, m_Point.Y, m_BackgroundImage.Width, m_BackgroundImage.Height),
new Rectangle(0, 0, m_BackgroundImage.Width, m_BackgroundImage.Height),
GraphicsUnit.Pixel);
} // 背景图片
private Bitmap m_BackgroundImage;
// 背景图片位置
private Point m_Point;
// 每按一下移动的长度
private Int32 m_Step;
}
}