cocos2d for iPhone

A fast, easy to use, free, and community supported 2D game engine

Register or log in - lost password?
  • Blog
  • Store
  • Games
  • Documentation
  • Download
  • About

cocos2d for iPhone » Programming » JavaScript Bindings

cocos2d Javascript bindings

(221 posts) (35 voices)
  • Started 1 year ago by riq
  • Latest reply from riq

Tags:

  • bindings
  • cheap watches sale
  • discount wedding dresses
  • halloween
  • javascript
  • javascript ccdrawline
  • javascript html5
  • replica watches for sale
  • watches replica
« Previous1234…8Next »
  1. riq
    Key Master

    Update:
    class: 91%:
    enums: 0%
    functions: 80%:
    macros: 0%
    structures: 45%: added support for manual structures (3 types of structs supported: opaque, manual and automatic).
    constants: 0%
    test case: 8%: Added super super simple CocosDenshion + Chipmunk + cocos2d sample
    script: improved support for manual structs, suppers multiple bridgesupport files. Easier to add support for custom extensions like ChipmunkSprite

    TODO:
    - Add support for cocos2d input events: Keyboard, Mouse, Touches, Accel
    - Add support for Chipmunk callback collisions
    - Add thousands of tests... I expect to find many bugs... For example, I already know that cp.momentForPoly won't work.

    Posted 11 months ago #
  2. riq
    Key Master

    Mouse Events are working :-)

    Get the Video Widget

    Now I will focus on the Chipmunk collision callbacks

    Posted 10 months ago #
  3. riq
    Key Master

    Subclasses are working as expected (at least with goog.base and goog.inherit).
    It is easy to add more tests now. e.g.:

    Get the Video Widget

    code:
    https://github.com/ricardoquesada/cocos2d-iphone/blob/5910c885339f0ed5d9f9e246bee472b3a75de6d6/tests/SpiderMonkeyTest/javascript-spidermonkey/test-sprite.js

    Open Bugs / issues:
    - Finish Chipmunk's callback manager
    - Garbage Collector: Not all objects are rooted. Causes a crash when the GC is started
    - Actions: "copy" not implemented.
    - Add more tests, tests and tests.

    Posted 10 months ago #
  4. slembcke
    Administrator

    Wait? A collision callback manager? What would that be? Why not just match the existing API so that Chipmunk-JS could be used on HTML5?

    I don't really see what benefits a separate singleton object to track state that individual spaces track would provide.

    Posted 10 months ago #
  5. riq
    Key Master

    I am not sure if "collision callback manager" is the correct word, but I what I need is what we discussed here:
    http://www.cocos2d-iphone.org/forum/topic/31640/page/2#post-165336

    I will follow your advise and I will implement a manual wrapper for cpSpaceAddCollisionHandler... in the "data" I will create the "closure"... The JS API will be the same:

    cp.spaceAddCollisionHandler( a, b, this.collBegin, null, this.post, null, this );

    And the manual wrapper will be something similar to Objective-Chipmunk's collision handler:

    JSBool JSPROXY_spaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
    {
          uintptr a = jsval_to_number( *vp++);
          uintptr b = jsval_to_number( *vp++);
          JSObject *f1 = jsval_to_function( *vp++ );
          JSObject *f2 = jsval_to_function( *vp++ );
          JSObject *f3 = jsval_to_function( *vp++ );
          JSObject *f4 = jsval_to_function( *vp++ );
          JSObject *user_data = jsval_to_object( *vp++ );
    
         struct *collision_user_data = malloc( sizeof( *collision_user_data) );
         collision_user_data->a = a;
         collision_user_data->b = b;
    
         [..];
    }

    The "default" 4 collisions (begin, pre, post, separate) are going to be in C, and they will call the JS objects according to the values of "data".

    And in cpSpaceRemoveCollisionHandler I will also free the malloced struct.

    What do you think about it ?
    Thanks.

    Posted 10 months ago #
  6. slembcke
    Administrator

    Aah. Ok. I thought the implication was that there would be a separate singleton object that would be tracking all of the callbacks and somehow interacting with spaces to register the collision handlers. I wasn't really sure how that would work without making things more complicated and incompatible. Yeah, that makes more sense now.

    Nevermind then. >.>

    Posted 10 months ago #
  7. riq
    Key Master

    Chipmunk + Collision Handler working :)

    Get the Video Widget

    I had to manually wrap:

    cpSpaceAddCollisionHandler
    cpSpaceRemoveCollisionHandler
    cpArbiterGetBodies
    cpArbiterGetShapes

    chipmunk manually wrapped functions:
    https://github.com/ricardoquesada/cocos2d-iphone/blob/e092af252281d1e64af9713f23476dfb4085098a/tests/SpiderMonkeyTest/js_bindings_chipmunk_manual.m

    chipmunk test:
    https://github.com/ricardoquesada/cocos2d-iphone/blob/c460948411ee1541aae6bfa58c0f1bb12400d1d9/tests/SpiderMonkeyTest/javascript-spidermonkey/test-chipmunk.js#L248

    PS: All the chipmunk functions that receive pointer to pointer arguments need to be manually wrapped.

    PS2: bonus feature: Remote JS console. You can attach to a running JS VM and send JS commands. It is still a bit buggy, but it works. It will be useful once the iOS version is ready.

    Posted 10 months ago #
  8. riq
    Key Master

    Update:
    Migrated to SpiderMonkey from Firefox 13.0.1
    Added support for iOS (tested both on iSimulator and Device)

    Get the Video Widget

    Open Bugs / issues:
    - Garbage Collector: Not all objects are rooted. Causes a crash when the GC is started (partially fixed)
    - Actions: "copy" not implemented.
    - Add support for iOS touches and accelerometer
    - Add more tests, tests and tests.

    Posted 10 months ago #
  9. riq
    Key Master

    Daily update:
    - Started the "cocos2d + JS presentation" using cocos2d + JS as the presentation framework
    - Fixed bugs on callbacks
    - touches work OK on iOS

    Get the Video Widget

    Source code of the presentation:
    https://github.com/ricardoquesada/cocos2d-iphone/blob/b1caea9664b41796d70adccb51bcf7d4eeac695c/tests/SpiderMonkeyTest/javascript-spidermonkey/test-cocos2djs.js

    Open Bugs / issues:
    - Garbage Collector: Not all objects are rooted. Causes a crash when the GC is started (partially fixed)
    - Actions: "copy" not implemented.
    - accelerometer
    - Add more tests, tests and tests.

    PS: With Lucio Torre, co-author of cocos2d-python, we gave a cocos2d presentation in EuroPython 2008 using cocos2d-python as the presentation framework too :)

    Posted 10 months ago #
  10. dany
    Member

    ehehe...great work!...please continue to update us!

    Posted 10 months ago #
  11. riq
    Key Master

    Update:

    Mini Presentation sort of finished.
    Improved configuration file.
    Remote Console works on iOS as well.

    I will try to release a v2.1 Tech Preview new week with the JS bindings.

    Posted 10 months ago #
  12. riq
    Key Master

    Status:
    - Properties are being parsed: the getters have the "get" prefix.

    var point = sprite.getPosition();
    sprite.setPosition( point );

    - Added "Release" mode (default): Asserts disabled by default. If there is an error, instead of Assert() the script will safely fail.

    cocos2d-html5 compatiblity:
    - Ported ActionTest from "extend" to "goog.base". One step closer to reuse the same tests.

    Posted 10 months ago #
  13. riq
    Key Master

    In case you want to test the bindings, do the following:

    To run it:

    1. $ git clone git://github.com/ricardoquesada/cocos2d-iphone.git
    2. (make sure that you are using the js-spidermonkey branch )
    3. You will find 3 projects:
    - cocos2d iOS project
    - cocos2d Mac project
    - Console project

    4. Open the iOS and/or Mac project.
    5. Select the target "Javascript Spidermonkey"
    6. Run it.

    To edit it:

    1. Edit the file tests/SpidermonkeyTests/JavascriptSpidermonkey.m
    2. Change the "run" method, and select the tests that you want to try:
    https://github.com/ricardoquesada/cocos2d-iphone/blob/js-spidermonkey/tests/SpiderMonkeyTest/JavascriptSpidermonkey.m#L210
    3. Make your changes
    4. And run it.

    The JS files are located here:
    tests/SpidermonkeyTests/javascript-spidermonkey

    https://github.com/ricardoquesada/cocos2d-iphone/tree/js-spidermonkey/tests/SpiderMonkeyTest/javascript-spidermonkey

    In order to run the console:

    1. Open the console project
    2. Run it
    3. It will auto-discover all the servers automatically. The client/server shall be in the same network.

    IMPORTANT:
    Right now, I am working on the tests-actions.js test. It is a WIP. Most of
    the tests are not working. So, DO NOT BASE YOUR WORK ON tests-actions.js.
    What works 100%:
    - test-chipmunk.js
    - test-label.js
    - test-sprite.js
    - test-cocos2djs.js ( This is the cocos2d presentation demo )

    Posted 10 months ago #
  14. riq
    Key Master

    Update:
    - script supports merging different methods into one single JS method.
    -- "optional_args_since" was deprecated in favor of "merge"

    Made more progress on the "test-actions.js" tests.

    Posted 10 months ago #
  15. riq
    Key Master

    Update:
    - Ease Actions: working 100% (compatible with cocos2d-html5)
    - ActionTest: working 85% (compatible with cocos2d-html5) (missing: catmullRom and Bezier actions)
    - TMX maps: working 60% (compatible with cocos2d-html5 )
    - MenuItemImage: using cocos2d-html5 API

    Compare the API's and you will see that moving from cocos2d + JS to cocos2d-html5 (Web) is pretty easy:

    cocos2d-iphone + JS sample test:
    https://github.com/ricardoquesada/cocos2d-iphone/blob/e4c9c0d4097cc923d19a3db9cb39457d5e1861b7/tests/SpiderMonkeyTest/javascript-spidermonkey/test-actions.js#L227

    cocos2d-html5 test:
    https://github.com/cocos2d/cocos2d-html5/blob/aaed7a0e43ba31bf661518188691e293c60e0007/tests/Classes/tests/ActionsTest/ActionsTest.js#L249

    Video that shows some cocos2d-iphone + JS tests (un-edited. it contains some "dead" time )

    Get the Video Widget

    Posted 10 months ago #
  16. riq
    Key Master

    Update:
    - Updated actionTest from cocos2d-html5 (using newer tests from cocos2d v2.0)
    - Renamed more "create" static method for JS
    - New libjs_static.a for iOS (previous one was crashing under certain conditions)

    What's next:
    - figure out how to wrap self.schedule() and friends
    - More tests, tests, tests
    - Write a mini game using it

    Posted 10 months ago #
  17. riq
    Key Master

    Update:
    - Integrated all tests in "main.js"
    - Fixed memory leak in JS collision handler for Chipmunk
    - Added support MenuItemSprite, MenuItemFont and MenuItemLabel, and add Menu Test
    - Improved support for CocosDenshion and added CocosDenshion test
    - CocosDenshion is under the "cc" namespace.
    - Minor fixes in the JS remote console

    I merged my fork (github/ricardoquesada/js-spidermonkey) into the official repo (github/cocos2d/develop-v2).

    So, in oder to download it, use the develop-v2 branch from the cocos2d repo:
    https://github.com/cocos2d/cocos2d-iphone/tree/develop-v2

    Posted 10 months ago #
  18. riq
    Key Master

    Update:
    - Added support for MenuItemToggle
    - Created Parallax Tests (using cocos2d-html5 API and test case)
    - Created Particles Test (using cocos2d-html5 API and test case )

    Posted 10 months ago #
  19. riq
    Key Master

    Update:
    - ProgressActions working
    - Accelerometer working (see playground.js)... not yet integrated into CCLayer

    Posted 10 months ago #
  20. riq
    Key Master

    Update:
    - Added RenderTexture Test
    - Added Effects Tests (only 4 tests)

    What's next:
    - Fix the GC bug
    - Write a simple "1 game in 1 week" using cocos2d + JS and Chipmunk + JS. I will start the game on Monday, and the deadline is Sunday 22

    Posted 10 months ago #
  21. riq
    Key Master

    Update:
    Last week I wrote a simple physics game using the bindings and in the process of doing so I found some bugs and missing functionality.
    The bindings are much more stable now but there is still a crash when the GC is triggered.
    Today I upgraded the JS VM: It is using Spidermonkey from Firefox 14.0.1 (before it was using FF 13.0.1).
    I had to update a bit the script...

    Once the GC bug is fixed I will release an alpha or beta version.

    Posted 9 months ago #
  22. wilczarz
    Member

    @riq, can you please give more info about your work here? Am I right in thinking this project would parse a javascript-written game and generate obj-c compiled classes to some native cocos2d app template? What is the benefit of that, other than popularity of javascript, and why is prototyping supposed to be faster in js than obj-c?

    Posted 9 months ago #
  23. riq
    Key Master

    @wilczarz: The JS code will be executed inside the Spidermonkey VM. It won't generate objective-c code in runtime. The previous bindings (based on JSCocoa) were using that. But the new ones don't.

    The benefits, which has been mentioned many times on this thread is, are:
    - The benefits of a scripting language: faster devel times, faster prototyping.
    - The benefits of JS: Web portability. Develop your game in JS for cocos2d-iphone, and run it on the web using cocos2d-html5.

    Posted 9 months ago #
  24. wilczarz
    Member

    So cocos2d-html5 compatibility is cruicial here, somehow I missed that. I am confident your bindings will run ok with cocos2d-iphone, but maintaining cross browser compatibility is a huge task for cocos2d-html5. I tried running its tests in firefox13 a few weeks back and most of them crashed.

    However, you seem to have a lot of faith, so I will stay open minded too. Btw, extraordinary work running js code in embedded vm!

    Posted 9 months ago #
  25. riq
    Key Master

    @wilczarz:
    Yes, cocos2d JS API compatibility is key in this project. With the cocos2d-html5 guys we are working together on this to make sure that the API is the same.
    If you download cocos2d-html5 (most recent version from github) and the cocos2d-iphone JS code, you will notice that the API is about 95% the same... and we are working on having the remaining 5% covered.

    Please, report any crash that you might find to the cocos2d-html5 guys... browser compatibility is a big thing and we need help from everybody :)

    Posted 9 months ago #
  26. riq
    Key Master

    Update:
    I added more missing bindings like CCNode#update(...), have better names for some functions, etc.
    I am also "porting" the Moon Warriors game: http://www.cocos2d-x.org/news/58

    The goal is to have it running both on HTML5 and JS bindings without modifying a single line of code...

    So far the main menu, options and about are working OK.
    The "Game" layer is displaying the Ship, it shoots, collisions seems to be working, but the controls are not working yet. I think that in 2 or 3 days I will have it working Ok.


    If you want to try it, select the "JS Moon Warrior" target from the Xcode project. It is on the "develop-v2" branch.

    Posted 9 months ago #
  27. riq
    Key Master

    Update:
    "rooting" the manual callbacks. Missing: Automatic callbacks needs to be rooted.
    Code is bit more stable.
    Not to much progress with the game yet :-(... I still trying to find out why the ships are being destroyed automatically.

    Posted 9 months ago #
  28. aruntisa
    Blocked

    good work。I really appreciate it.

    Posted 9 months ago #
  29. riq
    Key Master

    Update:

    More fixes on the JS bindings.
    Reserved slots and "inheritance" of class methods can be configured per class.
    "Fixed" GC crash on Mac. Actually there is a "feature" on Spidermonkey that deallocs all objects on the main thread. So, cocos2d-mac should run on the main thread in order to avoid the crash.

    Moon Warrior games completed! It runs 100% on cocos2d-iphone (and Mac).
    I needed to make some changes, but the goal is to have it running without changes both on cocos2d-iphone and cocos2d-html5.

    Get the Video Widget

    Compare it with the JS version:
    http://www.cocos2d-x.org/news/58

    TODO:
    - Improve the performance a bit
    - Merge my changes into the Moon Warriors cocos2d-html5 version

    Posted 9 months ago #
  30. dany
    Member

    this should run soon also on cocos2d-x w\o modifying much code, right?

    Posted 9 months ago #

RSS feed for this topic

« Previous1234…8Next »

Reply »

You must log in to post.

cocos2d for iPhone is proudly powered by bbPress.