There is a custom class called MySprite that extends Sprite and includes additional methods.
var MySprite = cc.Sprite.extend({
ctor:function(){
this._super();
},
doSomethingStrange:function(){
//meow meow
}
}
);
In the game scene, the goal is to retrieve a sprite from the root node and convert it into an instance of MySprite in order to utilize the doSomethingStrange method. However, there seems to be no straightforward way to perform type casting in JavaScript.
var PlayLayer = cc.Layer.extend(new function() {
this.ctor=function () {
this._super();
var rootNode = ccs.csLoader.createNode(res.scene_playscene_json);
this.addChild(rootNode);
};
this.meow_meow = function(rootNode){
cat = rootNode.getChildByTag(numberTagBegin);
// implement a solution here to convert cat from Sprite to MySprite
cat.doSomethingStrange();
};
});
var playScene = cc.Scene.extend({
onEnter:function(){
this._super();
var layer = new PlayLayer();
this.addChild(layer);
}
});