7 Replies Latest reply on Aug 18, 2008 10:43 PM by CoB PEZ

    Cropped drawing in a Sprite

    CoB PEZ Level 1
      I'm trying to create a feeling of drawing on a sheet of moving paper. The paper is currently implemented as a Sprite and the drawing happens through lineTo() calls on the graphics property. But since the Sprite object grows with it's contents I can't figure out how to constrain the drawing to be "inside" the paper.

      Anyone have a suggestion for me to solve this. Currently I'm using a black pen and a black background around the paper, but that strategy will clearly break as soon as I want to allow different colors of the pen.

      I've considered implementing my own lineto() but I'd like to defer that work until I've exhausted my other options.

      Here's an SWF with the paper and pen in action: Doodulum. (Drag the pendulum weights, optionally shrinking or growing them, and then click "Start".)
        • 1. Re: Cropped drawing in a Sprite
          Level 7

          "CoB PEZ" <webforumsuser@macromedia.com> wrote in message
          news:g83f2q$kul$1@forums.macromedia.com...
          > I'm trying to create a feeling of drawing on a sheet of moving paper. The
          > paper
          > is currently implemented as a Sprite and the drawing happens through
          > lineTo()
          > calls on the graphics property. But since the Sprite object grows with
          > it's
          > contents I can't figure out how to constrain the drawing to be "inside"
          > the
          > paper.
          >
          > Anyone have a suggestion for me to solve this. Currently I'm using a black
          > pen
          > and a black background around the paper, but that strategy will clearly
          > break
          > as soon as I want to allow different colors of the pen.
          >
          > I've considered implementing my own lineto() but I'd like to defer that
          > work
          > until I've exhausted my other options.

          Have you tried putting the Sprite inside a Canvas set to clip content?


          • 2. Re: Cropped drawing in a Sprite
            CoB PEZ Level 1
            No. Well, now I've tried to wrap the Sprite inside a Canvas object. But that gave a trace because the Sprite isn't implementing IUIComponent.

            You're saying "Canvas set" however. I don't know what that is.
            • 3. Re: Cropped drawing in a Sprite
              Level 7

              "CoB PEZ" <webforumsuser@macromedia.com> wrote in message
              news:g8447s$crv$1@forums.macromedia.com...
              > No. Well, now I've tried to wrap the Sprite inside a Canvas object. But
              > that
              > gave a trace because the Sprite isn't implementing IUIComponent.
              >
              > You're saying "Canvas set" however. I don't know what that is.

              Canvas should actually contain its own graphics object that you can use.
              Set (<-- this is a verb) the Canvas to clipContent = true.

              HTH;

              Amy


              • 4. Re: Cropped drawing in a Sprite
                CoB PEZ Level 1
                Ah, it's a verb. Of course. =)

                I did try to use the graphics object of the Canvas instance yesterday when I failed to wrap the Sprite. But it didn't render at all then. I'll push some more on that solution and see if I can make it work. Maybe I need to set the width and height of the Canvas...

                I added a link to my original message where one can test the SWF at it's current.
                • 5. Re: Cropped drawing in a Sprite
                  Level 7

                  "CoB PEZ" <webforumsuser@macromedia.com> wrote in message
                  news:g8650i$kdg$1@forums.macromedia.com...
                  > Ah, it's a verb. Of course. =)
                  >
                  > I did try to use the graphics object of the Canvas instance yesterday when
                  > I
                  > failed to wrap the Sprite. But it didn't render at all then. I'll push
                  > some
                  > more on that solution and see if I can make it work. Maybe I need to set
                  > the
                  > width and height of the Canvas...

                  Yes, the Canvas needs to know how big it is supposed to be if the only thing
                  in it is what you draw in the graphics object.

                  > I added a link to my original message where one can test the SWF at it's
                  > current.

                  I'm on NNTP, so once the message goes out, that's what it looks like to me
                  forever.


                  • 6. Re: Cropped drawing in a Sprite
                    CoB PEZ Level 1
                    I'm still failing to render the paper using a Canvas instance. I'm really curious about how it implements clipContent though. Since it's a descendant of Sprite. I found that I can use a Shape for paper. It can't clip the contents of course, but since Sprite can neither I now have a more lightweight paper til I find out how to do the cropping.

                    The SWF link: http://www.pezius.com/doodelum/DoodelumApp.swf
                    • 7. Re: Cropped drawing in a Sprite
                      CoB PEZ Level 1
                      It seems that the clipContent setting on a Canvas has to do with what is rendered. I would still be drawing outside the paper, just not showing it. That's not what I want. I want have something like a drawing mask.

                      Since I am only using lineTo() to draw I solved it by controling that the current position of the pen and the next both are within my bounds. If they are I call lineTo() otherwise I call moveTo(). That and increasing the precision of my simulation gives me what I want.