I have an array with 3 elements, which were taken randomly from a larger array (let's just imagine the larger array is an alphabet, and the 3 elements array called currentChars).
I want to represent each of the character in the currentChars array with an animated sprite, which I have done through a function:
function animateChars(){
y = 300;
for (i=0; i<currentChars.length; i++){
var shape = game.add.sprite(200,y,currentChars[i]);
shape.animations.add('twinkle',null,25,true);
shape.play('twinkle');
y += 60;
}
}
The player make an input, and if the input is correct, the element and its sprite should be removed from the array, and the game.
function searchAndRemove(input, arr) {
for(i = 0; i< arr.length; i++) {
if(arr[i] === input) {
arr.splice(i, 1);
score += 1;
scoreText.text = score;
break;
}
}
However, I have not figured out the way to remove the sprite as the element has been taken out of the array. Ideally, the position of the other sprite should be remained when an element (and its sprite) is removed, but still, I am still stumped.