Cropping when drawing

0 favourites
  • 7 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Ref: construct.net/en/forum/construct-3/plugin-sdk-10/canvas-image-extraction-146200

    I still must be missing something. If I add the following code to the drawing-plugin-demo (v1.8):

    Draw(renderer)
    {
    ...
    	var c = new self.C3.Color(0.5, 0.5, 0.25, 1.0);
    	c.premultiply();
    	renderer.SetColor(c);
    	renderer.PushLineWidth(5);
    	renderer.Line(0, 0, 100, 200);
    	renderer.PopLineWidth();
    }
    

    ... it just draws on the screen/viewport even outside of the objects given boundaries. Is there no mechanism to crop to the objects boundaries?

  • or... do I need to draw into a texture, which handles the cropping, and then apply that texture? Or... can I even use the DrawingCanvas inside my plugin to do the heavy lifting?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In my experience, C3 renderer drawing lines or drawing quads will draw anywhere on the viewport/screen regardless of the worldinfo bounding box.

    If you want to clip to the size of particular bounding box, you might trying to clip the line yourself (e.g. find the line intersection(s) of the bounding box and draw the line with the new coordinates.) Using GetBoundingQuad() to get the coordinates to clip against.

    In the current public plugin SDK I have not yet seen a way to draw into another C3 texture (though I imagine this is what the Drawing Canvas does.)

    Perhaps you could try extending the Drawing Canvas plugin class and add the features you want to it? Or add a behavior to a Drawing plugin object which could do something similar?

  • Here's a JS line clipping library in case you want to do the clipping yourself:

    github.com/mapbox/lineclip

  • The whole screen is game to draw to as long as the bounding box is in the view.

    I haven’t explored c3’s renderer but it’s likely a batched renderer similar to C2. As such you’re limited to features exposed to to the renderer. Drawing to a texture is probably just an undocumented feature. C2’s renderer had it as a feature at least. It’s used for drawing effects and layers with force own texture. The paster plugin utilized this, although there is more setup and such.

    Now in C2 there was also a function in the renderer to complete all current batches. This was useful to let the renderer finish what it was doing and then you could do anything you desired with all of webgl as long as you preserved the webgl state to what construct had it at. This can kill the benefits of batching so I doubt this way would be officially supported. C3 probably has a similar undocumented function in its renderer.

    Examples in C2 are the dragon bones plugin and some more recent 3D experiments I posted capx for.

    Anyways, webgl provides a couple clipping ideas. One is scissoring. It limits what is drawn to a rectangle on the screen.

    The other is stencil buffers. You can draw anything to the buffer and then you can draw to the screen like normal and the stencil acts like a mask.

    Anyways just some ideas.

  • Blackhornet, if you are interested, we can discuss C3/WebGL over on the Construct Community Discord (R0J0hound gave me some great tips based on their C2 work.)

  • Thanks R0J0hound and Mikal. I've decided not to sweat it. I was thinking that I was being a bad citizen by not bounding my graphics by the bounding box, but then it occurred to me finally that Particles aren't bound by their bounding box. My Lightning plugin is similarly just a graphics effect, so it's not required to be bound at all.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)