即使定時器始終以100的間隔值開啓,我的代碼也不會使用tmrMoving
(定時器),所以沒有理由我可以看到,但我希望這只是其中的一個,而且很簡單。代碼如下所示,我的程序不會調用要在C#中執行的代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace games1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
tmrMoving.Enabled = true;
Invalidate();
}
private void tmrMoving_Tick(object sender, object value, Type targetType,
object parameter, CultureInfo culture, EventArgs e)
{
var cursPoint = new System.Drawing.Point(Cursor.Position.X, Cursor.Position.Y);
var playerPoint = new System.Drawing.Point(player.Location.X, player.Location.Y);
var diff = new Point(Cursor.Position.X - playerPoint.X, Cursor.Position.Y - playerPoint.Y);
var speed = Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y);
if (speed > 10)
{
diff.X /= (int)(speed/10);
diff.Y /= (int)(speed/10);
}
player.Location = new System.Drawing.Point(player.Location.X + diff.X, player.Location.Y + diff.Y);
}
}
}
此鏈接到我的coding的圖像格式,如果你喜歡這種方式。
什麼是您的問題? – MajkeloDev 2015-04-01 10:00:42
你可以在代碼後面顯示相關行嗎? – 2015-04-01 10:00:53
我從來沒有見過這麼多參數的計時器事件處理程序 - 這是一個'System.Windows.Forms.Timer'嗎? – 2015-04-01 10:03:24