Resolved in a workaround. Here’s my current setup:
~~cocosbuilder 3.0 alpha
~~all cocos2d-javascript (using jsbindings from 2.1 - v.6 I think)
-prototyping exclusively in cocosbuilder and cocosplayer, but periodically moving everything into an xcode project to confirm that it works. and hey, can also move over to android and web. yay so far. i can really get behind this direction as future of the framework.
Now, because touchdispatcher isn’t bound yet (but it is targeted for next release) making touchable sprites from cocosbuilder actually was a bit of a headache. A lot of the samples (including TouchesTest) didn’t bear fruit as they are based on cocos2d-html5, and if I understand correctly cocos2d-javascript (and the bindings which will ultimately produce native code) represents a subset of the functionality in html5 at the moment. Ergo the touchdispatcher binding issue. So, to make a touchable sprite in this edge usecase here’s how I do it, please let me know if you’ve got a better idea while waiting on bindings to catch up.
-
Layout cocosbuilder scene as you would. To add touchable sprite, create a new ccb file with cclayer as its rootnode. Do not make fullscreen.
-
Go into that layer, and set javascript controller to something that looks like Actor.js below.
-
Add a sprite to the layer. Set doc var to “mysprite.”
-
Go ahead and add a timeline, for fun, in ccb and call it “touchedAnimation.” Add some keyframes to the sprite and do things with it.
-
Go back to your main scene, add the ccb you just created to the scene, run and it should work.
Some notes: I had to create my own function for cc.RectMake in the file below, as it was not working for some reason. Perhaps another bindings thing, i dunno. Also this makes for a nice set of functionality that I can then extend into other js controllers and then override the vars with other soundeffects, animations, behaviors, etc.
@
//Actor.js
require(“js/resource.js”);
var Actor = cc.Layer.extend({
ctor:function() {
this.*super;
cc.associateWithNative;
var soundeffect = ‘Rainbow.caf’;
},
onEnter:function {
this.*super();
},
});
Actor.prototype.onDidLoadFromCCB = function()
{
// Forward relevant touch events to controller (this)
this.rootNode.onTouchesBegan = function( touches, event) {
this.controller.onTouchesBegan(touches, event);
return true;
};
// this.rootNode.onTouchesMoved = function( touches, event) {
// this.controller.onTouchesMoved(touches, event);
// return true;
// };
this.rootNode.onTouchesEnded = function( touches, event) {
this.controller.onTouchesEnded(touches, event);
return true;
};
}
Actor.prototype.onTouchesBegan = function(touches, event)
{
this.startTouch = touches[0].getLocation();
};
//Actor.prototype.onTouchesMoved = function(touches, event)
//{
//// if (gSettingControlType != CD_CONTROLTYPE_TOUCH) return;
//
// this.touchPoint = touches[0].getLocation();
// // cc.log(‘moved’);
// // cc.log(‘touchPoint x:’touchPoint.x ‘y:’touchPoint.y);
//
// if > swipedistance )
//
//
//};
Actor.prototype.onTouchesEnded = function
{
this.endTouch = touches[0].getLocation;
this.myspriterect = ttRectMake.x this.rootNode.getPosition().x, this.mysprite.getBoundingBox().y + this.rootNode.getPosition().y, this.mysprite.getBoundingBox().width,this.mysprite.getBoundingBox().height);
if (cc.rectContainsPoint(this.myspriterect, this.endTouch)){
audioEngine.playEffect(this.soundeffect);
this.rootNode.animationManager.runAnimationsForSequenceNamed(“touchedAnimation”);
}
};
ttRectMake = function (x, y, width, height) {
return cc.rect(x, y, width, height);
};
@