A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F8] [Help] Clipping redraw regions

  1. #1
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270

    [F8] [Help] Clipping redraw regions

    I've run into one of those problems that might not be resolvable, but I'm giving it a shot here to see if anyone has some ideas on what to do.

    Objective:
    I want to construct my 2D game levels by piecing them together in a giant container, then reduce lag by updating the position of a scrollRect to achieve camera tracking and zoom. Specifically, I want to reduce as much lag as possible by making flash believe that the container is only as big as the scrollRect's surface area.

    Problem:
    Flash automatically expands the redraw regions to fit the actual size of the container if it extends beyond the scrollRect.

    Approaches:
    I have tried to use a scrollRect, then setMask, and finally both in tandem. No luck.

    I have considered using BitmapData's draw function to force a snapshot of the region I need, but this would probably create more lag rather than less because I'd be storing each frame as an image instead of just rendering in one pass.

    Is there any other way?
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  2. #2
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    I just refactored the class to accept BitmapData.draw() and it looks like a pretty good fix. The only issue I'm having with it now is slowdown. There's a noticable lag when I zoom out too far, but the limitations presented by this are easy to work within.

    Still seems like alot more work than it should be.
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  3. #3
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    The way I'd do it is splice up your area into several huge tiles, and only attack those tiles visible. This will solve your problem and proberbly make the engine faster aswell.

    ~Sph

  4. #4
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    Tiling would not work well for this scenario because it would require alot of resources to achieve a much more inefficient variety of the same desired result.

    The fix I came up with was to use a scrollRect on a nested mc whose _visible property was set to false, then use BitmapData.draw() to grab the pixels of the nested mc. Zoom was achieved by scaling up the nested mc before grabbing the pixels.

    The clever thing about this is how the nested mc (and everything inside of it) is not redrawn each frame because it's not visible. The not so clever thing is that I have to re-initialize and re-attach my BitmapData per frame to prevent a failure in the render loop that closely resembles what it looks like when you walk outside a level map in Doom 2 (basically, any transparent regions reveal residual pixel information from previous frames.)

    Doing this obviously slows down my engine enormously for no good reason, so I'm going to axe the init and attach code from my render loop and composite everything in the nested mc. As long as everything is opaque, no artifacts.
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

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