角色在我的C#游戏中走得很慢

角色在我的C#游戏中走得很慢,c#,performance,draw,C#,Performance,Draw,问题是,我不明白为什么我的角色在绘制图像时移动缓慢。所有计时器均设置为1个间隔,且从未更改。任何帮助都将不胜感激。以下是整个项目: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks

问题是,我不明白为什么我的角色在绘制图像时移动缓慢。所有计时器均设置为1个间隔,且从未更改。任何帮助都将不胜感激。以下是整个项目:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Rice_Boy_Tester_2
{
  public partial class Form1 : Form
  {
    bool iggy = false;
    bool left2 = false;
    bool right2 = false;
    bool Up2 = false;
    bool Down2 = false;
    bool Check2 = false;

    bool left = false;
    bool right = false;
    bool Up = false;
    bool Down = false;
    bool Check = false;

    public Form1() {
        InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e) {
        // Empty block
    }


    private void Refresh_Tick(object sender, EventArgs e) {
        this.Refresh();

    }

    private void PriceBoyWalk_Tick(object sender, EventArgs e) {
        if (left) // Goes Left
            Player.Left -= 1;

        if (Player.Left < 170 & Check == false) {
            // Checks how far away player is from form
            left = false;
            Up = true;
        }
        if (Up & Player.Left < 170) { // Goes Up
            Player.Top -= 1;
            Check = true;
        }

        if (Player.Top < 100 & Check) {
            Up = false;
            Down = true;

        }

        if (right) // Goes Right
            Player.Left += 1;

        if (Down) // Goes Down
            Player.Top += 1;

        if (Player.Top + 150 > this.ClientSize.Height) {
            Check = false;
            Down = false;
            right = true;
        }


        if (Player.Left + 150 > this.ClientSize.Width)
            right = false;

    }
    private void B1_Click(object sender, EventArgs e) {
        this.Paint += new PaintEventHandler(form1_Pad1_Rice);
        RiceBoyWalkGif.Enabled = true;
        left = true;
        left2 = true;
        RiceBoyWalk.Enabled = true;

    }

    private void timer1_Tick(object sender, EventArgs e) {
        if (left2) {
            Player.Image = Image.FromFile("Rice-Boy-Walking-Left-Bouncing.gif"); // Animates RiceBoyWalkingLeft
            left2 = false;

        }
        if (Player.Left < 170 & Check2 == false) {
            // Checks how far away the player is from form
            left2 = false;
            Up2 = true;

        }
        if (Up2 & Player.Left < 170) { // Goes Up
            this.Player.Size = new System.Drawing.Size(36, 76); // Changes size of the picture box to maintain quality 
            Player.Image = Image.FromFile("Rice-Boy-Walking-Up-Bouncing.gif"); // Animates RiceBoyWalkingUp
            Check2 = true;
            Up2 = false;

        }

        if (Player.Top < 101 & Check2) {
            // Player.Top < 101 must be +1 greater than the RiceBoyWalkTimer
            Up2 = false;
            Down2 = true;

        }

        if (right2) {
            this.Player.Size = new System.Drawing.Size(53, 77); // Changes size of the picture box to maintain quality 
            Player.Image = Image.FromFile("Rice-Boy-Walking-Right-Bouncing.gif"); // Animates RiceBoyWalkingRight
            right2 = false;

        }

        if (Down2) { // Goes Down
            Player.Image = Image.FromFile("Rice-Boy-Walking-Down.gif");
            Down2 = false;

        }

        if (Player.Top + 150 > this.ClientSize.Height) {
            iggy = true; // Shows that riceboy is approaching the starting point
            Check2 = false;
            Down2 = false;
            right2 = true;
        }

        if (Player.Left + 150 > this.ClientSize.Width & iggy) {
            right2 = false;
            Player.Image = Properties.Resources.Rice_Boy_Standing_Left;
        }

    }
    private void form1_Pad1_Rice(object sender, System.Windows.Forms.PaintEventArgs e) {
        e.Graphics.DrawImage(Properties.Resources.Corn_Cobs, 120, 58, 50, 50);
        // Draws Corn cobs Character goes slower when corn is drawing
        // (x(-left), y(-Up), W, H) 
    }
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间Rice_Boy_Tester_2
{
公共部分类Form1:Form
{
bool-iggy=false;
bool left2=false;
bool right2=假;
bool Up2=假;
bool-Down2=假;
布尔检查2=假;
布尔左=假;
布尔右=假;
bool Up=false;
bool Down=错误;
布尔检查=假;
公共表格1(){
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e){
//空块
}
私有无效刷新\u勾选(对象发送方,事件参数e){
这个。刷新();
}
私有void PriceBoyWalk_Tick(对象发送方,事件参数e){
if(left)//向左
Player.Left-=1;
如果(Player.Left<170&检查==false){
//检查球员离状态有多远
左=假;
向上=真;
}
如果(向上&Player.Left<170){//向上
Player.Top-=1;
检查=正确;
}
如果(Player.Top<100&检查){
向上=错误;
向下=真;
}
if(right)//向右转
玩家。左+=1;
如果(下降)//下降
Player.Top+=1;
如果(Player.Top+150>this.ClientSize.Height){
检查=错误;
向下=假;
右=真;
}
如果(Player.Left+150>this.ClientSize.Width)
右=假;
}
私有void B1\u单击(对象发送方,事件参数e){
this.Paint+=新的PaintEventHandler(form1_Pad1_Rice);
RiceBoyWalkGif.Enabled=true;
左=真;
left2=真;
RiceBoyWalk.Enabled=true;
}
私有无效计时器1_刻度(对象发送方,事件参数e){
如果(左2){
Player.Image=Image.FromFile(“Rice Boy Walking Left Bouncing.gif”);//设置RiceBoyWalkingLeft动画
left2=假;
}
如果(Player.Left<170&Check2==false){
//检查球员离状态有多远
left2=假;
Up2=真;
}
如果(Up2&Player.Left<170){//上升
this.Player.Size=new System.Drawing.Size(36,76);//更改图片框的大小以保持质量
Player.Image=Image.FromFile(“米童蹦蹦跳跳地走上街头”);//设置米童穿越马路的动画
检查2=正确;
Up2=假;
}
如果(Player.Top<101并检查2){
//玩家.Top<101必须比RiceBoyWalkTimer大+1
Up2=假;
Down2=真;
}
如果(右2){
this.Player.Size=new System.Drawing.Size(53,77);//更改图片框的大小以保持质量
Player.Image=Image.FromFile(“Rice Boy Right Bouncing.gif”);//设置RiceBoyWalkingRight动画
right2=假;
}
如果(Down2){//下降
Player.Image=Image.FromFile(“Rice Boy Walking Down.gif”);
Down2=假;
}
如果(Player.Top+150>this.ClientSize.Height){
iggy=true;//表示riceboy正在接近起点
检查2=错误;
Down2=假;
right2=正确;
}
如果(Player.Left+150>this.ClientSize.Width&iggy){
right2=假;
Player.Image=Properties.Resources.Rice\u Boy\u Standing\u Left;
}
}
私有void form1_Pad1_Rice(对象发送器,System.Windows.Forms.PaintEventArgs e){
e、 Graphics.DrawImage(Properties.Resources.Corn_Cobs,120,58,50,50);
//绘制玉米芯绘制玉米芯时,角色速度变慢
//(x(-左),y(-上),W,H)
}
从以下内容开始:

Player.Image=Image.FromFile(“Rice Boy Walking Down.gif”)

(和其他加载例程)

每一个滴答声?真的

在初始化过程中加载一次,将其存储在变量中,重新使用图像。玩过电脑游戏吗?它们不会破坏您的光盘试图在每帧加载所有图形资源

光盘访问速度慢。图像解码速度慢。我怀疑您会在程序运行时更改图像。

从以下内容开始:

Player.Image=Image.FromFile(“Rice Boy Walking Down.gif”)

(和其他加载例程)

每一个滴答声?真的

在初始化过程中加载一次,将其存储在变量中,重新使用图像。玩过电脑游戏吗?它们不会破坏您的光盘试图在每帧加载所有图形资源


光盘访问速度慢。图像解码速度慢。我怀疑你会在程序运行时更改图像。

@Unihedron该OP会因此受到GameDev的嘲笑。如果问题中有“game”一词在它里面,这并不意味着问题应该自动重定向到GameDev。在我看来,这个问题在这里比在那里更合适。@Unihedron的OP会因此被GameDev嘲笑。如果一个问题有“游戏”这个词在本文中,这并不意味着问题应该被自动重定向到GameDev。在我看来,这个问题在这里比在那里更合适。谢谢你的回答。有人编辑了我对编程有点陌生,这段代码不是很好,但我该如何加载它们,然后将它们存储到变量中。比如PutPlayer.Image=Image.FromFile(“Rice Boy Walking Down.gif”);和Form1_中的其他变量加载,然后将它们分配给变量,并在计时器中使用这些变量,以便我可以更改