box2d.js icon indicating copy to clipboard operation
box2d.js copied to clipboard

Drawing objects with images

Open sbiermanlytle opened this issue 10 years ago • 0 comments

If I have two polygons, and I want to draw them with different images depending on their properties, I need a reference to the full object in the draw function:

debugDraw.DrawSolidPolygon = function(vertices, vertexCount, color) {
        setColorFromDebugDrawCallback(color);
        drawPolygon(vertices, vertexCount, true);
};

I traced the call to this part of the stack:

self.DrawSolidPolygon($1,$2,$3);

so I could get what I want by changing that to

self.DrawSolidPolygon($1,$2,$3,self);

but that code was generated and only shows up in the VM. How do I change how this code is generated?

(function(Module, FS) { return function($0,$1,$2,$3){ { var self = Module['getCache'](Module['JSDraw'])[$0]; if (!self.hasOwnProperty('DrawSolidPolygon')) throw 'a JSImplementation must implement all functions, you forgot JSDraw::DrawSolidPolygon.'; self.DrawSolidPolygon($1,$2,$3); } } })

sbiermanlytle avatar Oct 25 '15 23:10 sbiermanlytle