Hi Jake.
Thank you so much for your help. I’m very new at phaser so all help is much appreciated.
After I do this however, the setDraggable is not working.
I tried putting it inside the for loop too.
In my game, I have 10 images (‘c’ is one of them) and the user has to drag and drop them.
After that is done, I want to be able to read what order the user has arranged those images in, and display that or record it.
@Jake.Caron this is my complete code as of now:
//var gameScene= new Phaser.Scene(‘Game’);
var config={
type: Phaser.AUTO,
width: 1230,
height: 800,
physics:{
default: ‘arcade’,
arcade: {
gravity: { y: 300},
debug: false
}
},
scene: {
preload: preload,
create: create,
//update: update
}
};
var game= new Phaser.Game(config);
const droppedObjectIdList = [ ];
function preload()
{
this.load.image(‘background’,‘assets/background.png’);
this.load.image(‘a’, ‘assets/Acceptance.png’);
this.load.image(‘c’, ‘assets/Curiosity.png’);
this.load.image(‘f’, ‘assets/Freedom.png’);
this.load.image(‘o’, ‘assets/Order.png’);
this.load.image(‘p’, ‘assets/Power.png’);
this.load.image(‘r’, ‘assets/Relatedness.png’);
this.load.image(‘s’, ‘assets/Status.png’);
this.load.image(‘h’, ‘assets/Honor.png’);
this.load.image(‘g’, ‘assets/Goal.png’);
this.load.image(‘m’, ‘assets/Mastery.png’);
this.load.image(‘bar’,‘assets/bar.png’);
}
function create() {
this.add.image(615, 400, ‘background’);
bar= this.physics.add.staticGroup();
bar.create(615,450,‘bar’);
var mvs= [‘c’,‘h’,‘a’,‘m’,‘p’,‘f’,‘r’,‘o’,‘g’,‘s’];
for (var i=0; i<10 ;i++)
{
this.input.setDraggable(this.add.image(210+(90*i), 200, mvs[i]).setInteractive());
}
// for (var i=0;i<10;i++)
// {
// this.physics.add.staticGroup({
// key: mvs[i],
// setXY: {x: 210, y: 200, stepX: (90*i)}
// });
// this.physics.add.collider(mvs[i], bar);
// }
this.input.on('drag',function(pointer, gameObject, dragX, dragY){
gameObject.x=dragX;
gameObject.y=dragY;
});
//function update(){
this.input.on(“dragend”, function(pointer, gameObject)
{
droppedObjectIdList.push(this.id);
});
for (i=0;i<10;i++)
{
//this.add.text(600, 500, ‘hello’,
this.add.text(600, 500, droppedObjectIdList[i],{ fill: “#ffffff”});
}
//}
}
I’ve been stuck for days. Could you help ?