0 Favourites

SDK drawing functions

  • Here are some functions that I use to draw shapes on the Construct 2 renderer.

    Box:

    renderSquare(this, renderer,cr.RGB(0,0,255));[/code:3573wm0c]
    [code:3573wm0c]function renderSquare(inst, renderer,color) {
    	var q = inst.instance.GetBoundingQuad();
    	renderer.Outline(q, color);
    }[/code:3573wm0c]
    Circle:
    [code:3573wm0c]renderCircle(this, renderer,cr.RGB(0,0,0),18);[/code:3573wm0c]
    [code:3573wm0c]
    function renderCircle(inst, renderer, color,segments) {
    	var q = inst.instance.GetBoundingQuad();
    	var xpos = (q.tlx + q.trx + q.blx + q.brx) / 4;
    	var ypos = (q.tly + q.try_ + q.bly + q.bry) / 4;
    	xsto = new cr.vector2(inst.instance.GetSize().x / 2, 0);
    	ysto = new cr.vector2(inst.instance.GetSize().y / 2, 0);
    	rcos = Math.cos((Math.PI / (segments/2)))
    		rsin = Math.sin((Math.PI / (segments/2)))
    		for (var i = 0; i < segments; i++) {
    			xsto.x = ysto.x * rcos - ysto.y * rsin;
    			xsto.y = ysto.x * rsin + ysto.y * rcos;
    			renderer.Line(new cr.vector2(xpos + xsto.x, ypos + xsto.y), new cr.vector2(xpos + ysto.x, ypos + ysto.y), color);
    			q.tlx = xpos + xsto.x;
    			q.tly = ypos + xsto.y;
    			q.trx = xpos + ysto.x;
    			q.try_ = ypos + ysto.y;
    			q.blx = xpos;
    			q.bly = ypos;
    			q.brx = xpos;
    			q.bry = ypos;
    			ysto = new cr.vector2(xsto.x, xsto.y);
    		}
    }
    [/code:3573wm0c]
    Polyline:
    [code:3573wm0c]drawPolyline("641 96 435 99 434 186 634 181 641 95 688 45 689 138 633 180 435 98 513 50 688 45",cr.RGB(255, 0, 0), this.instance,renderer);[/code:3573wm0c]
    [code:3573wm0c]function drawPolyline(points,color, inst,rend) 
    {
    			var q = inst.GetBoundingQuad();
    			var xpos = (q.tlx + q.trx + q.blx + q.brx) / 4;
    			var ypos = (q.tly + q.try_ + q.bly + q.bry) / 4;
    			var fq = new cr.quad;
    			var diffx,diffy;
    			var pArray = [];
    			pArray = points.split(" ");
    			if (xpos > pArray[0]) {
    				diffx = xpos - pArray[0];
    				diffx *= -1;
    			} else {
    				diffx = pArray[0] - xpos;
    			}
    			if (ypos > pArray[1]) {
    				diffy = ypos - pArray[1];
    				diffy *= -1;
    			} else {
    				diffy = pArray[1] - ypos;
    			}
    			for (var i = 0; i < pArray.length; i += 2) {
    				rend.Line(new cr.vector2(pArray[i] - diffx, pArray[i + 1] - diffy), new cr.vector2(pArray[i + 2] - diffx, pArray[i + 3] - diffy), color);
    			}
    
    }[/code:3573wm0c]
    
    You may find these useful when making your own plugins.
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)