A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: using conditionals to save processor

  1. #1
    ___________________
    Join Date
    May 2004
    Posts
    3,174

    using conditionals to save processor

    hi. is it better to use a conditional statement than a shorter script as far as cpu?

    like which of these is best (they both are supposed to stop when _xscale is at 100, the first naturally, the second bbth naturally and by condition):

    Code:
    this._xscale += Math.round((100-this._xscale)/10);
    Code:
    if (this._xscale<100) {
    this._xscale += Math.round((100-this._xscale)/10);
    }
    or if im missing something altogether lemme know.

    tyia.

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Assuming you're doing this from inside an onEnterFrame handler, the best thing, CPU-wise, is to detect when you've hit 100 (as you are with the if statement) and then DELETE the onEnterFrame handler so it no longer executes that statement at all.


    delete this.onEnterFrame;

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    jbum, thx for the reply. if this is in response to a mouse event/ user action, should i still delete it then rebuild it with onRollOver? and should i only be detecting mouse events with the appropriate handlers (rather than enterframe ifs)?

    also... i've been using Math.round (or ceil or floor) on pretty much all my calculations - thinking that it'll be less work to compute integers - occassionally (not often) this gives me a little roughness in a movement or resize... am i wrong about that? is calculating the nearest whole just as much/more work than working with 12.982752735097*4.035709237502?

    edit: while im at it; does masking require flash to draw the whole thing first, then mask? so for example, it wouldn't be any more work to load a jpeg at 1000+ square px and just show a 10x100 px slice of it using a mask?

    thanks for your help.
    Last edited by moagrius; 09-04-2004 at 04:18 AM.

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    jbum, thx for the reply. if this is in response to a mouse event/ user action, should i still delete it then rebuild it with onRollOver? and should i only be detecting mouse events with the appropriate handlers (rather than enterframe ifs)?
    Yes, and yes.

    also... i've been using Math.round (or ceil or floor) on pretty much all my calculations - thinking that it'll be less work to compute integers - occassionally (not often) this gives me a little roughness in a movement or resize... am i wrong about that?
    I personally mostly use rounding when presenting data to humans (e.g. when printing it in a text field and I don't want extra decimals). I don't think you're saving any CPU by using rounding for animation calculations, and you are probably costing extra CPU by making the extra rounding calls (I think flash is storing all the numbers as floats regardless of whether you round or not).
    Plus you're getting the roughness in movement.

    while im at it; does masking require flash to draw the whole thing first, then mask? so for example, it wouldn't be any more work to load a jpeg at 1000+ square px and just show a 10x100 px slice of it using a mask?
    It would be faster to just load the slice only, if that's all you are going to show. However, if you intend to show the whole thing, then load the whole thing.

    In general, a lot of these questions can be answered by experimentation using getTimer(). See this thread:

    http://www.flashkit.com/board/showth...hreadid=580528

    For an example of how to compare timings of two different things.

    - Jim
    Last edited by jbum; 09-04-2004 at 04:34 AM.

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    thx u very much sir!

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