I have stored the positions of the sprites of the board in an array, how can I configure the code to be able to use that information?
declaration of the variable
var arrayPosition = [[], []];
arrayPosition [[0], [0]] = ‘-702, 602’;
use of the variable
const newBullet1 = cc.instantiate (this.element2);
newBullet1.setPosition (arrayPosition [[0], [0]]);
this.node.addChild (newBullet1);
But if I replace it directly by numbers if the sprite is shown
newBullet1.setPosition (-702, 602);
Thanks for the answer, I do not know how to use it, I use a single constant object as controller in the scene and the other nodes appear in already established positions, so I do not know how “this.node” could apply
What Big_Bear suggested was to change the declaration of your array to be an array of Vec2 objects (which are returned by the cc.v2 function):
var arrayPosition = cc.Vec2[];
And to use it somewhere in your code:
var pos = arrayPosition[0]; // or any other index, maybe in a loop perhaps.
pos.x += 10;
this.node.position = pos;
this.node
refers to the node where the component (the script in this case) belongs. In you case, you should find the node corresponding to your object that you want to change its position and use it instead of “this.node”.