May 28th, 2009

Scrolling Materials in PaperVision

For a project we were building recently in PaperVision3D I came across a problem when trying to clip MovieMaterials inside of a plane.  Another big factor was that my stage was not set to scaleToStage, which seemed to fix the problems the little I played with it.  However, for this site it wasn’t an option. Following is some insight into the steps I took to solve this problem in hopes that it saves someone else some time.  Admittedly, this problem should be no biggie for the papervision buff, but it took me a while to track down an answer.



scrollrectheader

Problem 1:

I have a MovieClip that I am using as the target of a MovieMaterial, and I want to add another clip to it which happens to be a lot larger than the original clip.  If you simply add it, it will be clipped off at the size of the original.  However, if your added clip contains multiple buttons, the hit areas of the buttons will all squish to fit in the plane, even though it won’t look like it.  Confusing?  Very.  To see the true hit areas of your buttons you can set the allowAutoResize property on the MovieMaterial to true, and just like that your whole MovieClip is visible on the plane.  This leads us into..

Problem 2:

Sure the whole clip is visible, but it’s now terribly squished.  My first thought was to set a mask on my added MovieClip which gave me some weird results.  However, applying a scrollRect to the MovieClip seemed to solve my problems.  MouseEvents translated well and I could scroll my material by altering the scrollRect of my MovieClip.  It was all peachy until I resized the stage.

Problem 3:

When scaling the stage all of the sudden MouseEvents because unpredictable.  They seemed to be off by an amount proportionate to how much I scaled the stage.  After a whole lot of searching I eventually stumbled across a post I believe by Andy Zupko (to which I have lost the link) giving a solution to a similiar situation.  MovieMaterials have a fifth parameter called ‘rect’ which is just what you’d think it would be.  This parameter describes the rectangle of a material to draw, and by changing that you can scroll your material, and the VirtualMouse adjusts correctly, even when resizing.

Included below is a file demonstrating the three above problems.

» Source