Jump to content

Help with group vs group collision


BenWeasel
 Share

Recommended Posts

Hi,

I'm at my approach  to this amazing framework but i need help to understand group collision (Admitting that my approach is correct  :rolleyes: )

 

I apologize in advance for my english...

 

 

I'mtrying to create a sort of Educational Game where i have to drag some letters to the right placeholder...

 

I have a word (ex. APPLE)

 

I create a sprite for each Letters and put it in a group called "grp_word"

 

I create a sprite as placeholder for each letter and put it in a group called "grp_placeholder"

 

I have to drag each Letter to the right placeholder

 

In my update function i check overlap collision between grp_word and grp_placeholder.. and.. it dosen't work!!

 

Here my create function

 

 
   create: function(){        //set word        var word = 'APPLE';        //create word group        this.grp_word = game.add.group();        this.grp_word.enableBody = true;        this.grp_word.physicsBodyType = Phaser.Physics.ARCADE;                //create placeholder group        this.grp_placeolder = game.add.group();        this.grp_placeolder.enableBody = true;        this.grp_placeolder.physicsBodyType = Phaser.Physics.ARCADE;        //fix placeholder position        this.grp_placeolder.setAll('body.immovable',true);                 //Create 'Letter' sprite to word group        //set x position for the first letter        var x = 30;                  //create sprite for each letter of word        for (i=0; i< word.length;i++){                       this.word = this.grp_word.create(x, 100, 'tessera');              //set sprite name as array index              this.word.name = i;              this.word.anchor.setTo(0.5,0.5);              //create word as textand add to sprite              this.txt_word = new Phaser.Text(game, this.word.centerX, this.word.centerY, word[i], { font: "20px Arial", fill: "#000000" });              this.txt_word.anchor.setTo(0.5,0.5);                    this.word.addChild(this.txt_word);              //enable drag for this letter              this.word.inputEnabled = true;              this.word.input.enableDrag();              //update x position for next letter              x +=55;              }                //Create letter placeholder sprite        //set x position for the first placeholder        var x = 30;        for (i=0; i< word.length;i++){            this.word_placeholder = this.grp_placeolder.create(x,30, 'tessera');            //set sprite name as array index            this.word_placeholder.name = i;            this.word_placeholder.anchor.setTo(0.5,0.5);            //update x position for next placeholder            x +=55;           }        },
 
And this is my update function
 

    update: function(){        game.physics.arcade.overlap(this.grp_word, this.grp_placeholder, this.checkCollision, null, this);    },

 

 

And this is checkCollision function

checkCollision: function(letter, placeholder){      //simply try to kill letter to check if overlap is detect     letter.Kill();}

Now,

dragging Letter  on placeholder sprite has no effect, but if i drag Letter on othe letter (of the same group "grp_word"), collision's detected and Letter 's killed.

 

What?? Why collision works inside the group?

 

Obviously I'm missing something... :unsure:

 

Can you help me understand where I wrong?

 

Thanks in advance to all

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...