Jump to content

Where is the renderer.setColor() function coming from?


Dan K
 Share

Recommended Posts

In the examples/graphics the following call is made on line 45

me.video.renderer.setColor(r);

But where does the setColor function come from?  the renderer is a me.Object and there is no setColor Funciton in the renderer class.

The function does seem to refer to the declaration in me.Color.setColor  but this function just returns a color, so to me its unclear how the canvas context knows that the color is set.

Even if the setColor is a prototype function, I still don't see where it become part of the renderer object.

--- To supplement this thought.  I would suggest moving color related functions (the active setting / changing not the Color manipulation functions) inside of the me.Renderer  even if it just referencs the function in the me.Color class.    It is logical that the programmer will be using the 'renderer' class for custom drawing functions and it would be natural to expect to find references on how to set the color here.

 

Link to comment
Share on other sites

me.Renderer is just a base class for both the Canvas and WebGL renderer to prevent duplicated code as half of it is anyway common to both.

as for the setColor() methods, this is used to define the current fill and stroke rendering color and is defined here for the canvas renderer :

https://github.com/melonjs/melonJS/blob/master/src/video/canvas/canvas_renderer.js#L571-L586

and there for the WebGL one :

https://github.com/melonjs/melonJS/blob/master/src/video/webgl/webgl_renderer.js#L591-L603

reason of this one not being in the base Renderer class is that, as you can see, the implementation is different based on the target renderer.

 

hope this helps ! 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...