C#对象的运动.......... [英] C# The movment of an object..........

查看:96
本文介绍了C#对象的运动..........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

This is my code

private void timer2_Tick(object sender, EventArgs e)
{
    if (Death.Width == 64)
    {
        Death.Location = new Point(Death.Location.X + 1, Death.Location.Y);
    }

    if (Death.Location == new Point(390, 188))
       {
           Death.Width = 63;
       }
     if (Death.Width == 63)
     {
         Death.Location = new Point(Death.Location.X - 1, Death.Location.Y);
     }

     if (Death.Location == new Point(30, 188))
    {
        Death.Width = 64;
    }

}


推荐答案

IMO,只需更改位置就足够了.不需要更改宽度(除非您想要拉伸类型的动画).
IMO, just changing the location should be enough. There is no need to change the width (unless you want a stretch type of animation).


从我所看到的情况中,我希望能获得一些有关通常如何解决类似问题的参考资料:
2D游戏入门 [ http://www.programming.de/programming_cs.php [ http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=6556 [^ ]

至于回答问题:仅更改位置

问候
Espen Harlinn
From what I can see, I hope some references on how similar problems are usually solved will be appreciated:
2D Game Primer[^]

http://www.programming.de/programming_cs.php[^]

Christian Graus has written a very informative set of articles on GDI+:
http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=6556[^]

As for answering the question: Only change the position

Regards
Espen Harlinn


此代码完全没有意义.
您可以更改Death的宽度和位置3次,但实际上,这样移动就足以一次更改位置(和宽度,如果需要),无论这些属性是如何根据以前的值计算的,无需在此之间进行任何更改.

但是,这并不重要.该议案应怎么办?它看起来不像是一个议案.它应该持续多少滴答声?

现在,函数名称建议使用System.Windows.Forms.Timer.到目前为止,该计时器不够准确,无法显示动画动作. System.Timers.Timer更好,但是即使此计时器也不应使用.为此目的使用计时器是没有意义的.应该使用一个线程.在所有情况下(如果我们忘记了System.Windows.Forms.Timer),应该通过Control.Invoke完成对UI控件属性的访问.最后,如何认真讨论使用390和188之类的硬编码立即数的代码(特别是当任何后勤常数依赖于这些常量时)?

我什至不知道该怎么建议.看起来很无助...

抱歉,
—SA
This code has no sense at all.
You change Death width and location three times, but in fact, to make a move like that it''s enough to change location (and width, if required) just once, no matter how these properties are calculated based on previous values, no need to change anything in between, ever.

But even this is not important. What this motion should do? It does not look like a motion. How many ticks it should last?

Now, the function name suggests that a System.Windows.Forms.Timer is used. This timer is by far not accurate enough to show anything like animated motion. System.Timers.Timer is much better, but even this timer should not be used. Using timers for such purposes makes no sense. A thread should be used. In all cases (if we forget about System.Windows.Forms.Timer) the access of the UI Control properties should be done via Control.Invoke. And finally, how one can seriously discuss the code where hard-coded immediate constants like 390 and 188 are used (and especially when any logistics depends on those)?

I don''t even know what to advice. It all looks helpless…

Sorry,
—SA


这篇关于C#对象的运动..........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆