Draw primitive and use it like as a sprite

I draw a rectangle with the drawNode, but i would like to know if it`s possible to use it as a body and shape, and add to the space, to avoid to use an image. I mean… to use the drawRect result like a sprite.

My current code:

this.drawNode =  new cc.DrawNode();
    this.addChild(this.drawNode, 10);
    this.drawNode.drawRect(cc.p(280,280), cc.p(300,300),
                           cc.color(255,255,255,255), 1 , cc.color(255,255,255,255) );


    var body = this.space.addBody(new cp.Body(10, cp.momentForBox(40, 15, 15)));
    var shape = this.space.addShape(new cp.BoxShape(body, 20, 20));

thanks in advance.

1 Like