A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] Which is quicker...

  1. #1
    Member
    Join Date
    Mar 2008
    Posts
    82

    resolved [RESOLVED] Which is quicker...

    Essentially I'm just trying to rotate an object (mc) clockwise or anticlockwise depending on the value of a variable called 'angle'.
    If 'angle' is positive it should go anticlockwise.
    If 'angle' is negative it should go clockwise.

    Is there a quicker way to do this than Option 1?
    Is Option 2 any better?
    Is there an even quicker alternative I'm not considering?


    Option 1
    PHP Code:
    if(angle 0) {
        
    mc.rotation += rotateIncrement;
    }

    else if(
    angle 0) {
        
    mc.rotation -= rotateIncrement;


    Option 2
    PHP Code:
    mc.rotation += rotateIncrement Math.abs(angle)/angle

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    i would think option 1 would be slightly quicker just because you are using basic operators , which typically are less processor intensive then using things from the math package. you could even say

    Code:
    (angle > 0)  ? mc.rotation += rotateIncrement : mc.rotation -= rotateIncrement;
    to get that sucker in one line.

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    All the code in here is pretty low level already - if you were running this millions of times per frame you might get a couple milliseconds off with option 1 but still negligible.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  4. #4
    Member
    Join Date
    Mar 2008
    Posts
    82
    Thanks guys. I'm liking the look of:
    PHP Code:
    (angle 0)? mc.rotation += rotateIncrement mc.rotation -= rotateIncrement
    I've never seen an if/else statement written like that before. Nice and simple.

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