I am trying to create a scenario where my cylindrical objects (referred to as pions in the code) move step by step towards a specified object on a board of my design. Here is the code snippet I have:
a: starting point
index: target object
attachEvent(_this, index,a) {
if(index>=a){
_this.domEvents.addEventListener(_this.cases[index], 'click',
function(event) {
for ( var i = a; i <= index; i++) {
_this.stepByStep(_this,i)
}
}, false)
}else{
_this.domEvents.addEventListener(_this.cases[index], 'click',
function(event) {
//no action for now
}, false)
}
}
stepByStep(_this,i)
{
_this.tween = new TWEEN.Tween(this.pions.position)
.to({
x: _this.cases[i].position.x,
y: _this.cases[i].position.y,
z: 5},1000)
.start();
}
Despite implementing the code, when I test it out, the pions seem to move directly to the target object without moving step by step as intended.