I change my Reel class implementation.
And it is now working correctly.
Changed my posX to index.
And let setPosition() do the job to change position.
Here’s my Reel Class for those people who want to develop a Slotmachine.
var Reel = cc.LayerColor.extend({
reel_height:0,
card:[],
reel_index:0,
reel:[],
roll:false,
animRoll:null,
animCorrect:null,
index:'',
target:null,
duration:0,
ctor:function (index, target) {
//this._super(cc.color(255, 155, 255), 200, cc.winSize.height);
this._super();
this.index = index;
this.target = target;
this.reel_height = 100 * -10;
this.reel[this.index] = [];
for(var i=0;i<2;i++) {
//this.reel[i] = new cc.LayerColor(cc.color(this.getRandomInt(0,255), this.getRandomInt(0,255), this.getRandomInt(0,255)), 80, this.reel_height);
this.reel[this.index][i] = new cc.Layer();
for (var ctr = 0; ctr < 10; ctr++) {
var color = cc.color(255, 255, 255);
if(i%2){
color = cc.color(255, 155, 255);
}
this.card[ctr] = new Card(ctr.toString(), color);
this.card[ctr].name = ctr.toString();
this.card[ctr].setPosition(cc.p(0, this.card[ctr].card_height * -ctr));
this.reel[this.index][i].addChild(this.card[ctr]);
}
this.reel[this.index][i].setPosition(cc.p(0, this.reel_height * i));
this.addChild(this.reel[this.index][i]);
}
this.scheduleUpdate();
return true;
},
rollAnimation: function () {
this.roll = true;
this.duration = this.getRandomInt(3,5);
this.animRoll = cc.moveBy(this.duration, 0, 100 * 14).repeatForever();
this.runAction(this.animRoll);
},
stopAnimation: function () {
this.roll = false;
this.stopAction(this.animRoll);
console.log('target: '+this.target);
var positionY = this.getPositionY();
var cardNumber = (Math.ceil(positionY / 100) - 1) % 10;
var correctY = (((Math.ceil(positionY / 100) * 100) + 75) - positionY);
var targetPosition = 100 * ((parseInt(this.target) + 10) - cardNumber);
this.animRoll = cc.moveBy(this.duration, 0, targetPosition);
this.animCorrect = cc.moveBy(1, 0, correctY).easing(cc.easeOut(1.0));
this.runAction(cc.sequence(this.animRoll, this.animCorrect));
},
update: function (dt) {
if (this.reel[this.index][this.reel_index % 2].getParent().convertToWorldSpace(this.reel[this.index][this.reel_index % 2].getPosition()).y >= (14 * 100)) {
this.reel[this.index][this.reel_index % 2].setPositionY(this.reel_height * (this.reel_index + 2));
//console.log("reel_index: "+this.reel_index+" index: "+this.index);
this.reel_index++;
}
if(!this.roll){
//console.log(this.reel[this.index][this.reel_index % 2].getParent().convertToWorldSpace(this.reel[this.index][this.reel_index % 2].getPosition()).y);
}
},
getRandomInt: function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});