dcsimg
A Flash Developer Resource Site

Page 18 of 21 FirstFirst ... 81415161718192021 LastLast
Results 341 to 360 of 411

Thread: Optimization Tips

  1. #341
    curiouser and curiouser LittleRed's Avatar
    Join Date
    Mar 2004
    Location
    Nottingham
    Posts
    335
    thanks for sharing that - that's really useful to know!

  2. #342
    Senior Member
    Join Date
    Aug 2005
    Posts
    225
    Is their an event that makes it possible to have code run periodically but not every frame? (i use good old flash 6)

  3. #343
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Quote Originally Posted by helpmeplz
    Is their an event that makes it possible to have code run periodically but not every frame? (i use good old flash 6)
    You can always use counters to skip frames:

    if(mycounter>10){
    //run code
    mycounter=0;
    }
    mycounter++;


    or use getTimer() to run code after certain time:

    if(mytime<getTimer()){
    //run code
    mytime=getTimer()+3000;
    }

  4. #344
    Junior Member
    Join Date
    Feb 2005
    Posts
    28
    Quote Originally Posted by helpmeplz
    Is their an event that makes it possible to have code run periodically but not every frame? (i use good old flash 6)
    I like to use the setInterval for those cases, you can choose every however many milliseconds you want it to run
    If hunting is the sport of Kings than bowling is a fine sport as well - H.J.Simpson

  5. #345
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    Let's unearth this famous thread !
    Anyone know how I could optimize this test ?

    if (Math.abs(this._x-this._width/2-this._parent.progression[mc]._x+this._parent.progression[mc]._width/2)<this._parent.progression[mc].colli+this._width/2-3 and Math.abs(this._y-this._height/2-this._parent.progression[mc]._y+this._parent.progression[mc]._height/2)<this._parent.progression[mc].colli+this._height/2-3) {


    It runs dozens (hundreds?) of time per frame in my code so it should be optimized as much as possible

    Thanks in advance ^^
    Last edited by fil_razorback; 04-27-2006 at 02:35 PM.

  6. #346
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    Firstly, nest the second statement within the first(otherwise it will test both, even if the first one fails, so put the second after the first with no and).

    Secondly, if you save a variable of Math.abs, that may be faster.

    code:

    var _mathabs=Math.abs //Define only once, not every time looped through, so outside of loop
    if (_mathabs(this._x-this._width/2-this._parent.progression[mc]._x+this._parent.progression[mc]._width/2)<this._parent.progression[mc].colli+this._width/2-3){

    if(_mathabs(this._y-this._height/2-this._parent.progression[mc]._y+this._parent.progression[mc]._height/2)<this._parent.progression[mc].colli+this._height/2-3) {

    //It is true
    //Do stuff
    }
    }



    That should help a bit.

    (Also, you could save a reference to this every time in a local variable, though I don't know if that will help).

  7. #347
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    you could aslo make a refrence to the _parent.progression[mc] so the script doesn't have to keep looking it up. If it were me i'd make all the variable names nice and small. I think that has a slight impact (if any)
    code:

    var abs = Math.abs
    var ob = this._parent.progression[mc]
    //properties, thanks unknownGuy
    var w = this._width/2
    var h = this._height/2
    var obw = ob._width/2
    var obh = ob._height/2
    var colli = ob.colli
    //main loop
    onEnterFrame = function(){
    //our variables
    var x = this._x
    var y = this._y
    //ob's variables
    var obx = ob._x
    var oby = ob._y
    //check
    if(abs(x-w-obx+obw)<colli+w-3){
    if(abs(y-h-oby+obh)<colli+h-3){
    //do stuff
    }
    }
    }

    Last edited by mr_malee; 04-27-2006 at 08:16 PM.
    lather yourself up with soap - soap arcade

  8. #348
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    I've never been sure of this, but Mr. Malee, for the obx, obw, oby, and obj, wouldn't it be faster not to create a local variable since it is only used once(since by creating the variable you are using it once + creating a variable)?

  9. #349
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    whoops, yes it would, however you need to update the x and y positions
    lather yourself up with soap - soap arcade

  10. #350
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    Thanks ! I'll nest the if statements and do a reference to this._parent.progression
    I can't make a reference to Math.abs...It's not a constant value but an operation >_<

    Anyway, many thanks to both of you

  11. #351
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    why cant you reference Math.abs, are you using it as a function or something?

    i do it all the time with Math.floor and Math.sqrt

    chuck it on frame one of your main timeline as

    _global.abs = Math.abs
    lather yourself up with soap - soap arcade

  12. #352
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    O_o
    I never tried such a thing. Would it be faster?

  13. #353
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    Yes.

    Just 'cause it's a built in method doesn't mean you can't create a short-cut to it ( I think this was covered in the first few pages of this thread ).

    It's no different doing something like

    var rnd=Math.random;

    than

    var health=playerSprite.health;

    Squize.

  14. #354
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    I'm sure this was explained earlier in the thread but I didn't see it. And I haven't looked thorugh all of it but here it is. I've noticed in the very beginning of this thread when you guys were talking about if/else statements. Now when you were talking about this I recall something of a ? statement and how it performs. I'm just wondering what this ? statement is or is just anykind of a statement after the if/else?

  15. #355
    Senior Member fil_razorback's Avatar
    Join Date
    Jul 2005
    Location
    Paris, France
    Posts
    607
    As far as I understood it works like this
    code:

    var myVar= Math.round(Math.random())+1;
    var isMyVarEqualToTwo = "The Answer is : " + (myVar == 2 ?"true":"false");




    Another question, about collision detection in Shumps...it it less slow to use
    code:

    everybullet.onEnterFrame = function(){
    //test every ennemies with a for...in loop
    }


    OR
    code:

    onlyOneMovieClip.onEnterFrame=function(){
    for(bullets in the game){
    for(ennemies in the game){
    //Do hitest
    }
    }
    }


  16. #356
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,367
    It is generally thought(I believe is true, haven't tested) that one onEnterFrame is the best.

  17. #357
    PSN
    Join Date
    May 2001
    Location
    WC
    Posts
    48
    Would I take a performance hit for breaking apart an imported bitmap, edit it, and then regrouping it?

    The motivation behind the question is that I am trying find a quick way to break up the frames in a sprite sheet without using trace bitmap (which appears to be really slow). When I copy and paste from an external paint program, the transparency is not preserved, so I have to use break apart + lasso tool to remove the background.

    I could preserve transparency by cutting each frame in the sprite sheet and saving them individually, but that is way too tedious.

    Any help is appreciated, thanks much!


    EDIT: I did some testing, and found that using a bitmap as is was about 3% faster than breaking it up.

    I created 60 movieclips of either a bitmap or a broken up one and timed their move across the screen from x=0 to x=600.

    Anyone seen similar results?
    Last edited by drakz; 05-09-2006 at 05:19 AM.

  18. #358
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    Jee, sounds like my worst nightmare: breaking apart a bitmap then lasso to create an alpha for sprites: Ahhhhhh! get me out of here.

    Well no! get yourself a real image editing program and save your stuff with transparency as gif or png24. I'll go for png24 because that gives you a smoth mask and then in Flash you can compress it as a Jpeg --> optimized as never!

    If you cant aford photoshop of one of those, here are some free editing softs, which probably will do the job:

    http://www.gimp.org
    http://picasa.google.com
    http://vicman.net/vcwphoto
    http://www.cursorarts.com/ca_imffw.html
    http://www.eecs.wsu.edu/paint.net
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  19. #359
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Quote Originally Posted by drakz
    Would I take a performance hit for breaking apart an imported bitmap, edit it, and then regrouping it?

    The motivation behind the question is that I am trying find a quick way to break up the frames in a sprite sheet without using trace bitmap (which appears to be really slow). When I copy and paste from an external paint program, the transparency is not preserved, so I have to use break apart + lasso tool to remove the background.

    I could preserve transparency by cutting each frame in the sprite sheet and saving them individually, but that is way too tedious.

    Any help is appreciated, thanks much!


    EDIT: I did some testing, and found that using a bitmap as is was about 3% faster than breaking it up.

    I created 60 movieclips of either a bitmap or a broken up one and timed their move across the screen from x=0 to x=600.

    Anyone seen similar results?
    Some tests were done a while back, using a lassoed alpha is actually faster than if the image has transparency. That said, it is an archaic method, and even though it offers minor speed increases, shouldn't be used.

    Try using batch processing in photoshop (or use slices to export the images). If you have Flash 8, try using BitmapData to read from the bitmap instead of cutting it up.
    Christopher Rhodes
    squarecircleco.

  20. #360
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    breaking an image apart essentially makes it become a vector shape with a bitmap fill. If it then needs less or more performance than an image with alpha area depends on the amount of curves in the vector shape (so the more curves your "custom alpha mask" has,the more performance it will need).
    As pred said its an archaic method,painful to do and a giant time waste.

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