问题描述
我正在使用c#来获取 winapp 。不适用于Unity或其他。
我的类
{
Lasers laser1 = new Lasers();
Lasers laser2 = new Lasers();
public Screen()
{
InitializeComponent();
DoubleBuffered = true ;
this .Paint + = new PaintEventHandler(Screen_Paint);
计时器timerforLaser = new Timer();
timerforLaser.Tick + = new EventHandler(Timer_forLaser_Tick);
timerforLaser.Interval = 100 ;
timerforLaser.Start();
....
laser1.Initialize();
laser2.Initialize();
}
void Screen_Paint( object sender,PaintEventArgs e)
{
........
e.Graphics.DrawImage(laser1.Img0,laser1.Rectangle); // LaserPaint
e.Graphics.DrawImage(laser2.Img0,laser2.Rectangle); // LaserPaint
}
void Timer_forLaser_Tick( object sender,EventArgs e)
{
laser1.ShootUp();
laser2.ShootUp();
this .Refresh(); // 非常重要 - 没有他这里没有任何作用
}
private void Screen_KeyDown( object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
laser1.New( Player.X,Player.Y);
laser2.New(Player.X,Player.Y);
}
this .Refresh(); // 非常重要 - 没有他这里没有任何作用
}
}
从我发布的代码中,当我按空格键时,它将在屏幕上创建2个激光图像并在计时器事件中更新它们。
问题在于它是一次创建它们,还是重叠的。
我希望他们一个接一个地创建。像一阵爆发。彼此之间的时间很短。并没有重叠。
我想我必须以某种方式在每个激光的起始点之间放一个计时器,只要我按住Space键。或者某种延迟。如果我必须创建100个激光器,我可能会创建一个包含所有激光器的阵列?我不知道如何让这件事发挥作用。
非常感谢。
我尝试过:
一切
一切
一切
一切
一切
一切
I am using c# for winapp. Not for Unity or whatever.
my class { Lasers laser1 = new Lasers(); Lasers laser2 = new Lasers(); public Screen() { InitializeComponent(); DoubleBuffered = true; this.Paint += new PaintEventHandler(Screen_Paint); Timer timerforLaser = new Timer(); timerforLaser.Tick += new EventHandler(Timer_forLaser_Tick); timerforLaser.Interval = 100; timerforLaser.Start(); .... laser1.Initialize(); laser2.Initialize(); } void Screen_Paint(object sender, PaintEventArgs e) { ........ e.Graphics.DrawImage(laser1.Img0, laser1.Rectangle);//LaserPaint e.Graphics.DrawImage(laser2.Img0, laser2.Rectangle);//LaserPaint } void Timer_forLaser_Tick(object sender, EventArgs e) { laser1.ShootUp(); laser2.ShootUp(); this.Refresh(); //very Important -without him here nothing works } private void Screen_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { laser1.New(Player.X, Player.Y); laser2.New(Player.X, Player.Y); } this.Refresh(); //very Important -without him here nothing works } }
From the code i post, when I press Space key, it will create 2 lasers images on the screen and update them in the timer event.
The problem is that is creating them at once, and overlapped.
I want them created 1 after another. Like a burst. With a short time between each other. And no overlaps.
I imagine i must put a timer between the starting point of each laser somehow, as long as i keep pressed the Space key. Or a delay of some sort. And if i have to create 100 lasers, i will probably create an array that will contain all the lasers? I have no idea how to make this thing work.
Thank you kindly.
What I have tried:
everything
everything
everything
everything
everything
everything
这篇关于怎么让激光飞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!