wayfinder Posted August 21, 2015 Share Posted August 21, 2015 Hi! In my (Phaser) project, I'm changing the fragmentSrc and vertexSrc of PIXI.StripShader. I would like to do this from outside the framework—I have a separate file into which I put stuff that I've rewritten, instead of going into the big file and having to carefully diff on every new release. This has never been a problem (I successfully put a bunch of changed pixi functions in there and it always worked), until this one, which is the first time I want to replace a constructor. When I simply put the updated constructor function PIXI.StripShader into my add-on file, it doesn't work—it looks like that removes all the prototypical functions, and I get an error the first time anything tries to call the StripShader's non-existant init function. When I give the updated constructor a new name and set PIXI.StripShader.prototype.constructor to that, it looks like that's simply being ignored. When I duplicate the constructor and all its prototypical functions inside my add-on file, it doesn't work either—I don't get an error message, and the code is not being ignored, however the Strip does not get displayed at all. The shader code I wrote works, but only if I make the changes to the fragmentSrc/vertexSrc in place, in the framework build, which is what I wanted to avoid in the first place. Can you help? How would I best handle this? Quote Link to comment Share on other sites More sharing options...
xerver Posted August 21, 2015 Share Posted August 21, 2015 Let me see how you are doing this and I'll let you know Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 22, 2015 Author Share Posted August 22, 2015 Oh my, it was my own stupidity at fault. The shader init function was already one of the functions I had replaced in order for my updated vertex shader and fragment shader to function correctly, so I was overwriting that when I duplicated the constructor and all its (unmodified) prototypical functions at a later point inside my add-on file. So now I have duplicated the whole PIXI.StripShader including all its prototypical methods in my add-on file and made my changes to the code there, and it all works now. But: I'm still wondering whether there's a more elegant way that would allow me to do it without having to replicate all functions, even the ones I don't use, inside my file. Do you know? Quote Link to comment Share on other sites More sharing options...
xerver Posted August 22, 2015 Share Posted August 22, 2015 You could just have your custom thing inherit the prototype of the thing you are overriding, then only redefine methods you need.function MyStrip() { // .. custom ctor}MyStrip.prototype = Object.create(OriginalStrip.prototype);Mystrip.prototype.constructor = MyStrip;MyStrip.prototype.someMethod = function () {}; wayfinder 1 Quote Link to comment Share on other sites More sharing options...
alex_h Posted August 22, 2015 Share Posted August 22, 2015 If you did want to replace the constructor function still you can do something likevar oldStripShader = PIXI.StripShader;//you could even be tidy and put this somewhere rather than polluting the global namespace...PIXI.StripShader = function(){ //your custom stuff goes here};PIXI.StripShader.prototype = Object.create(oldStripShader.prototype);PIXI.StripShader.prototype.constructor = PIXI.StripShader; Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 23, 2015 Author Share Posted August 23, 2015 If you did want to replace the constructor function still you can do something likevar oldStripShader = PIXI.StripShader;//you could even be tidy and put this somewhere rather than polluting the global namespace...PIXI.StripShader = function(){ //your custom stuff goes here};PIXI.StripShader.prototype = Object.create(oldStripShader.prototype);PIXI.StripShader.prototype.constructor = PIXI.StripShader;This looks like it's working, thanks! One trip-up to look out for was that in PIXI.Strip (for which I similarly edited the constructor), there was a non-prototypical addition of the draw modes, which still got wiped using this method, so they still needed to be duplicated, even though they weren't changed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.