Optimizing my dynamic background engine for a 2d flash game in actionscript-3

前端 未结 6 1313
青春惊慌失措
青春惊慌失措 2021-02-11 05:23

Edit 2: judging on the lack of replies I start wondering if my issue is clear enough. Please tell me if I need to elaborate more.

Notice: see bottom for a co

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-11 05:49

    • You should be able to simplify some of your math by using stored variables instead of stageCenterX + stageWidth * 0.75, and similar since they don't change.
    • Have you considered using HitTestPoint instead of doing the math to check positions of containers? It's a native function, so it might be faster.
    • You should use a Shape instead of a Sprite if you don't need to add children to the object. e.g., your star. This might help quite a bit.
    • What if you created a set of star backgrounds at the start of the program. Then converted them to bitmaps, and saved them for later reuse. e.g., create a star background, convert it to bitmap data, and save this in an array. Do this, say, 10 times, and then when you need a background to just randomly select one, and apply your other shapes to it. The benefit of doing this is that you don't have to render 100-250 Sprites or Shapes each time you create a new background--that takes time.

    EDIT: New idea:

    • Maybe you can play with the idea of only drawing the stars on the backgrounds rather than adding individual objects. The number of objects added to the screen are a big part of the problem. So I'm suggesting you draw the stars on the container directly, but with different sizes and alphas. Then scale the container down so that you get the effect you're looking for. You could reduce the display footprint from 500-1000 stars down to 0. That would be a huge improvement if you can get the effect you need from it.

提交回复
热议问题