Jump to content

[Arcade Physics] method Collide not working


Recommended Posts

I'm relatively new to Phaser, but up until now I have found everything to work as expected. 

I'm trying to develop a Worms clone (just for fun) and i'm basing most of my code on the following tutorial :http://phaser.io/tutorials/coding-tips-001

The problem is, I can't get my worms (group) to collide with the land (bitmapdata converted into a sprite)

Here is my create()

create: function() {

//create background first
this.background = this.game.add.sprite(0,0,'background');

//start the physics system
//create land

//create worms


and createLand()

createLand: function(){
//create the land bitmap data
this.landBmp = this.add.bitmapData(1500,1000);
//convert to sprite landBmp -> land
this.land = this.game.add.sprite(0,0,this.landBmp);

//enable physics on land sprite
this.land.body.allowGravity = true;
this.land.body.immovable = true;



createWorms: function(){

            this.worms = this.game.add.group();

        	for (var i = 0; i < 10; i++)
                //calculate team and select name
        		var team = i % 2;
        		var name = names[Math.floor((Math.random() * names.length -1))];
                //create a worm
        		var worm = this.worms.create(land1SpawnPoints[i].x,land1SpawnPoints[i].y,'sprites');
                worm.team = team;
                worm.name = name;
                worm.health = 100;

                //enable physics for the worm
                worm.body.gravity.y = 200;
                worm.body.bounce = 0.3;
                worm.body.velocity.x = 1;

                worm.animations.add('idle' ,
                worm.animations.add('move' ,

                //add the worm to worms group

and in my update function i'm calling

//NOTE: this function works , and by works, I mean - 
//The function this.test will be called when a worm overlaps with the land sprite

//this.physics.arcade.overlap(this.worms, this.land, this.test, null, this);

When I run my code with physics.arcade.collide it doesn't trigger any callback function and the worms just fall through the ground.

However if I use the overlap function , a callback function is triggered.

If anyone could point me in the right direction as to what is going wrong I would be very grateful.


Edit: Even if you could tell me how I can  programmatically stop my worms from falling through the ground 

For example, the following function would be called when a worm overlaps with the ground.

 test : function(worm, land) {
            //code goes here to prevent worm falling further


Link to comment
Share on other sites


  • Recently Browsing   0 members

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