dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: actionscript 8 vs 9 speed question

  1. #1
    Junior Member
    Join Date
    Nov 2002
    Posts
    12

    Question actionscript 8 vs 9 speed question

    hello.... i've recently been thinking about converting a project i'm working on from flash 8 to flash 9 due to the supposed increase in performance. i wanted to illustrate an example of that improvement to myself by creating an example of some code in both flash 8(as2) and 9(as3) and comparing the performance of the two. sooooo... i made 50 different streams of particles in each using pretty similar code... and flash 9 seems to be the same or slower.

    could anyone tell me if i'm doing something inefficiently, or if what i'm actually doing is something that wouldn't see a performance increase? i figured flash 9 would allow me to at least double the number of streams. any help is greatly appreciated.



    here are my swfs (their default fps is 30... in my browser they both run at about half that)...

    flash 8: http://www.totaljerkface.com/bloodtest8.swf

    flash 9: http://www.totaljerkface.com/bloodtest9.swf


    and here is the code i'm using...
    code for the flash 8 version is all in the timeline...

    for (var i = 0; i<50; i++) {
    var bf:MovieClip = _root.createEmptyMovieClip("blah", _root.getNextHighestDepth());
    bf._x = Math.random()*350+100;
    bf._y = Math.random()*300+50;
    bf.onEnterFrame = bleed;
    var bloodInt:Number = bf.setInterval(bleed, 1);
    }
    function bleed() {
    var randY:Number = Math.random()*-6-6;
    var randX:Number = Math.random()*3-1.5;
    var b:MovieClip = _root.attachMovie("Blood1", "blood", _root.getNextHighestDepth());
    b._x = this._x;
    b._y = this._y;
    b._rotation = Math.random()*360;
    b.gotoAndStop(Math.ceil(Math.random()*4));
    b.cacheAsBitmap = true;
    b.speedY = randY;
    b.speedX = randX;
    b.onEnterFrame = function() {
    this._y += this.speedY;
    this._x += this.speedX;
    this.speedY += 1;
    if (this._y>400) {
    this.removeMovieClip();
    }
    };
    }


    code for flash 9 is in the timeline and in 2 class files:

    //timeline
    for(var i:int = 0; i < 50; i++){
    var bf:BloodFlow = new BloodFlow();
    root.addChild(bf);
    bf.x = Math.random()*350 + 100;
    bf.y = Math.random()*300 + 50;
    }

    //class files
    package {
    import flash.display.*;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    public class BloodFlow extends MovieClip {
    public function BloodFlow() {
    var myTimer:Timer = new Timer(0, 0);
    myTimer.addEventListener("timer", createBloodMC);
    myTimer.start();
    }
    private function createBloodMC(event:TimerEvent):void {
    var randY:Number = Math.random()*-6 - 6;
    var randX:Number = Math.random()*3 - 1.5;
    var b:Blood1 = new Blood1(randY, randX);
    root.addChild(b);
    b.x = this.x;
    b.y = this.y;
    b.rotation = Math.random()*360;
    b.gotoAndStop(Math.ceil(Math.random()*4));
    }
    }
    }

    package {
    import flash.display.*;
    import flash.events.Event;
    public class Blood1 extends MovieClip {
    public var speedY:Number;
    public var speedX:Number;
    public function Blood1(sY:Number, sX:Number) {
    this.cacheAsBitmap = true;
    this.speedY = sY;
    this.speedX = sX;
    this.addEventListener(Event.ENTER_FRAME, flow);
    }
    private function flow(event:Event):void {
    this.y += speedY;
    this.x += speedX;
    speedY += 1;
    if(this.y > 400){
    this.removeEventListener(Event.ENTER_FRAME, flow);
    root.removeChild(this);
    }
    }
    }
    }

  2. #2
    Flash Guru pbleper's Avatar
    Join Date
    Jan 2001
    Location
    BC, Canada
    Posts
    477
    Perhaps the vector rendering is what does the major performance hit in this project. I don't know for sure, but doesn't AS3 only increase code execution speed?
    Witek Radomski
    Programmer and Sound Engineer
    http://www.surreal-media.com/

  3. #3
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    Quote Originally Posted by pbleper
    Perhaps the vector rendering is what does the major performance hit in this project. I don't know for sure, but doesn't AS3 only increase code execution speed?
    Yes. I don't think much has changed for the renderer.

    So loops and such should be much faster.

    By the way rotating a clip when it has cacheAsBitmap true will be counter productive. The clip will be turned back into a vector, rotated, cached, then that will happen again and again. So no point caching a bitmap that is rotating over and over. Instead make the blood a png to start with.

  4. #4
    Junior Member
    Join Date
    Nov 2002
    Posts
    12
    hey pugger... i only rotate it randomly once when it's first created... then apply cacheasbitmap

    but yeah... i think you guys are correct. anyone know of an example that illustrates the speed difference?

  5. #5
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    Right now I'm working on an as3 physics engine, and I can tell you that there's a huge difference in performance. It kinda weird that your demo had that kind of performance, but here's something I did a while back:

    This is a demo of my old physics engine in as2:
    http://studio.fileitup.com:88//Fisix...collision.html
    (press ctrl,alt,shift to create stuff)

    then check out any of the demos on my development blog
    http://blg.fisixengine.com:88/index..../engine-demos/

    especially this one:
    http://www.fisixengine.com/demos/demo1.html

    and this one
    http://www.fisixengine.com/demos/demo2.html

    and this one
    http://www.fisixengine.com/demos/demo5.html

    all of them kind of prove it really..

    hope that helps
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  6. #6
    Flash Guru pbleper's Avatar
    Join Date
    Jan 2001
    Location
    BC, Canada
    Posts
    477
    ozmic66,

    But your demos show much lighter vector rendering than Totaljerkface's demo. In your demos, the Flash 9 VM has a chance to show it's new speed because most of the work is happening in math, not visual rendering.
    Witek Radomski
    Programmer and Sound Engineer
    http://www.surreal-media.com/

  7. #7
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    Quote Originally Posted by pbleper
    ozmic66,

    But your demos show much lighter vector rendering than Totaljerkface's demo. In your demos, the Flash 9 VM has a chance to show it's new speed because most of the work is happening in math, not visual rendering.
    Well, that's where all the improvement is really

    try jerkface's demo with a bitmapdata and you'd probably get some just results
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  8. #8
    \x3a\x6f\x29
    Join Date
    Sep 2005
    Location
    paris
    Posts
    88
    You could also use a Sprite instead of a MovieClip and so on.
    I see also a big mistake in your code. First you add the BloodFlow child 50 times which seems to be a MovieClip with some timer running and then again the Blood1 instances added to root which are MovieClips.

    You should use the Sprite class for your Blood sprites(!), and one global control to move them. But I have to agree. Rendering is not that much faster.

    Doing the same with a BitmapData and setPixel calls would result in very different speeds.

  9. #9
    dubba you tee eff steven_h_2000's Avatar
    Join Date
    Oct 2000
    Location
    Columbus, Ohio
    Posts
    137
    fisixengine rocks!!! wooot....

  10. #10
    Senior Member
    Join Date
    Aug 2001
    Posts
    227

    Back to tweening

    After a long hiatus, i am back and need my tweening class completed.

    Before i continue work on my clunky classes, has anyone found a good way to do frame by frame movement with efficiency?

    I have noticed there is a Physics engine out there and it is amazing, so obviously there is currently a good way of doing it. I just don't know which is best out of the given options (onframe vs timers is the only way i know)

  11. #11
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    Hey zeus, got your email, so I'll just post here

    What I do with the fisix engine isn't really tweening as much as it is simulating... instead of specifying two points and a time, I give the objects speeds and let them loose with some integration (or pretty much adding the velocity to the position)

    Simply tweening between two points is actually simpler than what I'm doing right now because the position of your objects can be derived for any point in time. Here's an example:

    Code:
    //here we'll move the object 'mc' from point 'p1' to point 'p2' in 'animTime' milliseconds.
    'timeStart' is when we want the animation to start (in milliseconds)
    
    var p1:Object = {x:0,y:0}
    var p2:Object = {x:100,y:100}
    var animTime:uint = 3000 //take three seconds to get there
    var timeStart:uint = 5000 //start 5 seconds into the movie
    
    //your main loop can be called either on enter frame, or in a timer
    
    function mainLoop(){
        var currentTime:uint = getTimer() //the current time in milliseconds
    
        var dt:Number = (currentTime-timeStart)/animTime
        
        //we only need to animate if dt is between 0 and 1
        if(dt<0 || dt>1) return;
    
        xDistance = p2.x-p1.x
        yDistance = p2.y-p1.y
        
        //interpolate
        mc.x = p1.x + xDistance*dt
        mc.y = p1.y + yDistance*dt
    }
    Good luck! let me know if this is what you were trying to understand
    Last edited by ozmic66; 09-30-2006 at 02:48 PM.
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  12. #12
    Senior Member
    Join Date
    Aug 2001
    Posts
    227
    oops i didn't mean to post here and hijack this thread lol. Too many windows open when i posted

    I'll continue the discussion here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center