【发布时间】:2015-08-19 14:27:12
【问题描述】:
我正在尝试为电脑游戏制作外部地图。
因此,我制作了一个带有图片框的表单应用程序,其中包含我的地图图像。
现在我想使用 GDI 在地图上绘制小方块。我已经使用Graphics.DrawRectangle 完成了这项工作。
现在我想每 0.2 秒更新一次矩形的位置。
我该怎么做?
我当前的来源(我不想用自动更新替换按钮):
public partial class Form1 : Form
{
//choords local player
int localX;
int localY;
int running;
const int Basex = 0x05303898;
const int Basey = 0x05303894;
const string Game = "ac_client";
//map drawing
Pen aPen = new Pen(Color.Black);
Graphics localp;
//choords enemy
//permission to read process memory
const int PROCESS_VM_READ = 0x0010; //needed for reading memory
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess,
int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (Process.GetProcessesByName(Game).Length > 0)
{
Process process = Process.GetProcessesByName(Game)[0];
IntPtr procHandle = OpenProcess(PROCESS_VM_READ, false, process.Id);
int bytesRead = 0;
byte[] buffer = new byte[24]; //'Hello World!' takes 12*2 bytes because of Unicode
// 0x0046A3B8 is the address where I found the string, replace it with what you found
ReadProcessMemory((int)procHandle, Basex, buffer, buffer.Length, ref bytesRead);
localX = BitConverter.ToInt32(buffer, 0);
LBlocalx.Text = Convert.ToString(Math.Ceiling(Convert.ToDecimal(localX)));
ReadProcessMemory((int)procHandle, Basey, buffer, buffer.Length, ref bytesRead);
localY = BitConverter.ToInt32(buffer, 0);
LBlocaly.Text = Convert.ToString(Math.Ceiling(Convert.ToDecimal(localY)));
localp = pictureBox1.CreateGraphics();
localp.DrawRectangle(aPen, (Convert.ToInt32(Convert.ToString(Math.Ceiling(Convert.ToDecimal(localX))))/1000), (Convert.ToInt32(Convert.ToString(Math.Ceiling(Convert.ToDecimal(localY))))/1000), 10, 10);
}
else
{
MessageBox.Show("Error! Process not running.");
}
}
【问题讨论】:
-
请提供更多信息。你在哪里存储绘制的正方形?向我们展示您当前的代码以及您尝试执行的操作。基本上,您需要清除每个“框架”的绘图,然后在适当的位置再次绘制所有正方形。除非您更具体,否则我们无法提供更多帮助
-
更新了我的帖子。我基本上想用自动更新来替换 button_click...
-
是在地图上绘制正方形还是将它们绘制到地图中,改变地图像素? - 通常你会使用一个计时器,改变你想要绘制的图形项目的数据并使 pb 无效。在它的绘制事件中,你绘制你的项目列表。这是在表面上绘制的方法。
-
它们将被绘制在地图上。
-
不要存储本地图形 localp。图形对象是您从绘画事件或图像中获得的临时对象。