I am very new to Cocos2d-html5 and have almost forgotten how javascript works. What I want to do is create a shared instance of an object and to access it from various other classes. What i want to do is exactly how we access the CCDirector sharedInstance. I looked that code and this is what i did
@
var sharedInstance = null;
var GameScene = cc.Scene.extend({
onEnter:function () {
this._super();
sharedInstance = new GameSceneLayer();
sharedInstance.init();
this.addChild(sharedInstance);
}
});@
In my other .js file I access the sharedInstance directly. I can access it and get all the data associated with it, but the problem is that any sprite I load after that is not aligned properly. This is what Im doing in the other file
@
var size = (sharedInstace.profilesData.length + 1) / 3;
var start = screenNo * size;
var sprite = cc.Sprite.create(sharedInstance.profilsData[start]);
sprite.setPosition(cc.p(100,100));
this.addChild(sprite);
@
In the above case, profilesData is an array that holds the path to the sprite. The sprite loads correctly, but it is always displayed at (0,0)
even though i set the position to something else. Can anyone help me with this?