我想在C#(窗体)中制作迷你游戏,就像太空侵略者一样。飞船飞得很好,但我没有得到多个镜头,我有一个方法timer_Tick
来制作动画,当我按下空间拍摄时,第一个镜头工作正常,但第二个镜头。这一半位置的第一枪消失了。镜头是pictureBox
,我试过列表pictureBox
,但没有成功。迷你游戏形式
我有这样的事情:
public void Form1_Load(object sender, EventArgs e)
{
shootP = new PictureBox();
shootP.Image = Properties.Resources.shoot_1;
shootP.SizeMode = PictureBoxSizeMode.Zoom;
shootP.Size = new Size(10, 72);
ListShoot = new List<PictureBox>();
int i = -1;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
control = false;
i++;
ListShoot.Add(shootP);
timeShoot.Start();
}
private void timeShoot_Tick(object sender, EventArgs e)
{
if (control == false)
{
ListShoot[i].Location = new Point(spacecraft._imageBox.Location.X + 50, spacecraft._imageBox.Location.Y - 55); // align the shoot with spacecraft
control = true;
}
ListShoot[i].Top -= 40;
}
我在做什么错?
我想你必须在ListShoot.Add(shootP)后面添加ListShoot [i] .Location = new ...并完全移除if(control == false)子句,因为它被调用一次 –