65.9K
CodeProject 正在变化。 阅读更多。
Home

在 Picturebox C#.Net 中的抛物线运动

2013 年 3 月 10 日

CPOL
viewsIcon

22263

downloadIcon

1458

引言

C#.Net 包含大量的库和命名空间。当考虑需要弹道或双曲线运动的应用程序时。 在此背景下,C#.Net 提供了 System.Drawing 库和 Point 类,用于在不同的轴 (x,y) 上绘制点。 使用 for 循环 和其他技术实现抛物线运动会给程序员带来复杂性和编码开销。 此技术将帮助你使用计时器和图形逻辑创建抛物线运动。

 

 

 

 

 

 

背景

在 C#.Net 中很难实现抛物线运动。 当将一个位置放在 Windows 窗体上时,它会立即触发,这是不同的学生和专业人员面临的常见问题。

使用代码 

此图将帮助用户在 C#.Net 中绘制任何运动。 轴在上面的图像中已定义和描述

public Form1()
        {
            InitializeComponent();
        }
        int TimerCounter = 0;
        byte Duck_Pos = 5; 
       void Duck_SmallJump()
        {
            TimerCounter++;
            if (TimerCounter <= 10)
                duck.Location = new Point(duck.Location.X - 4, duck.Location.Y - 6);
            else if (TimerCounter > 10 && TimerCounter <= 15)
                duck.Location = new Point(duck.Location.X - 6, duck.Location.Y - 4);
            else if (TimerCounter > 15 && TimerCounter <= 20)
                duck.Location = new Point(duck.Location.X - 8, duck.Location.Y + 4);
            else if (TimerCounter > 20 && TimerCounter <= 30)
                duck.Location = new Point(duck.Location.X - 8, duck.Location.Y + 6);

            else
            {
                timer1.Enabled = false;
                TimerCounter = 0;
                Duck_Pos -= 1;
            }
        } 

要点             

 在窗体设计中,名为 Double Buffered 的属性应设置为 true 以最大限度地减少 pictureBox 的延迟。 

历史 

定义维度始终是编程中的关键领域,识别轴的位置并在该位置放置新点通常是一项复杂的任务。 

© . All rights reserved.