一个控制或图片:动画用户界面时,这是更快? [英] Which is faster when animating the UI: a Control or a Picture?

查看:134
本文介绍了一个控制或图片:动画用户界面时,这是更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/我用和测试是建立与以下的计算机上工作:
{1 GB RAM(现在的1.5 GB),1.7 GHz的Intel Pentium处理器,ATI的Mobility Radeon X600 GFX}

/I'm working with and testing on a computer that is built with the following: {1 GB RAM (now 1.5 GB), 1.7 GHz Intel Pentium Processor, ATI Mobility Radeon X600 GFX}

我需要的规模/转换控制,并使其顺利流动。目前我操纵每24-33ms(30fps)的控件的大小和位置,±的3px。当我添加了淡入淡出效果的图像,淡入和淡出顺利,但也仅仅是25×25大小像素。控制是450x75像素到450x250像素的大小。在2D游戏如宝石迷阵3,精灵动画,没有波涛汹涌的动画。

I need scale / transform controls and make it flow smoothly. Currently I'm manipulating the size and location of a control every 24-33ms (30fps), ±3px. When I add a 'fade' effect to an image, it fades in and out smoothly, but it is only 25x25 px in size. The control is 450x75 px to 450x250 px in size. In 2D games such as Bejeweled 3, the sprites animate with no choppy animation.

因此​​,作为标题建议:哪一个更容易/处理器更快:动画位图(它渲染动画过程中父控件)或动画它的自我控制

So as the title would suggest: which is easier/faster on the processor: animating a bitmap (rendering it to the parent control during animation) or animating the control it's self?

编辑:
嘿,我认为这是一个有益的社会,不是一个向下率的问题似乎不具有挑战性! (我在这里提供更好的收视率看得更可笑的问题呢!)首先请给我一个行之前我的问题负面评价!

Hey, I thought this was a helpful community, not one that down-rates questions that don't seem challenging! (And I've seen more ridiculous questions here with better ratings too!) Please drop me a line first before negatively rating my questions!

推荐答案

我设法找到原定我到底蜱一些自由时间,迅速掀起一个新的项目。我敢肯定,我的时间本来可以更好地用于其他地方,但希望有人在我的鞋别人可能会觉得这个用在那里...

答案是:一个优化过的控制。当渲染一个位图到画布上,有非常小的事件将触发,如果有的话。至于控制,它充满了事件 - 有些链接,一些环状,并增设递归的,所以一个简单的LocationChanged'事件甚至不涵盖这实际上是引擎盖下发生的一半

The answer is: a Picture over a Control. When rendering a bitmap onto the canvas, there are very little events that will fire, if any. As for the control, it is filled with events - some chained, some looped, and the addition of recursion, so a simple 'LocationChanged' event wouldn't even cover the half of what actually is taking place under the hood.

我会为有大量的运行时应用了动态动画控件做的,是发展的两件套:控制[渲染]模板或有源接口(当控制处于停顿或动画的播放),和一个在动画结构基本限定性质如显示图像[呈现的控制]的矩形范围,任何动画的算法可应用于后者前

What I would do for controls that have lots of dynamic animations applied to them during runtime, is to develop a two piece set: a control [rendering] template or active interface (for when the control is at a stand-still or before the play of an animation), and a the animating structure with basic defining properties such as the display image [the rendered control], the rectangle bounds, and any animation algorithms that may be applied latter.

编辑:根据要求,这里有前后code的例子:结果

As Requested, here are the before and after code examples:

// This is the triggering event of the translating animation
private void object_Click(object sender, EventArgs e)
{
      // the starting point is at (75,75)
      element.Transform(new Point(500, 250));
}

public class ControlElement : UserControl
{
      private Timer tick;
      private Point pT0;
      public ControlElement() : base()
      {
            tick = new Timer();
            tick.Interval = 30; // about 30fps
            tick.Tick += new EventHandler(tick_Tick);
      }
      void tick_Tick(object sender, EventArgs e)
      {
            // get the new point from distance and current location/destination
            this.Location = Utils.Transform(this.Location, pT0, 3);
            if ((pT0.X - this.Location.X)+(pT0.Y - this.Location.Y) <= 0)
            {
                this.Location = pT0;
                tick.Stop();
                //this.Visible = true;
            }
      }
      public void Transform(Point destination)
      {
            pT0 = destination;
            //this.Visible = false;
            tick.Start();
      }
}

在我创建包含的控制会是什么样子使用 DrawToBitmap 功能图片的类。它仍然包含与上述相同的动画的方法。我不得不添加位置 LocationChanged 元素,因为这个类不再是一个控制。如果当要访问所需的实际控制人,我会停下来渲染和显示它的自我控制的一个实例。结果
下面是渲染调用:

After: I create a class that holds a picture of what the control would look like using the DrawToBitmap feature. It still contains the same animation methods as above. I had to add the Location and LocationChanged elements since this class was no longer a control. If and when the actual control needed to be accessed, I would stop rendering and display an instance of the control it's self.
Here is the rendering call:

void element_LocationChanged(object sender, EventArgs e)
{
      canvas.Invalidate();
}
void canvas_Paint(object sender, PaintEventArgs e)
{
      if (element != null)
      {
            Bitmap bmp = new Bitmap(element.Display);
            Pen p = new Pen(Color.FromArgb(128, 128, 128), 1);
            e.Graphics.DrawImage(bmp, element.Location);
            e.Graphics.DrawRectangle(p, 
                 element.Location.X, element.Location.Y, 
                 bmp.Width, bmp.Height);
      }
}

这篇关于一个控制或图片:动画用户界面时,这是更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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