Here’s the scenario -
preload:
var newdecor = { name: ‘’, url: ‘’, locked: 0, x: 0, y: 0, width: 0, height: 0, frames: 0, depth: 0 } /// data gets assigned right after
decorArray.push(newdecor);
decorArray.forEach(loadSprites);
function loadSprites(item,index,arr) {
scene.load.spritesheet(arr[index].name, arr[index].url, { frameWidth: arr[index].width, frameHeight: arr[index].height, endFrame: arr[index].frames });
}
create:
decorArray.forEach(animateDecor);
function animateDecor(item,index,arr) {
var decorobject;
if (arr[index].frames==1) {
decorobject = scene.add.image(arr[index].x,arr[index].y,arr[index].name);
} else {
decorobject = scene.physics.add.sprite
// more sprite stuff
}
decorobject.setInteractive().on(‘pointerdown’, function(pointer, localx, localy, event) {
this.setDepth(this.depth-20);
});
scene.input.setDraggable(decorobject);
decorobjects.push(decorobject);
}
update:
scene.input.on(‘drag’, function (pointer, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
gameObject.setDepth (dragY+(gameObject.height/2));
});
Here is the question:
Everything works, BUT, what is the proper way to update the array info? Right now, the image gets updated and set correctly, but I need to have the array data (decorarray[item].x = …) updated as well.