New property API in Cocos2d-html5 v3.0

pandamicro wrote:

Hi, everyone

The doc has been updated with two improvement:
How to define your own getter/setter
How to inherit the property with your custom getter/setter

Please take a look at it.

Huabin

Hi, where are those docs defined?
I’m looking at here but I can’t find them:
http://www.cocos2d-x.org/docs/catalog/en

In general I’m very in-favor of the change to properties for the JS interface. I think it makes sense to make the javascript interface seem like natural javascript as much as possible, and this will go a long way. One question though:

Does doing something like calling the setX and setY setters in sequence result in more overhead than calling the one setPosition setter? Is that doubling any work hidden away in the setter?

@ZippoLag

Sorry, it’s on my local forked repo, I will push it to the main repo when it’s stabilized.
English version is here: https://github.com/pandamicro/cocos-docs/blob/master/manual/framework/html5/getter_setter_api/en.md

@rejemy

I rewrite functions for setPositionX, setPositionY, _setWidth, _setHeight, etc, to make sure there is not any double work, so feel free to use it.
On another level, we have done the comparison between function calls and getter/setter, on some browser the function calls is quicker, on some other it’s slower, so we think it’s acceptable. And what’s more important is that the getter/setter will have a stable future in ECMAScript standard, so we trust the implementation of getter/setter will getting better and better in all browser.

rejemy wrote:

In general I’m very in-favor of the change to properties for the JS interface. I think it makes sense to make the javascript interface seem like natural javascript as much as possible, and this will go a long way. One question though:

Does doing something like calling the setX and setY setters in sequence result in more overhead than calling the one setPosition setter? Is that doubling any work hidden away in the setter?

After a few days of fiddling with the cocos2d-js-v3.0-alpha2 API here are my impressions.

Using the properties seems more natural… But it breaks the flow when I work with C++ and javascript code at the same time. Therefore I will keep using the setters to keep an homogenous environment.

@slawo, you mean you work at same time with a Cocos2d-JS project and a Cocos2d-x project ? Or you mean the homogenous environment between html5 code base and JSB code base ?
If it’s the second case, JSB in Cocos2d-JS v3.0 alpha2 do support these property APIs

I have a Cocos2d-x project which I’m working on and in parallel I started a Cocos2d-JS port of that project.

I will also have to add some C++ and Java code to the Cocos2d-JS project when deploying on android to add gamepad support.

How should I proceed to add this? I would like to create a module easily distribuable (open source it?). Should I add it in “extensions” or “external”?