function prefix
Elliot

I have been wondering... you know how most objects in wade have functions and properties that start with an underscore, like sprite._position.

 
Does the underscore mean that we are not supposed to use them? What about functions that end with an underscore, like all the wade.drawFunctions?
All 7 Comments
Gio

That's right, functions that start with an underscore are not meant to be used, unless you know exactly what you're doing. In other words, they are for internal usage only. As you may have noticed, these aren't even documented, and they may change without notice in future versions of WADE.

 
Functions that end with an underscore are a different thing: this is just a naming convention that we use in WADE to indicate functions whose only purpose is to return another function (if you want to be technical, they are functions that only serve to generate a closure).
 
So for example wade.drawFunctions.solidFill_('green') returns a function that fills the bounding box of a sprite with a green color. As such, it ends with an underscore. It's perfectly OK to use it.
 
On the other hand, changing the value of sprite._position will cause all sorts of problems (WADE's quadtrees won't know that you have changed that value, and will still think that the sprite is in its previous position), so don't do it.
hermes

If you want to prevent people using some functions, why make them accessible as member functions? If you made them local (function-scoped), you could still access them through a closure, but users of wade couldn't get to them.

Gio

That's right hermes, you could essentially make them "private", as they would be in another language such as C.

 
But we aren't trying to stop people using those functions (or properties). I'm just saying that if you want to use them, you have to be careful with them. So if you see something that starts with an underscore, think twice before using it.
 
There may be some legitimate uses for them, which is why I like the fact that they're accessible. For example you may want to print sprite._position to the console while debugging, and so on.
 
Things that we want to keep private are private... for example, there's no way a wade user can access the internal scene manager directly.
Elliot

Makes sense, thanks for the explanation.

 
I agree, it's nice to be able to access them for debugging even if they are meant for internal usage only.
Taddeus

Good to know, I was thinking the same thing... I don't never use underscore functions, I thought they are private.

echar

wade.drawFunctions.solidFill_ is not available in webgl mode. 

How can i change this mode to 2d?

Gio

Hi echar

You have a couple of options for solidFill_

  1. Switch the layer's render mode to 2d. This could be done either in code
    wade.setLayerRenderMode(layerId, '2d');

    or in th editor, in the scene properties
    :

  2. Saying that, you can also keep using WebGL and use a custom shader to achieve the same effect (though this obviously won't work on systems where WebGL is not supported). Again, this can be done in code

    mySprite.setPixelShader('gl_FragColor=vec4(1.,0.,0.,1.);');

    or in the editor (in the sprite editor tab):

Post a reply
Add Attachment
Submit Reply
Login to Reply