Ive written a fairly simple sports game in Java and I am now battling to do the same thing in Cocos2d Javascript, which I'm really new at.
What I did in Java and would like to do here is to be able to create a Sprite on the click of a button and and add that sprite to an array of sprites. The tricky part is I want to be able to add and access specific properties and functions in the those sprites in order to change their position, check if they have the ball, give them a ball etc. I think I have subclass somthing and the most logical to me would be the sprite class but I am not sure if this is the right class to subclass or how to do so effectively.
eg.
var player = Player.create(somepicturefile);
this._players.push(player);
this._players[1].hasBall = true;
What I was able to do in java was use those classes to save and load teams form file and move only those players who havent moved, pass the ball around etc but hopefully just getting the sprites to appear on the screen would be a bonus for now : )
a truncated version of what I have so far...
var MakePlan = cc.LayerColor.extend({
_players:[],
_playernumber: 0,
ctor:function() {
// Rest of file...
this._super();
cc.associateWithNative( this, cc.LayerColor );
},
onEnter:function () {
this._super();
this.addPlayer();
},
addPlayer:function() {
var player = Player.create(s_player);
this.addChild(player);
this._players.push(player);
this._playernumber++;
}
});
MakePlan.create = function () {
var sg = new MakePlan();
if (sg && sg.init(cc.c4b(255, 255, 255, 255))) {
return sg;
}
return null;
};
MakePlan.scene = function () {
var scene = cc.Scene.create();
var layer1 = MakePlan.create();
scene.addChild(layer1,0);
return scene;
};
and
var Player = cc.Sprite.extend ({
_hasMoved: false,
_hasBall: false,
ctor:function() {
// Rest of file...
this._super();
cc.associateWithNative( this, cc.Sprite );
}
});
It seems like a decent idea but it doesn't seem to work...