Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One problem is that on every execution of .run you're redrawing the sprite's graphic box, but the sprite doesn't change at all over time. So just drawing once in the constructor is enough. </p> <p>But what if you <em>DO</em> have to redraw every frame for some reason? Maybe to change the color of the box over time? Well, you're neglecting to clear your old image... so every frame you just add more and more vector points to the graphics objects. So in reality while it looks like you have just one black square you actually have thousands of black squares worth of data after only a few seconds. You can clear out the graphics object like this...</p> <pre><code>this.graphics.clear(); </code></pre> <p>As a micro optimization, you can assign this.graphics to a local variable...</p> <pre><code>var g:Graphics = this.graphics g.moveTo(0); // and so on... </code></pre> <p>Another thing I notice is that you don't appear to have time-based movement, but rather it's frame based. The blocks themselves have no idea how much time has elapsed, so they'll slow down. The alternative is to base their movement on elapsed time, which will keep them moving at the right "speed" but the app will drop frames to do it.</p> <p>Since this is a box you're dealing with, you can also use graphics.drawRect() instead of drawing a box line by line.</p> <p>In my own testing, option 1 worked the best. If you do have to redraw, make sure to do graphics.clear(), as that works almost as well even for large numbers of boxes.</p> <p>EDIT to add...</p> <p>Your example, after adding the .clear() function calls does perform very well. I should however caution you that the JVM is most certainly going to have better performance than the Flash Player. This isn't to say that people can't make highly performant Flash applications, but that the upper ceiling for performance in the Flash Player when dealing with CPU rendering is much lower than that of Java. Of course, if you're willing to live on the bleeding edge you can check out the new "Molehill" 3D apis that are capable of things like this... </p> <p><a href="http://blog.theflashblog.com/?p=2593" rel="nofollow">3D game on the Wii ported to Flash using molehill, running at 60fps</a>http://blog.theflashblog.com/?p=2593</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload